又从kaggle离学到一个新的知识点,下面代码是对模型特征重要性的解释
import eli5
from eli5.sklearn import PermutationImportance
#for SHAP values
import shap
from pdpbox import pdp, info_plots #for partial plots
perm = PermutationImportance(model, random_state = 0).fit(x_test, y_test)
eli5.show_weights(perm, feature_names = x_test.columns.tolist())
out:
部分特征依赖图
base_features = data.columns.values.tolist()
feat_name = 'num_major_vessels'
pdp_dist = pdp.pdp_isolate(model=model, dataset=x_test, model_features = base_features, feature = feat_name)
pdp.pdp_plot(pdp_dist, feat_name)
plt.show()