Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn logistic regression parameter in GridSearch

just wondering how to separate parameters into a group and pass it to gridsearch? As i want to pass penalty l1 and l2 to grid search and corresponding solver newton-cg to L2.

However, when i run the code below, the gridsearch will first run l1 with newton-cg and result in error msg ValueError: Solver newton-cg supports only l2 penalties, got l1 penalty.

Thanks

 param_grid = [

  {'penalty':['l1','l2'] ,
   'solver' : ['newton-cg', 'lbfgs', 'liblinear', 'sag', 'saga']
  }

 ]
like image 980
Tony G Avatar asked Nov 30 '25 11:11

Tony G


1 Answers

Try this example:

param_grid = [
  {'penalty': ['l1'], 'solver': [ 'lbfgs', 'liblinear', 'sag', 'saga']},
  {'penalty': ['l2'], 'solver': ['newton-cg']},
 ]

here l1 will be tried with 'lbfgs', 'liblinear', 'sag', 'saga' and l2 will be tried with only 'newton-cg'

like image 158
Pratik Kumar Avatar answered Dec 02 '25 03:12

Pratik Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!