更改Python sklearn部分依赖性图中的y轴标签

我想将部分依赖性图的y轴标签从“部分依赖性”更改为“故障概率”。

此帖子与更改Python sklearn部分依赖性图中的x轴标签类似,但该解决方案不起作用,并且显然y轴是在函数中硬编码的(当前partial_dependence.py源代码的第740行)。


回答:

这些图共享y轴,因此在轴上调用set_ylabel可能无法设置正确的轴。

以下是解决方法:

fig, ax = plt.subplots(1, 1)pdp = plot_partial_dependence(    clf, X_train, features, feature_names=names, n_jobs=3, ax=ax, grid_resolution=50)pdp.axes_[0][0].set_ylabel("故障概率")

完整代码:

from sklearn.model_selection import train_test_splitfrom sklearn.ensemble import GradientBoostingRegressorfrom sklearn.inspection import plot_partial_dependencefrom sklearn.datasets import fetch_california_housingimport matplotlib.pyplot as pltcal_housing = fetch_california_housing()X_train, X_test, y_train, y_test = train_test_split(    cal_housing.data, cal_housing.target, test_size=0.2, random_state=1)names = cal_housing.feature_namesclf = GradientBoostingRegressor(    n_estimators=100, max_depth=4, learning_rate=0.1, loss="huber", random_state=1)clf.fit(X_train, y_train)features = [0, 5, 1]fig, ax = plt.subplots(1, 1)pdp = plot_partial_dependence(    clf, X_train, features, feature_names=names, n_jobs=3, ax=ax, grid_resolution=50)pdp.axes_[0][0].set_ylabel("故障概率")fig.suptitle(    "加州住房数据集中房屋价值对非位置特征的部分依赖性\n")plt.show()

结果:

输出图像,显示y轴标记为'故障概率'

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注