'Reading coef value from OLS regression results
I use pandas and statsmodels to do linear regression. However, i can't find any possible way to read the results. the results are displayed but i need to do some further calculations using coef values. is there any possible way to store coef values into a new variable?
import statsmodels.api as sm
import numpy
ones = numpy.ones(len(x[0]))
t = sm.add_constant(numpy.column_stack((x[0], ones)))
for m in x[1:]:
t = sm.add_constant(numpy.column_stack((m, t)))
results = sm.OLS(y, t).fit()
Solution 1:[1]
According to the docs, an instance of RegressionResults is returned.
You can see all the available attributes there.
Maybe you are interested in:
params
The linear coefficients that minimize the least squares criterion. This is usually called Beta for the classical linear model.
Example:
model = sm.OLS(Y,X)
results = model.fit()
print(results.params)
Solution 2:[2]
Try this:
B0, B1, B2, B3 = modelo.params
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | sascha |
Solution 2 | lcarboneto |