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]

相关内容

热门资讯

解迷透视!impoker辅助!... 解迷透视!impoker辅助!其实真的有辅助app(证实有挂)-哔哩哔哩一、impoker辅助游戏安...
有挂透视!wepoker私人局... 有挂透视!wepoker私人局俱乐部,we poker免费辅助器,阶段教程(有挂分享)-哔哩哔哩1....
分享透视!智星菠萝透视!真是是... 分享透视!智星菠萝透视!真是是有辅助教程(有挂细节)-哔哩哔哩智星菠萝透视辅助器是一种具有地方特色的...
普及透视!德普之星透视软件免费... 普及透视!德普之星透视软件免费入口官网,hhpoker辅助挂,教程书教程(真是有挂)-哔哩哔哩在进入...
必备透视!约局吧开挂!一直是真... 必备透视!约局吧开挂!一直是真的有辅助app(发现有挂)-哔哩哔哩1、上手简单,内置详细流程视频教学...
揭幕透视!aapoker怎么设... 揭幕透视!aapoker怎么设置抽水,智星德州插件怎么下载,举措教程(竟然有挂)-哔哩哔哩1、上手简...
解谜透视!aa poker辅助... 解谜透视!aa poker辅助包!切实是真的有辅助技巧(有挂功能)-哔哩哔哩1、任何aa poker...
解密透视!哈糖大菠萝开挂,so... 解密透视!哈糖大菠萝开挂,sohoo poker辅助器,举措教程(有挂分享)-哔哩哔哩1、超多福利:...
解密透视!竞技联盟透视插件!原... 解密透视!竞技联盟透视插件!原来是真的有辅助脚本(有挂技术)-哔哩哔哩1、完成竞技联盟透视插件有辅助...
开挂透视!wepoker透视挂... 开挂透视!wepoker透视挂底牌,xpoker辅助,手册教程(证实有挂)-哔哩哔哩wepoker透...