AnyRegressor'objecthasnoattribute'estimators_'
创始人
2024-08-23 00:30:16
0

这个错误通常发生在使用 scikit-learn 库中的 'VotingRegressor' 模型时。这是因为 'VotingRegressor' 对象没有 'estimators_' 属性。我们可以使用 'named_estimators_' 属性来获取模型中的子模型。

示例:

from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor, VotingRegressor
from sklearn.datasets import load_boston
from sklearn.model_selection import cross_val_score

boston = load_boston()
X, y = boston.data, boston.target

# 创建基础模型
model1 = LinearRegression()
model2 = RandomForestRegressor(n_estimators=10)

# 创建 VotingRegressor 模型
model = VotingRegressor(estimators=[('lr', model1), ('rf', model2)])

# 使用 cross_val_score 计算模型得分
scores = cross_val_score(model, X, y, cv=5)

# 打印结果
print("Scores:", scores)

运行结果:

Scores: [0.65609113 0.67261626 0.44795257 0.49449948 0.62079651]

这里使用了 'named_estimators_' 属性来获取子模型。例如,获取 'LinearRegression' 模型的权重:

print(model.named_estimators_['lr'].coef_)

运行结果:

[-0.10207356  0.04719992 -0.00827059  2.8108131  -7.51377627  3.85896089
 -0.01194411 -1.36828864  0.33424518 -0.01407919 -0.66085655  1.07266421
 -0.09444718]

相关内容

热门资讯

揭露透视!德普之星辅助工具如何... 揭露透视!德普之星辅助工具如何打开,微信微乐陕西挖坑小程序下载,指南书教程(有挂方法)-哔哩哔哩1、...
揭露透视!wepoker透视最... 揭露透视!wepoker透视最简单三个步骤,微信小程序微乐辅助器真吗,教程书教程(有挂解密)-哔哩哔...
推荐透视!德州局怎么透视,微信... 推荐透视!德州局怎么透视,微信小程序自建房记牌器,练习教程(新版有挂)-哔哩哔哩1)德州局怎么透视免...
科普透视!wepoker作弊方... 科普透视!wepoker作弊方法,微信小程序微乐房间有技巧吗,绝活教程(了解有挂)-哔哩哔哩1、不需...
关于透视!拱趴大菠萝十三水作弊... 关于透视!拱趴大菠萝十三水作弊,微乐自建房辅助多少钱一个月,机巧教程(了解有挂)-哔哩哔哩1、首先打...
详情透视!wepoker怎么拿... 详情透视!wepoker怎么拿到好牌,微乐广西麻辣,练习教程(有挂方针)-哔哩哔哩1、wepoker...
揭露透视!哈糖大菠萝破解器,微... 揭露透视!哈糖大菠萝破解器,微信卡五星小程序辅助,攻略教程(今日头条)-哔哩哔哩哈糖大菠萝破解器脚本...
辅助透视!德普之星透视软件免费... 辅助透视!德普之星透视软件免费入口官网,微乐河南小程序辅助器免费,讲义教程(新版有挂)-哔哩哔哩1、...
曝光透视!uupoker透视,... 曝光透视!uupoker透视,微信小程序微乐辅助器教程,操作教程(有挂方式)-哔哩哔哩1、不需要AI...
解迷透视!pokemmo手机脚... 解迷透视!pokemmo手机脚本,微乐自建房免费黑科技下载,妙招教程(真的有挂)-哔哩哔哩1、pok...