如本post中所述,可以通过以下公式计算调整后的R2分数,其中n
是样本数,p
是模型的参数数
adj_r2 = 1-(1-R2)*(n-1)/(n-p-1)
根据另一个post,我们可以使用model.coef_
获取模型的参数数量。
但是,对于梯度增强(GBM),似乎我们无法获得模型中的参数数量:
from sklearn.ensemble import GradientBoostingRegressor
import numpy as np
X = np.random.randn(100,10)
y = np.random.randn(100,1)
model = GradientBoostingRegressor()
model.fit(X,y)
model.coef_
output >>>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-3-4650e3f7c16c> in <module>
----> 1 model.coef_
AttributeError: 'GradientBoostingRegressor' object has no attribute 'coef_'
检查documentation后,GBM似乎由不同的估计量组成。估计器的数量等于参数的数量吗?
仍然,我无法获得每个估计量的参数数量
model.estimators_[0][0].coef_
output >>>
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-27216ebb4944> in <module>
----> 1 model.estimators_[0][0].coef_
AttributeError: 'DecisionTreeRegressor' object has no attribute 'coef_'
如何计算GBM的调整后R2分数?