根据adaboostclassifier

时间:2017-11-10 05:31:12

标签: python scikit-learn

我尝试使用以下代码在具有大约300条记录和100个功能的数据集上训练和预测模型。我想知道我在代码中搜索下面的n_estimators的选择是否过高?既然我只有300条记录,那么为n_estimators尝试像[10,20,30]那样更有意义吗? n_estimators是否与训练数据的数据集大小相关?学习率怎么样?

代码:

from sklearn.grid_search import GridSearchCV
from sklearn.metrics import accuracy_score, make_scorer
from sklearn.ensemble import AdaBoostClassifier, GradientBoostingClassifier


# TODO: Initialize the classifier
clf = AdaBoostClassifier(random_state=0)

# TODO: Create the parameters list you wish to tune
parameters = {'n_estimators':[100,200,300],'learning_rate':[1.0,2.0,4.0]}

# TODO: Make an fbeta_score scoring object
scorer = make_scorer(accuracy_score)

# TODO: Perform grid search on the classifier using 'scorer' as the scoring method
grid_obj = GridSearchCV(clf,parameters,scoring=scorer)

# TODO: Fit the grid search object to the training data and find the optimal parameters
grid_fit = grid_obj.fit(X_train,y_train)

# Get the estimator
best_clf = grid_fit.best_estimator_

# Make predictions using the unoptimized and model
predictions = (clf.fit(X_train, y_train)).predict(X_test)
best_predictions = best_clf.predict(X_test)

1 个答案:

答案 0 :(得分:1)

让我们一次拿一个:

  1. n_estimators:我认为根据n_estimators的定义,你的估算器越多,构建和用于投票的树就越多。所以,是的,你通过最大化估算器来做到这一点。

  2. learning_rate:学习率按定义确定每棵树在输出中的影响,参数控制影响的大小。要添加到最上面,你应该从非常低的learning_rate开始,可能是0.001或0.01,这将使你的模型更加健壮,因此你将能够控制你的开发/测试集中的方差。

  3. 希望这会有所帮助:)

相关问题