max_depth
という唯一のハイパーパラメータを使用して、DecisionTreeClassifier
を超えてGridSearchCV
を実行しようとしています。私はこれを実行した2つのバージョンがある:スコアリング関数は、試験に0.8880示しているDecisionTreeClassifierのGridSearchCV
max_depth = range(1,20)
best_estimator_ attribute
15のMAX_DEPTHを示す設定
max_depth = range(1,15)
best_estimator_ attribute
は、より高い10のMAX_DEPTHを示します0.8907のスコア。
私の質問は、なぜより良いスコアを与える場合、GridSearchCV
は10のmax_depthを最初に選ぶのですか?次のように
コードは次のようになります。それは、より良いスコアを与える場合
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import make_scorer
clf = tree.DecisionTreeClassifier(random_state=7)
parameters = {"max_depth": range(1,20), "random_state":[7]}
scorer = make_scorer(fbeta_score,beta=0.5)
grid_obj = GridSearchCV(estimator=clf,param_grid=parameters,scoring=scorer)
grid_fit =grid_obj.fit(X_train,y_train)
best_clf = grid_fit.best_estimator_
predictions = (clf.fit(X_train, y_train)).predict(X_test)
best_predictions = best_clf.predict(X_test)
# Report the before-and-afterscores
print best_clf
print "\nOptimized Model\n------"
print "Final accuracy score on the testing data:
{:.4f}".format(accuracy_score(y_test, best_predictions))
print "Final F-score on the testing data: {:.4f}".format(fbeta_score(y_test,
best_predictions, beta = 0.5))
他の質問を削除して再度追加してコメントを破棄しましたか? – sascha
しました。私がしたコードを追加するように頼む2つのコメント以外には、 "捨て去る"ものは何もありませんでした。 –
あなたはそれを削除して、あなたの質問の中で何かを準備したように見えますか?また、再現可能な '' 'X_train、y_train'''を使わずにコードを表示することもできます。 – sascha