我目前正在进行数据建模,但我收到错误,无法找到解决方案。所以我希望我能从这个平台得到一些帮助! 提前谢谢。
我的代码: -
from sklearn import cross_validation
from sklearn.cross_validation import cross_val_score
from sklearn.cross_validation import train_test_split
from sklearn import svm
X = np.array(observables) #X are features
y = np.array(df['diagnosis']) # y is label
X_train, y_train, X_test, y_test= cross_validation.train_test_split(X, y, test_size=0.2)
clf= svm.SVC()
clf.fit(X_train, y_train)
accuracy= clf.score(X_test, y_test)
print (accuracy)
但是我收到了这个错误:
ValueError:错误的输入形状(114,8)
答案 0 :(得分:2)
好像你混淆了return values of train_test_split
的顺序,使用
X_train, X_test, y_train, y_test= cross_validation.train_test_split(X, y, test_size=0.2)
而不是
X_train, y_train, X_test, y_test= cross_validation.train_test_split(X, y, test_size=0.2)