'GridSearchCV' object has no attribute 'cv_results_
时间: 2023-10-07 07:06:17 浏览: 169
This error usually occurs when you are trying to access the `cv_results_` attribute of a `GridSearchCV` object before calling the `fit()` method on it.
To fix this error, make sure that you have called the `fit()` method on your `GridSearchCV` object before accessing its `cv_results_` attribute. Here is an example:
```
from sklearn.model_selection import GridSearchCV
from sklearn.svm import SVC
# define the parameter grid
param_grid = {'C': [0.1, 1, 10], 'gamma': [0.1, 1, 10]}
# create a GridSearchCV object
grid_search = GridSearchCV(SVC(), param_grid, cv=5)
# call the fit method to train the model
grid_search.fit(X_train, y_train)
# access the cv_results_ attribute after fitting the model
print(grid_search.cv_results_)
```
Make sure to replace `X_train` and `y_train` with your own training data.
阅读全文