#5, First Floor, 4th Street , Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to take linear regression model summary using statsmodels library in python?
Description

To take the summary of linear regression model for the given data set using python.

Process

   Import necessary libraries.

  Load the sample data set.

  Assign the independent(X)and dependent(y)variables.

  Pass the variables to the model.

  In sklearn library,dont have method like summary()

Sapmle Code

#import related libraries

import pandas as pd

#import stats model

import statsmodels.api as sm

#load sample data

data={‘salary’:[100,200,300,

400,500,400,300,200,100,50],

‘age’:[25,26,25,23,30,29,23,23,25,25],

‘rating’:[4,3.24,2.5,2.25,2,2.25,2.5,

2.75,3.2,4.2], ‘bonus’:[2500,1200,900

,3000,1800,1400,850,250,750,1000]}

#create data frame

df=pd.DataFrame(data)

#assign independent variable

X = df.iloc[:, :1].values

#assign dependent variable

y = df.iloc[:, 3].values

#build regression model

model=sm.OLS(y,X).fit()

#take summary of model

result=model.summary()

#print the result

print(result)

Screenshots