该错误来自预测方法。Numpy将[1,1]解释为一维数组。因此,这应该避免警告:
clf.predict(np.array([[1,1]]))
注意:
In [14]: p1 = np.array([1,1])In [15]: p1.shapeOut[15]: (2,)In [16]: p2 = np.array([[1,1]])In [17]: p2.shapeOut[17]: (1, 2)
另外,请注意,您不能使用形状(2,1)的数组
In [21]: p3 = np.array([[1],[1]])In [22]: p3.shapeOut[22]: (2, 1)In [23]: clf.predict(p3)---------------------------------------------------------------------------ValueError Traceback (most recent call last)<ipython-input-23-e4070c037d78> in <module>()----> 1 clf.predict(p3)/home/juan/anaconda3/lib/python3.5/site-packages/sklearn/svm/base.py in predict(self, X) 566 Class labels for samples in X. 567 """--> 568 y = super(baseSVC, self).predict(X) 569 return self.classes_.take(np.asarray(y, dtype=np.intp)) 570/home/juan/anaconda3/lib/python3.5/site-packages/sklearn/svm/base.py in predict(self, X) 303 y_pred : array, shape (n_samples,) 304 """--> 305 X = self._validate_for_predict(X) 306 predict = self._sparse_predict if self._sparse else self._dense_predict 307 return predict(X)/home/juan/anaconda3/lib/python3.5/site-packages/sklearn/svm/base.py in _validate_for_predict(self, X) 472 raise ValueError("X.shape[1] = %d should be equal to %d, " 473 "the number of features at training time" %--> 474 (n_features, self.shape_fit_[1])) 475 return X 476ValueError: X.shape[1] = 1 should be equal to 2, the number of features at training time
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)