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.
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,
train_test_split
or KFold
that can be imported from skleanpara=[{‘max_iter’:[1,10,100,100]}]
clf=GridSearchCV(LogisticRegression, param_grid=para, cv=5, scoring=‘r2’)
clf.fit(x_train, y_train)
You can also fetch the best number of iterations with RandomizedSearchCV
or BayesianOptimization
.