0
点赞
收藏
分享

微信扫一扫

shap库进行特征重要性排名。

钎探穗 2022-03-24 阅读 41
python

最近把之前没写完的一篇文章拿出来重新改,里面一张柱状图真是显得很low,
于是在浏览博客时发现了一张很惊艳的图
在这里插入图片描述
瞬间觉得柱状图low爆了,于是各种找方法,终于找到了shap库,pip install shap安排上
导入库
anaconda search -t shap
pip install --channel 链接
下载完成

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.inspection import permutation_importance
import shap
from matplotlib import pyplot as plt

data = pd.read_csv("./new_data.csv")
X= data.loc[:,data.columns!='EGFR']
y=data.loc[:, "EGFR"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25, random_state=12)
rf = RandomForestRegressor(n_estimators=100)
rf.fit(X_train, y_train)
explainer = shap.TreeExplainer(rf)
shap_values = explainer.shap_values(X_test)
shap.summary_plot(shap_values, X_test)

结果

在这里插入图片描述
瞬间高大上

举报

相关推荐

0 条评论