如何提取特征重要性lr.系数从GridSearchCV创建的模型?

2024-09-19 20:50:45 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从GridSearchCV创建的模型中提取feature_importances_和{}?我尝试过用调整过的超参数手动拟合模型,以便能够使用函数,但结果(即auc)是不同的。在

pipelines = {
'rf' : make_pipeline(StandardScaler(), 
RandomForestClassifier(random_state=521)),
'l1' : make_pipeline(StandardScaler(), LogisticRegression(penalty='l1' , 
random_state=521))
}

rf_hyperparams = {
'randomforestclassifier__n_estimators': [100, 110],
'randomforestclassifier__max_features': ['auto', 'sqrt']
}

l1_hyperparams = {
'logisticregression__C': np.linspace(1e-3, 10)
}

hyperparams = {
'rf' : rf_hyperparams,
'l1' : l1_hyperparams
}

fitted = {}
for name, pipeline in pipelines.items():
    model = GridSearchCV(pipeline, hyperparams[name], cv=10, n_jobs=-1)
    model.fit(X_train, y_train) 
    fitted[name] = model

Tags: name模型l1makemodelpipelinerandomstate