How to extract the regression coefficient from statsmodels api

0 votes
 result = sm.OLS(gold_lookback, silver_lookback ).fit()

After I get the result, how can I get the coefficient and the constant? In other words, if y = ax + c how to get the values a and c?

Mar 15, 2022 in Machine Learning by Nandini
• 5,480 points
9,524 views

1 answer to this question.

0 votes

The coefficients can be obtained using the params attribute of a fitted model.

Consider the following code:

import statsmodels.api as sm
import numpy as np 
np.random.seed(1) 
val_x = sm.add_constant(np.arange(100))
val_ y = np.dot(val_x, [1,2]) + np.random.normal(size=100) 
output = sm.OLS(val_y, val_x).fit() 
print(output.params)

It will print a numpy array with the values [0.89516052 2.00334187] for the intercept and slope, respectively.
If you need more information, utilize the output.summary() object, which has three full tables with model descriptions.

Read the Artificial Intelligence tutorial to learn more about Artificial Intelligence and Machine Learning. Also, enrol in Machine Learning Course to become proficient.

answered Mar 17, 2022 by Dev
• 6,000 points

Related Questions In Machine Learning

+1 vote
1 answer

how to analysis the heatmap to find the correlation

Hi @Vikas, there are 5 simple steps ...READ MORE

answered Sep 30, 2019 in Machine Learning by Vishal
10,545 views
0 votes
1 answer

How to load a model from an HDF5 file in Keras?

Hi@akhtar, If you stored the complete model, not ...READ MORE

answered Jul 14, 2020 in Machine Learning by MD
• 95,460 points
6,360 views
0 votes
1 answer

How to import the BatchNormalization function in Keras?

Hi@akhtar, The general use case is to use ...READ MORE

answered Jul 29, 2020 in Machine Learning by MD
• 95,460 points
3,638 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to find the intersecting point in the regression line

To find the intersecting point use the ...READ MORE

answered Apr 5, 2022 in Machine Learning by Dev
• 6,000 points
1,056 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP