Issue
I'm creating a model to perform Logistic regression on a dataset using Python. This is my code:
from sklearn import linear_model
my_classifier2=linear_model.LogisticRegression(solver='lbfgs',max_iter=10000)
Now, according to Sklearn doc page, max_iter is maximum number of iterations taken for the solvers to converge. How do I specifically state that I need 'N' number of iterations ?
Any kind of help would be really appreciated.
Solution
I’m not sure, but, Do you want to know the optimal number of iterations for your model? If so, you are better off utilizing GridSearchCV
that scan tune hyper parameter like max_iter
.
Briefly,
- Split your data into two groups: train/test data with
train_test_split
orKFold
that can be imported from sklean - Set your parameter, for instance
para=[{‘max_iter’:[1,10,100,100]}]
- Instance, for example
clf=GridSearchCV(LogisticRegression, param_grid=para, cv=5, scoring=‘r2’)
- Implement with using train data like this:
clf.fit(x_train, y_train)
You can also fetch the best number of iterations with RandomizedSearchCV
or BayesianOptimization
.
Answered By - Genzo Ito
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.