16장 회귀 모델의 해석
회귀 모델을 해석하는 방법들을 다룹니다.
import xgboost as xgb
xgr = xgb.XGBRegressor(
random_state=42, base_score=0.5
)
xgr.fit(bos_X_train, bos_y_train)
sample_idx = 5
xgr.predict(bos_X.iloc[[sample_idx]])
import shap
shap.initjs()
exp = shap.TreeExplainer(xgr)
vals = exp.shap_values(bos_X)
shap.force_plot(
exp.expected_value,
vals[sample_idx],
bos_X.iloc[sample_idx],
)
shap.initjs()
shap.force_plot(
exp.expected_value, vals, bos_X
)
import matplotlib.pyplot as plt
shap.dependence_plot("LSTAT", vals, bos_X)
shap.dependence_plot(
"DIS", vals, bos_X, interaction_index="RM"
)
shap.summary_plot(vals, bos_X)