首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有没有Eli5的替代品?

有没有Eli5的替代品?
EN

Stack Overflow用户
提问于 2020-03-08 22:33:50
回答 1查看 182关注 0票数 0

(在python 2.7,3.7中尝试过)你能帮我吗?代码如下:

代码片段

代码语言:javascript
复制
feature_names = [c for c in train_df.columns if train_df[c].dtype in [np.int64]]

X = train_df[feature_names]

X = X.drop('state', axis = 1)

y = train_df['state']

X_train,X_test,y_train,y_test = train_test_split(X,y,random_state = 1)

my_model = RandomForestClassifier(n_estimators = 100,random_state = 1).fit(X_train,y_train)

perm = PermutationImportance(my_model, random_state = 1).fit(X_test,y_test)

**eli5.show_weights(perm, show_feature_values = X_test.columns.tolist())**#This prints nothing
EN

回答 1

Stack Overflow用户

发布于 2020-03-08 23:18:26

Sci-kit learn最近添加了permutation importance

这是另一种选择。

关于你的代码。试着分别打印出来看看。

你可以在你的代码末尾尝试一下:

代码语言:javascript
复制
##fit the permutation
perm = PermutationImportance(my_model, random_state = 1).fit(X_test,y_test)

##view importances
print(perm.feature_importances_)

## view with xvalues
for feat, imp in zip(X.columns,perm.feature_importances_):
    print("Feature: {}, Importance: {}".format(feat,imp))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60588536

复制
相关文章

相似问题

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