2014-07-17 86 views
5

當我訓練的scikit-learn v0.15 SGDClassifier這些選項:SGDClassifier(loss='log', class_weight=None, penalty='l2'),訓練,並沒有錯誤完成。 然而,當我在訓練這個分類與class_weight='auto' scikit學習v0.15,我得到這個錯誤:SGDClassifier與class_weight =自動上失敗scikit學習0.15而不是0.14

return self.model.fit(X, y) 
    File "/home/rose/.local/lib/python2.7/site-packages/scikit_learn-0.15.0b1-py2.7-linux-x86_64.egg/sklearn/linear_model/stochastic_gradient.py", line 485, in fit 
    sample_weight=sample_weight) 
    File "/home/rose/.local/lib/python2.7/site-packages/scikit_learn-0.15.0b1-py2.7-linux-x86_64.egg/sklearn/linear_model/stochastic_gradient.py", line 389, in _fit 
    classes, sample_weight, coef_init, intercept_init) 
    File "/home/rose/.local/lib/python2.7/site-packages/scikit_learn-0.15.0b1-py2.7-linux-x86_64.egg/sklearn/linear_model/stochastic_gradient.py", line 336, in _partial_fit 
    y_ind) 
    File "/home/rose/.local/lib/python2.7/site-packages/scikit_learn-0.15.0b1-py2.7-linux-x86_64.egg/sklearn/utils/class_weight.py", line 43, in compute_class_weight 
    raise ValueError("classes should have valid labels that are in y") 
ValueError: classes should have valid labels that are in y 

這是什麼原因呢?

僅供參考,這裏的一對class_weight文檔:

Preset for the class_weight fit parameter. Weights associated with classes. If not given, all classes are supposed to have weight one. The 「auto」 mode uses the values of y to automatically adjust weights inversely proportional to class frequencies.

+0

您正在使用的OSX相同scikit學習的版本?版本0.15剛剛發佈,也許你可以嘗試一下。如果錯誤仍然存​​在,即相同的代碼引起了在Linux EC2的錯誤,而不是MacOSX上,那麼你應該考慮這個報告對scikit學習郵件列表。 – eickenberg

+0

我使用的是版本0.15。在您的回溯 –

+1

尋找您所使用的β1,不釋放0.15 – eickenberg

回答

3

我想這可能是內scikit學習中的錯誤。作爲變通,請嘗試以下操作:

from sklearn.preprocessing import LabelEncoder 
le = LabelEncoder() 
y_encoded = le.fit_transform(y) 
self.model.fit(X, y_encoded) 
pred = le.inverse_transform(self.model.predict(X))