【发布时间】:2020-11-01 21:13:28
【问题描述】:
我必须在 python 中解决一个多类分类问题。
我开始使用 ensemble,我从 adaboostclassfier 开始,但在 gridsearch 之后我得到了不好的结果。
我所做的是使用调整后的分类器(在我尝试过的分类器列表中),它向我显示了作为基础估计器的最佳分数:SVC()。
然后我对 AdaBoostClassfier 的其他参数进行了网格搜索:
n_estimators: [1,50,100,150]
learning_rate: [0.1,0.4,0.7,1]
algorithm: ['SAMME']
现在我有 3 个问题要问你:
- 为什么调整后的 SVC() 显示 f1_macro 分数的 82.5%,而只有 1 个估计器的 AdaBoostClassfier 显示 18.6%?
- 为什么我无法使用 AdaBoostClassfier 提高 1 个以上的估算器的 f1_macro 分数?
- 提升是否有可能让我的数据集变得更糟,还是我做错了什么?
这是我的代码:
def adaBoost_try(train_x, train_y, test_x, test_y):
base_estimator = svm.SVC(C=60, class_weight=None, decision_function_shape='ovo', kernel='rbf', gamma=0.1, random_state=0)
classfier = AdaBoostClassifier()
pipeline = [
('scaler', scaler),
('reduce_dim', pca),
('classfier', classfier)]
best_params = [{
'scaler':[scaler_quantile],
'reduce_dim': [pca],
'reduce_dim__n_components': [15],
'classfier__base_estimator': [base_estimator],
'classfier__n_estimators': [1,50,100,150],
'classfier__learning_rate': [0.1,0.4,0.7,1],
'classfier__algorithm': ['SAMME'],
'classfier__random_state': [0]
}]
pipe = Pipeline(pipeline, memory=cachedir)
my_scoring = 'f1_macro'
n_folds = 5
gscv = GridSearchCV(pipe, param_grid=best_params, scoring=my_scoring, n_jobs=-1, cv=n_folds, refit=True)
gscv.fit(train_x, train_y)
print(gscv.best_params_)
print(gscv.best_score_)
print(gscv.score(test_x,test_y))
【问题讨论】:
标签: python scikit-learn classification adaboost boosting