Sklearn的train_test_split在多个输入上不起作用

我有两个输入X1和X2,以及对应的标签Y。我想使用SkLearn的train_test_split将数据分割成训练和验证集。我的X1的形状是(1920,12),X2的形状是(1920,51,5)。我使用的代码是:

from sklearn.model_selection import train_test_splitX1 = np.load('x_train.npy')X2 = np.load('oneHot.npy')y_train = np.load('y_train.npy')X = np.array(list(zip(X1, X2))) ### 将两个输入打包。X_train, X_valid, y_train, y_valid = train_test_split(X, y_train,test_size=0.2)X1_train, oneHot_train = X_train[:, 0], X_train[:, 1]

然而,当我检查X1_train和oneHot_train的形状时,它们是(1536,),而X1_train应该为(1536,12),oneHot_train应该为(1536,51,5)。我在这里做错了什么?欢迎提供见解。


回答:

train_test_split可以接受任意数量的迭代器进行分割。因此,您可以直接输入x1x2 – 如下所示:

x1 = np.random.rand(1920,12)x2 = np.random.rand(1920,51,5)y = np.random.choice([0,1], 1920)x1_train, x1_test, x2_train, x2_test, y_train, y_test = train_test_split(\     x1, x2, y ,test_size=0.2)x1_train.shape, x1_test.shape # ((1536, 12), (384, 12))x2_train.shape, x2_test.shape # ((1536, 51, 5), (384, 51, 5))y_train.shape, y_test.shape # ((1536,), (384,))

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注