首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有一个热编码特征的Auto-Sklearn中的特征和特征重要性

具有一个热编码特征的Auto-Sklearn中的特征和特征重要性
EN

Stack Overflow用户
提问于 2019-01-04 16:50:26
回答 1查看 1.2K关注 0票数 2

我正在尝试使用Auto-Sklearn训练一个XGBoost模型。

https://automl.github.io/auto-sklearn/stable/

模型训练得很好,然而,我需要特征重要性来改进模型和报告目的。

autosklearn.classification.AutoSklearnClassifier没有可以为我做这件事的函数。

我正在尝试从底层管道中获取功能和功能重要性得分。

我已经使用下面的GitHub问题中给出的细节尝试了一些东西。

1) https://github.com/automl/auto-sklearn/issues/524

2) https://github.com/automl/auto-sklearn/issues/224

我也尝试过使用“Trace”python模块。这返回了超过900,000行代码。不知道从何说起。

我的代码正在开发中,但看起来像这样:

代码语言:javascript
复制
import pandas as pd
import numpy as np
import autosklearn.classification
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics
import datetime
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score, roc_curve, auc
from sklearn import preprocessing
from sklearn.preprocessing import LabelEncoder
import eli5 as eli
import pdb
df = pd.read_csv('titanic_train.csv')
df_target = df['Survived']
drop_Attbr = ['PassengerId', 'Name', 'Ticket', 'Cabin','Survived','Sex','Embarked']
df_labels = df.drop(drop_Attbr,axis=1)
feature_types = ['categorical'] +['numerical']+(['categorical']* 2)+['numerical']
df_train, df_test, y_train, y_test = train_test_split(df_labels, df_target, test_size=1/3, random_state=42)
automl = autosklearn.classification.AutoSklearnClassifier(
        time_left_for_this_task=15,
        per_run_time_limit=5,
        ensemble_size=1,
        disable_evaluator_output=False,
        resampling_strategy='holdout',
        resampling_strategy_arguments={'train_size': 0.67},
        include_estimators=['xgradient_boosting']
    )
automl.fit(df_train, y_train,feat_type=feature_types)
y_hat = automl.predict(df_test)
a_score = sklearn.metrics.accuracy_score(y_test, y_hat)
print("Accuracy score "+str(a_score))

我希望得到如下结果:

代码语言:javascript
复制
Feature 1 : Feature Importance score 1;
Feature 2 : Feature Importance score 2;
Feature 3 : Feature Importance score 3;
Feature 4 : Feature Importance score 4;
Feature 5 : Feature Importance score 5;
EN

回答 1

Stack Overflow用户

发布于 2019-01-05 00:14:26

尝尝这个!

代码语言:javascript
复制
for identifier in automl._automl._automl.model_:
    if identifier in automl.ensemble_.get_selected_model_identifiers():
        model = automl._automl._automl.models_[identifier].pipeline_._final_estimator()
        print(model.get_score())   
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54035645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档