小编Thr*_*nry的帖子

SGDClassifier 类的数量必须大于 1;上了1节课

因此,我已尽一切可能来解决这个错误,这也是我巨大的挫败感。

from sklearn.linear_model import SGDClassifier

train_labels_9 = [(label == 9) for label in train_labels_9]
test_labels_9 = [(label == 9) for label in test_labels_9]

sgd = SGDClassifier(max_iter = 1000, tol = 1e-3)
sgd.fit(train_images,train_labels_9)

below is the error
ValueError                                Traceback (most recent call last)
<ipython-input-57-8ad0fdf39a29> in <module>
      6 
      7 sgd = SGDClassifier(max_iter = 1000, tol = 1e-3)
----> 8 sgd.fit(train_images,train_labels_9)

~\Anaconda3\lib\site-packages\sklearn\linear_model\stochastic_gradient.py in fit(self, X, y, coef_init, intercept_init, sample_weight)
    741                          loss=self.loss, learning_rate=self.learning_rate,
    742                          coef_init=coef_init, intercept_init=intercept_init,
--> 743                          sample_weight=sample_weight)
    744 
    745 

~\Anaconda3\lib\site-packages\sklearn\linear_model\stochastic_gradient.py in _fit(self, …
Run Code Online (Sandbox Code Playgroud)

python

3
推荐指数
1
解决办法
3166
查看次数

标签 统计

python ×1