python - 我如何修复 reshape 我的数据集以进行交叉验证?

标签 python numpy machine-learning scikit-learn cross-validation

x_train:(153347,53)
x_test:(29039,52)
y:(153347,)

我正在使用 sklearn。为了交叉验证和 reshape 我的数据集,我做了:

x_train, x_test, y_train, y_test = cross_validation.train_test_split(
x, y, test_size=0.3)

x_train = np.pad(x, [(0,0)], mode='constant')
x_test = np.pad(x, [(0,0)], mode='constant')
y = np.pad(y, [(0,0)], mode='constant')
x_train = np.arange(8127391).reshape((-1,1))
c = x.T
np.all(x_train == c)
x_test = np.arange(1510028).reshape((-1,1))
c2 = x.T
np.all(x_test == c2)
y = np.arange(153347).reshape((-1,1))
c3 = x.T
np.all(y == c3)

我的错误信息是:ValueError: Found arrays with inconsistent numbers of samples: [ 2 153347]

我不确定在这种情况下是否需要填充我的数据集,并且 reshape 无法正常工作。关于如何解决此问题的任何想法?

最佳答案

有了我们在这里看到的一点点,我相信对 cross_validation.train_test_split 的调用会转储,因为两个向量的长度不一致。因此,对于每个 X(我们观察到的数据元组),您都需要一个 Y(作为结果观察到的数据点)。

至少这会导致上面显示的错误。

您绝对应该改进问题的表述。非常喜欢。

问候,fricke

关于python - 我如何修复 reshape 我的数据集以进行交叉验证?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39804629/

相关文章:

python - 按周分组,填充 'missing'周

MATLAB:重新排列特征矩阵

python - 按值迭代多个列表

python - 为什么有些参数需要定义,而另一些则不需要? (艰难地学习 Python,例如 25)

Python matplotlib scatter - 一个散布中的不同标记

python - 如何在 OpenCV 3.0 或更高版本中使用estimateRigidTransform,还有其他选择吗?

python - 迭代使用自己输出的数组的最佳方法

Python列表比较numpy优化

python - tf.keras.models.save_model 和优化器警告

machine-learning - sklearn.model_selection GridSearchCV 抛出 KeyError : 'mean_train_score'