【问题标题】:Is there any alternative to Eli5?Eli5 有什么替代品吗?
【发布时间】:2020-06-20 15:12:21
【问题描述】:

我试图通过使用 Eli5 来计算排列重要性,但是命令 eli5.show_weights 不会获取任何图像或任何东西。 (在 python 2.7、3.7 中试过)你能帮忙吗? 代码如下:

代码片段

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

【问题讨论】:

    标签: eli5


    【解决方案1】:

    Sci-kit learn 最近添加了permutation importance。

    这是另一种选择。

    关于您的代码。我认为您没有看到任何内容的原因是因为 X_test 可能没有列,因为它是一个 numpy 数组。尝试单独打印出来看看。

    另一种选择是将排列重要性作为fitted model 的属性访问。

    您可以在代码末尾尝试:

    ##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))
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 2022-11-10
      • 1970-01-01
      • 1970-01-01
      • 2010-12-13
      • 2023-03-08
      相关资源
      最近更新 更多