如何为sklearn svm塑造训练和测试数据

时间:2017-12-03 22:52:15

标签: pandas scikit-learn svm

我使用pandas库提取数据并使用它来提供svc分类器,如下所示:

from sklearn.svm import SVC
import pandas as pd

train = pd.read_csv('train.csv')
X_train = train['FunctionalWordPercent']
Y_train  = train['openness']

test = pd.read_csv('test.csv')
X_test = test['FunctionalWordPercent']
Y_test  = test['openness']

clf = SVC()
clf.fit(X_train, Y_train) 
SVC(kernel="linear", c=1.0)

print(clf.score(X_test,Y_test))

但我一直收到以下错误:

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

1 个答案:

答案 0 :(得分:0)

看起来您正在为X使用单个列(功能)。要使此代码起作用,您需要执行此操作:

X_train = train['FunctionalWordPercent']
X_train = X_train.reshape(-1,1)


X_test = test['FunctionalWordPercent']
X_test = X_test.reshape(-1,1)