As mentioned in this post, the adjusted R2 score can be calculated via the following equation, where n
is the number of samples, p
is the number of parameters of the model.
adj_r2 = 1-(1-R2)*(n-1)/(n-p-1)
According this another post, we can get the number of parameters of our model with model.coef_
.
However, for Gradient Boosting (GBM), it seems we cannot obtain the number of parameters in our model:
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_'
After checking the documentation, it seems GBM consists of different estimators. Is the number of estimators equals to the number of parameters?
Still, I cannot get the number of parameters for each individual estimator
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_'
How to calculate the adjusted R2 score for GBM?