我需要使用溜冰者图的部分依赖性来解释模型的性能。 但是情节没有显示任何东西。 这是我尝试的代码。
import xgboost as xgb
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
from skater.core.explanations import Interpretation
from skater.model import InMemoryModel
X = X = pd.read_csv("xyz")
y = X['class']
X.drop('class', axis=1, inplace=True)
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.30, random_state=0)
xgc = xgb.XGBClassifier(n_estimators=500, max_depth=5, base_score=0.5,
objective='binary:logistic', random_state=42)
xgc.fit(X_train, y_train)
interpreter = Interpretation(training_data=X_test, training_labels=y_test,
feature_names=list(X.columns))
interpreter.load_data(X_train, feature_names=list(X.columns))
im_model = InMemoryModel(xgc.predict_proba, examples=X_train,
target_names=[0,1])
r = interpreter.partial_dependence.plot_partial_dependence(['Age'], im_model, grid_resolution=50,
grid_range=(0,1), n_samples=23000,
with_variance=True, figsize = (6, 4),progressbar=False)
yl = r[0][1].set_ylim(0, 1)
r的类型是一个列表。 该代码正在运行,没有任何错误,但未显示任何内容。
我关注了https://towardsdatascience.com/explainable-artificial-intelligence-part-3-hands-on-machine-learning-model-interpretation-e8ebe5afc608 enter link description here