我已经用Python制作了一个随机森林分类器模型,现在想要制作部分依赖图(PDP)。我使用缩放数据来训练和测试模型,并使 PDP 如下所示:
PartialDependenceDisplay.from_estimator(best_clf, X_test_final, best_features)
。然而,x 轴值是按比例缩放的,这限制了可解释性。
在调用
X_test_final
之前取消缩放数据 PartialDependenceDisplay
不起作用,有关如何将 x 轴值从缩放更改为未缩放的任何建议?我已经使用 StandardScaler()
缩放了我的数据。
取消标准化数据的缩放比例很简单。要标准化数据,您需要执行以下操作:
X' = (X - mean(X)) / std(X)
因此要取消缩放,您只需执行X = (X' * std(X)) + mean(X)
即可。
如果您只想更改刻度标签,以便可以按照数据的原始比例解释结果,那么您只需执行以下操作:
# Get the tick positions on the current axis
x_ticks = ax.get_xticks()
# Un-standardise the tick values
xt_unscaled = [(xt * x.std()) + x.mean() for xt in x_ticks]
# Format the ticks to strings (here to 1 d.p.)
xt_unscaled = [f'{xt:.1f}' for xt in xt_unscaled]
# Assign the unscaled tick values to the tick labels
# This retains the original tick positions etc, but
# lets you interpret them the way you want.
ax.set_xticklabels(xt_unscaled)
plt.show()