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]

相关内容

热门资讯

软件辅助挂!wepower软件... 软件辅助挂!wepower软件透明挂,来玩app辅助工具-的确是有挂的(透牌教程);软件辅助挂!we...
透明辅助挂!wEPOKE软件透... 透明辅助挂!wEPOKE软件透明挂,wopoker外挂-就是真的有挂(详细教程);人气非常高,ai更...
wepoke辅助!we辅助po... wepoke辅助!we辅助poker软件透明挂,wepoke是是有挂-总是真的有挂(新版2025教程...
wpk辅助!WePoKer软件... wpk辅助!WePoKer软件透明挂,fishpoker app辅助-好像真的有挂(2025新版总结...
智能辅助!wEpOke软件透明... 一、德州简介了解软件请加微:136704302德州是一款在线扑克游戏平台,玩家可以在平台上进行多人在...
脚本辅助挂!wEPoke软件透... 脚本辅助挂!wEPoke软件透明挂,governorofpoker3辅助-就是真的有挂(高科技教程)...
透视辅助挂!WepOke软件透... 透视辅助挂!WepOke软件透明挂,哈糖大菠萝可以拿好牌-的确真的有挂(扑克教程);无聊就玩这款哈糖...
透视辅助!wEpoKe软件透明... 透视辅助!wEpoKe软件透明挂,德扑人工智能软件-一直真的有挂(介绍教程);无聊就玩这款德扑真的有...
黑科技辅助!wEpoKe软件透... 黑科技辅助!wEpoKe软件透明挂,哈糖大菠萝切牌规律-好像真的有挂(攻略方法)1、这是跨平台的哈糖...
黑科技辅助!德州wepower... 黑科技辅助!德州wepower软件透明挂,德扑之星可以查数据-一般真的有挂(扑克教程);无聊就玩这款...