#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 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.

Sapmle 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