我想一個GridSearchCV
在DecisionTreeClassifier
運行,唯一的超參數是max_depth
。我跑這兩個版本是:GridSearchCV上DecisionTreeClassifier
max_depth = range(1,20)
的best_estimator_ attribute
顯示15 MAX_DEPTH而計分函數顯示0.8880的測試設置
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
我做到了。除了兩個要求我添加代碼的評論外,沒有什麼可以「扔掉」了,我也這樣做了。 –
所以你刪除它,使我看起來像你沒有準備你的問題中的東西嗎?而且你再次呈現的代碼沒有可重現的'''X_train,y_train'''。 – sascha