scikit-learn文档之后,我试图适合虚拟分类器。但是,在运行值错误时。这是出乎意料的,如前所述,我使用的是相同的数据:x = vector_data(稀疏矩阵),y = vector_target(int列表)带有网格搜索cv的拟合,没有任何错误。
。因此,它必须是Train_testrongplit的引入。
为什么在我的代码中发生这种情况,而不是文档,请采取哪些预防步骤?
X_train, X_test, y_train, y_test = train_test_split(vector_data, vector_target, random_state=0)
clf = DummyClassifier(strategy='stratified',random_state=0)
clf.fit(X_train, y_train)
clf.score(X_test,y_test)
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19.
Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
DeprecationWarning)
首先,始终,始终读取警告/错误消息。
所以,尝试这样的事情:
X_train, X_test, y_train, y_test = train_test_split(vector_data.reshape(-1, 1),
vector_target, random_state=0)
我不能说更多,只是尝试理解此代码。