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 SVCclassifier = SVC(random_state = 0)classifier.fit(features,y_train)y_pred = classifier.predict(features)
错误:
ValueError: 发现输入变量的样本数量不一致:[676, 540]
我尝试了这个方法。
回答:
你为什么在.fit()中使用features和y_train呢?我认为你应该使用X_train代替features。
不是这样:
classifier.fit(features, y_train)
而是应该这样:
classifier.fit(X_train, y_train)
因为你之前已经做了分割,你试图使用两组形状不同的数据,所以features的样本数比y_train多。
另外,对于你的预测行,应该是这样的:
.predict(X_test)