Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to make prediction in multiple linear regression using statsmodel library in python?

Description

To make prediction for multiple regression model using python.

Process

   Import necessary libraries.

   Load the sample data set.

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

   Build the regression model.

   Make prediction.

Sample Code

#import libraries

import statsmodels.api as sm

import pandas as pd

#read the data set

data=pd.read_csv(‘/home/soft27/soft27

/Sathish/Pythonfiles/Employee.csv’)

#creating data frame

df=pd.DataFrame(data)

print(df)

#assigning the independent variable

X = df[[‘rating’,’bonus’]]

#assigning the dependent variable

Y = df[‘salary’]

#Build multiple linear regression

X = sm.add_constant(X)

#fit the variables in to the linear model

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

#print the intercept and regression co-efficients

print_model = model.summary()

print(print_model)

#make predictions

predictions = model.predict(X)

df1=pd.DataFrame({‘Actual’: Y, ‘Predicted’: predictions})

print(df1)

Screenshots
make prediction in multiple linear regression
read the data set