如何解决Sklearn部分依赖图返回ValueError:百分位数彼此太近
我想用目标值绘制某些输入变量的部分依赖图。我使用sklearn训练了梯度提升模型,然后使用获得的模型运行了from django.conf import settings
from storages.backends.s3boto3 import S3Boto3Storage
class StaticStorage(S3Boto3Storage):
location = settings.AWS_STATIC_LOCATION
class MediaStorage(S3Boto3Storage):
location = settings.DEFAULT_FILE_STORAGE_LOCATION
file_overwrite = False
。但是,我收到sklearn.inspection.plot_partial_dependence
错误。知道如何解决这个问题吗?
这是我的代码:
ValueError: percentiles are too close to each other,unable to build the grid. Please choose percentiles that are further apart
我遇到以下错误:
columns = ['zip','t-s','r','f','m-t','ir','if','n-d-m','t-n-d','a-d-f-l-d-t','a-d-f-l-a-t','a']
print("Training GradientBoostingRegressor...")
est = HistGradientBoostingRegressor()
est.fit(inputsTrain,outputsTrain)
print("Test R2 score: {:.2f}".format(est.score(inputsTest,outputsTest)))
print('Computing partial dependence plots...')
features = columns + [('zip','r')]
plot_partial_dependence(est,inputsTrain,features,n_jobs=3,grid_resolution=20)
fig = plt.gcf()
fig.subplots_adjust(wspace=0.4,hspace=0.3)
解决方法
已经晚了,但我还是会回答。
您需要向percentiles
(或plot_partial_dependence
)中添加一个partial_dependence
参数。
默认值为(0.05,0.95)
,如果引发此异常,则需要将其替换为(a,b)
,以使a
和b
相距0.05和0.95。
您能走得最远的是(0,1)
。
以您的情况为例,您可以编写:
plot_partial_dependence(est,inputsTrain,features,n_jobs=3,grid_resolution=20,percentiles=(0,1))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。