6

I am using GridSearchCV to do classification and my codes are:

parameter_grid_SVM = {'dual':[True,False],
                    'loss':["squared_hinge","hinge"],
                    'penalty':["l1","l2"] 
                    }
clf = GridSearchCV(LinearSVC(),param_grid=parameter_grid_SVM,verbose=2)
clf.fit(trian_data, labels)

And then, I meet the error

ValueError: Unsupported set of arguments: penalty='l1' is only supported when dual='false'., Parameters: penalty='l1', loss='hinge', dual=False

later on I change my code to :

clf = GridSearchCV(LinearSVC(penalty='l1',dual=False),verbose=2)

And I meet the error

TypeError: init() takes at least 3 arguments (3 given)

I also tried:

parameter_grid_SVM = {
                    'loss':["squared_hinge"]
                    }
clf = GridSearchCV(LinearSVC(penalty='l1',dual=False),param_grid=parameter_grid_SVM,verbose=2)
clf.fit(trian_data, labels)

However, I still have the error

ValueError: Unsupported set of arguments: penalty='l1' is only supported when dual='false'., Parameters: penalty='l1', loss='squared_hinge', dual=False

Anyone has idea what I should do to deal with that?

gladys0313
  • 2,569
  • 6
  • 27
  • 51
  • 1
    Just a hunch: try adding the fixed parameters to the dictionary you are using for the grid search as singleton lists: 'penalty': ['l1'], 'dual': [False]. – Matthew Drury Apr 27 '15 at 17:33
  • I tried this also, but it returns the error ValueError: Unsupported set of arguments: penalty='l1' is only supported when dual='false'., Parameters: penalty='l1', loss='squared_hinge', dual=False – gladys0313 Apr 28 '15 at 06:52

4 Answers4

2

I also met this problem when doing sparse SVM. I find one piece of working demo code in this page SVM module explanation. Hope it might help.

clf = LinearSVC(loss='l2', penalty='l1', dual=False)

William
  • 598
  • 4
  • 10
2

One option is to instruct GridSearchCV to set the score manually if model throws an exception using the error_score parameter. See my answer here.

crypdick
  • 16,152
  • 7
  • 51
  • 74
2

Had a similar issue and in my case, it was writing twelve 12 instead of 'el two' l2 in some instances.

ArdentLearner
  • 712
  • 7
  • 20
0

The code that produces this error message is here. I don't see what would cause this to only happen occasionally, but the bare else means that presumably it's something else other than just the penalty='l1', dual='false' combination.