title: How to calculate adjusted R2 score for non-linear models
body: <p>As mentioned in this <a href="https://stackoverflow.com/questions/51038820/how-to-calculated-the-adjusted-r2-value-using-scikit">post</a>, the adjusted R2 score can be calculated via the following equation, where <code>n</code> is the number of samples, <code>p</code> is the number of parameters of the model.</p>
  
  <pre><code>adj_r2 = 1-(1-R2)*(n-1)/(n-p-1)
  </code></pre>
  
  <p>According this another <a href="https://stackoverflow.com/questions/42033720/python-sklearn-multiple-linear-regression-display-r-squared/42392200">post</a>, we can get the number of parameters of our model with <code>model.coef_</code>.</p>
  
  <p>However, for Gradient Boosting (GBM), it seems we cannot obtain the number of parameters in our model:</p>
  
  <pre><code>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 &gt;&gt;&gt; 
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-3-4650e3f7c16c&gt; in &lt;module&gt;
  ----&gt; 1 model.coef_
  
  AttributeError: 'GradientBoostingRegressor' object has no attribute 'coef_'
  </code></pre>
  
  <p>After checking the <a href="https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html?highlight=gradientboosting#sklearn.ensemble.GradientBoostingRegressor" rel="nofollow noreferrer">documentation</a>, it seems GBM consists of different estimators. Is the number of estimators equals to the number of parameters?</p>
  
  <p>Still, I cannot get the number of parameters for each individual estimator</p>
  
  <pre><code>model.estimators_[0][0].coef_
  
  
  output &gt;&gt;&gt; 
  ---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-2-27216ebb4944&gt; in &lt;module&gt;
  ----&gt; 1 model.estimators_[0][0].coef_
  
  AttributeError: 'DecisionTreeRegressor' object has no attribute 'coef_'
  </code></pre>
  
  <p>How to calculate the adjusted R2 score for GBM?</p>