python(ver 3.6.1)でsklearnのgrid searchを実行したのですが、下記エラーで進めません。
わかる方いらっしゃったら教えていただきたいです。
前提
実行したコード
from sklearn.model_selection import GridSearchCV
scoring = "roc_auc"
params = {
'bootstrap': [True, False],
'class_weight': [None,'balanced'],
'criterion': ['gini', 'entropy'],
'max_depth': [None, 2],
'max_features': ['auto', 4, 5],
'n_estimators': [100,500]
}
gs = GridSearchCV(RandomForestClassifier(), params, scoring=scoring, n_jobs=2)
gs.fit(X_train, y_train)
print('Best params: {}'.format(gridsearch.best_params_))
print('Best Score: {}'.format(gridsearch.best_score_))
発生している問題・エラーメッセージ
NameError Traceback (most recent call last)
Cell In[21], line 17
14 gs = GridSearchCV(RandomForestClassifier(), params, scoring=scoring, n_jobs=2)
15 gs.fit(X_train, y_train)
---> 17 print('Best params: {}'.format(gridsearch.best_params_))
18 print('Best Score: {}'.format(gridsearch.best_score_))
NameError: name 'gridsearch' is not defined
試したこと
・1行目はもともと
from sklearn.grid_search import GridSearchCV
でしたが、
from sklearn.model_selection import GridSearchCV
に変更してみました
・sklearnのバージョンが最新のものではなかったため、最新のものにアップデートしました。
よろしくお願いいたします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2023/04/14 09:27
2023/04/18 00:24