Search code examples
pythonsvmscikit-learnsvc

Scikits-learn svm SVC simple issue


I have a problem which I solved, but I want to know if i am right.

on scikit's learn documentation regarding SVM SVC, there is an example to manage unbalanced data by using weights in classes.

they put an example where the classes weight are informed in svm.SVC()

    wclf = svm.SVC(kernel='linear', class_weight={1: 10})

but if a reproduce this command on source code, i get the following error:

    wclf = svm.SVC(kernel='linear', class_weight={1: 10})
    TypeError: __init__() got an unexpected keyword argument 'class_weight'

But if put the classes_weight on fit() function the problem is solved:

    wclf.fit(X, y, class_weight={1: 10})

am I right about this? did anybody ever had this problem?


Solution

  • The keyword 'class_weight' is not yet implemented in your sklearn version for SVC, but it is for SVC.fit(). sklearn updates their functions sometimes slower than you think, and the documentation you are reading may be /dev/ or /stable/ instead of your version.