Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 在Python Bagging分类器中将最佳网格搜索超参数分配到最终模型中_Python 3.x_Machine Learning_Scikit Learn_Classification_Hyperparameters - Fatal编程技术网

Python 3.x 在Python Bagging分类器中将最佳网格搜索超参数分配到最终模型中

Python 3.x 在Python Bagging分类器中将最佳网格搜索超参数分配到最终模型中,python-3.x,machine-learning,scikit-learn,classification,hyperparameters,Python 3.x,Machine Learning,Scikit Learn,Classification,Hyperparameters,我正在训练逻辑回归和使用袋装。我想使用gridsearch CV查找最佳超参数。我用‘‘‘’表示基估计量的超参数: from sklearn.linear_model import LogisticRegression from sklearn.ensemble import BaggingClassifier param_grid = { 'base_estimator__C': [1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20,

我正在训练逻辑回归和使用袋装。我想使用gridsearch CV查找最佳超参数。我用‘‘‘’表示基估计量的超参数:

from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import BaggingClassifier

param_grid = {
    'base_estimator__C': [1e-15, 1e-10, 1e-8, 1e-4, 1e-3, 1e-2, 1, 5, 10, 20, 50, 100, 1000], # lambdas for regularization
    'max_samples': [0.05, 0.1, 0.2, 0.5], # for bootstrap sampling
    'max_features': [0.3,0.5,0.7,0.9]} 



clf = GridSearchCV(BaggingClassifier(LogisticRegression(penalty='l2'),
                                            n_estimators = 100),
                        param_grid, cv=cv, scoring='f1', return_train_score=True)
clf.fit(x,y)
best_hyperparams = clf.best_params_
best_hyperparams

Results:
{'base_estimator__C': 10, 'max_features': 0.3, 'max_samples': 0.1}
既然我已经得到了最好的参数,我该如何再次将其放入装袋分类器?使用**best_超参数不起作用,因为Bagging分类器无法识别基本估计量_uC应进入基本估计量Logistic回归

best_clf = BaggingClassifier(LogisticRegression(penalty='l2'), n_estimators = 100, **best_hyperparams) # train model with best hyperparams
您可以在初始化装袋分类器后使用

best_clf = BaggingClassifier(LogisticRegression(penalty='l2'), n_estimators = 100)
best_clf.set_params(**best_hyperparams)