Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print the best parameters through GridSearchCV for k-fold cross validation

I have used a GridSearch for parameter optimization when predicting values with 10-fold cross validation using sklearn, as shown below,

svr_params = {
   'C': [0.1, 1, 10],
   'epsilon': [0.01, 0.05, 0.1, 0.5, 1],
    }

svr = SVR(kernel='linear', coef0=0.1, shrinking=True, tol=0.001, cache_size=200, verbose=False, max_iter=-1)
best_svr = GridSearchCV(
    svr, param_grid=svr_params, cv=10, verbose=0, n_jobs=-1)

predicted = cross_val_predict(best_svr, X, y, cv=10)

I want to print out the best parameters selected by the GridSearch for C and epsilon. I would really appriate some help. Thanks in advance.

like image 785
Krishi H Avatar asked Oct 20 '25 09:10

Krishi H


1 Answers

The best parameters are available as best_params_ attribute of GridSearchCV.

best_svr = GridSearchCV(svr, param_grid=svr_params, cv=10, verbose=0, n_jobs=-1, refit=True)
best_svr.fit(X, y)
print(best_svr.best_params_)
like image 121
jh314 Avatar answered Oct 21 '25 22:10

jh314



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!