如何在管道中包含的模型中访问最佳估计器参数?

我有以下sklearn管道:

Pipeline(memory=None,steps=[('feature_processor',DataProcessor()),('classifier',GridSearchCV(cv=15,error_score='raise-deprecating',estimator=XGBClassifier(base_score=0.5,booster='gbtree',colsample_bylevel=1,colsample_bynode=1,colsample_bytree=1,gamma=0,learning_rate=0.1,max_delta_step=0,..._dispatch='2*n_jobs',refit=True,return_train_score='warn',scoring='accuracy',verbose=1))
            ])

内部有一个训练有素的模型,该参数使用GridSearchCV进行了优化。带有管道的模型被保存到一个泡菜中。我正在使用pickle.load()来读回它,但是现在我不知道如何访问GridSearchCV发现的最佳参数。

能请人指出正确的方向吗?

如果无法通过管道的信息访问此信息,是否还有其他方法可以实现?

非常感谢您

mgdbrrr 回答:如何在管道中包含的模型中访问最佳估计器参数?

通过您的示例,您可以通过以下方式获得最佳模型:

loaded_pipe = pickle.load(open("<your_pkl_file>",'rb'))
loaded_pipe['classifer'].best_estimator_

编辑:

仅用于最佳参数:

loaded_pipe['classifer'].best_params_
,

尝试一下:

pipeline.named_steps['classifier'].best_params_
本文链接:https://www.f2er.com/3103233.html

大家都在问