Bad input shape error on SVM training using scikit

13,947

Which line of the code is throwing the error? Is it lin_clf.fit(features,u)?

According to the documentation of LinearSVC, the arguments for fit(X,y) are

X : {array-like, sparse matrix}, shape = [n_samples, n_features]

Training vector, where n_samples in the number of samples and n_features is the number of features.

y : array-like, shape = [n_samples]

Target vector relative to X

However, the u in your code is a python set. It should be a numpy array of length 72900.

Share:
13,947
m_amber
Author by

m_amber

SOreadytohelp

Updated on June 05, 2022

Comments

  • m_amber
    m_amber almost 2 years

    I m a little new to scikit and ML. I m trying to train an SVM classifier for one vs all classification. I m using the following code.

    g=list()
    for i in range(0,120):
        g.append(1)
    for i in range(120,240):
        g.append(2)
    
    u=set(g)
    numclasses=len(u)
    
    lin_clf = svm.LinearSVC()
    lin_clf.fit(features,u)
    

    Features is a 72900*120 array. I m getting features from a different python code and calling that here. It throws the following warning and error.

    /usr/lib/python2.7/dist-packages/scipy/misc/pilutil.py:279: 
    DeprecationWarning: fromstring() is deprecated. Please call frombytes() instead.
    image = Image.fromstring(mode, shape, strdata)
    

    error

    ValueError: bad input shape ()
    

    Please comment if you need the code for feature extraction. Thank you in advance.