Skip to main content
 首页 » 编程设计

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

2025年04月02日9itcoder

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