Python ValueError:找到样本数不一致的输入变量:[676540]
装配时,它会给出误差:Python ValueError:找到样本数不一致的输入变量:[676540],python,machine-learning,scikit-learn,Python,Machine Learning,Scikit Learn,装配时,它会给出误差: X_train, X_test, y_train, y_test = train_test_split(features, df['Label'], test_size=0.2, random_state=111) print (X_train.shape) # (540, 4196) print (X_test.shape) # (136, 4196) print (y_train.shape) # (540,) print (y_test.shape) # (136,
X_train, X_test, y_train, y_test = train_test_split(features, df['Label'], test_size=0.2, random_state=111)
print (X_train.shape) # (540, 4196)
print (X_test.shape) # (136, 4196)
print (y_train.shape) # (540,)
print (y_test.shape) # (136,)
错误:
from sklearn.svm import SVC
classifier = SVC(random_state = 0)
classifier.fit(features,y_train)
y_pred = classifier.predict(features)
我试过了。你为什么要在.fit()上使用y_系列的功能?我想你应该改用X_火车 而不是
ValueError: Found input variables with inconsistent numbers of samples: [676, 540]
使用:
您正在尝试使用两组形状不同的数据,因为您之前进行了拆分。所以特征比y_序列有更多的样本
还有,为你预测线。应该是:
classifier.fit(X_train, y_train)
您想使用
X\u train
调用fit
函数,而不是使用功能
。出现此错误的原因是功能
和y\u列
的大小不同
.predict(x_test)
您可能还需要使用X\u测试或X\u训练调用predict
。您可能想了解更多有关训练/测试拆分的信息以及使用它们的原因
.predict(x_test)
X_train, X_test, y_train, y_test = train_test_split(features, df['Label'], test_size=0.2, random_state=111)
print (X_train.shape)
print (X_test.shape)
print (y_train.shape)
print (y_test.shape)
from sklearn.svm import SVC
classifier = SVC(random_state = 0)
classifier.fit(X_train, y_train)
y_pred = classifier.predict(X_test)