【问题标题】:AttributeError: 'RandomForestRegressor' object has no attribute 'coef_'AttributeError:“RandomForestRegressor”对象没有属性“coef_”
【发布时间】:2020-12-20 18:22:08
【问题描述】:

我已经使用随机森林回归器来解决回归问题,现在我想绘制回归线,根据this 的答案,我正在尝试这个。

w =  model1.coef_[0]
a = -w[0] / w[1]
xx = np.linspace(-5, 5)
yy = a * xx - (model1.intercept_[0]) / w[1]

plt.plot(xx, yy, 'k-')

其中 model1 是 sklearn.ensemble.RandomForestRegressor,它已经适合数据集。有哪些替代方案。

错误信息是

AttributeError: 'RandomForestRegressor' object has no attribute 'coef_'

【问题讨论】:

标签: python scikit-learn random-forest


【解决方案1】:

当模型拟合超平面时,您将拥有 coef_intercept_。线性回归就是这样一种模型,它沿着训练数据拟合超平面,使得偏差/误差最小。这些coef_intercept_ 代表超平面。

但是,像随机森林这样的模型并不适合超平面,而是根据最终导致预测的输入来识别一组决策。您可以将它们视为一组嵌套的 if else 条件。因此,如果您的模型是基于随机森林的,则没有 coef_intercept_ 的概念,但您可以做的是打印决策树。

【讨论】:

    猜你喜欢
    • 2020-03-30
    • 2016-12-03
    • 2021-12-27
    • 2020-10-27
    • 2020-03-13
    • 2012-12-01
    • 2021-04-19
    • 2021-11-22
    • 1970-01-01
    相关资源
    最近更新 更多