1

I'm trying to find the goodness of fit for a model I have generated.

Premise:

I used scipy.optimize.minimize to find the coefficients of the following regression:

Y = B * X + e

where B and X have between 3 and 5 elements depending on the iteration.

I used the minimize package to comply with the following constraints

b >= 0
sum(b) = 1

Therefore, now as I know the value of the coefficients, I need to calculate the r-sq to assess which model has the best fit. Is this possible to do in python?

  • Possible duplicate of [How do I calculate r-squared using Python and Numpy?](https://stackoverflow.com/questions/893657/how-do-i-calculate-r-squared-using-python-and-numpy) – FlyingTeller Oct 05 '18 at 12:15
  • most likely, I've just gone ahead and calculated it by hand so I'm happy to close this question –  Oct 05 '18 at 12:43
  • I use the calculation for R-squared (R2) as "R2 = 1.0 - (absolute_error_variance / dependent_data_variance)" and use the numpy array var() method, so in my code this becomes "R2 = 1.0 - (abs_err.var() / dep_data.var())" – James Phillips Oct 05 '18 at 14:17

0 Answers0