Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:找到样本数不一致的输入变量:[676540]_Python_Machine Learning_Scikit Learn - Fatal编程技术网

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)