hemreddy2005 / Implementation-of-Simple-Linear-Regression-Model-for-Predicting-the-Marks-Scored

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementation-of-Simple-Linear-Regression-Model-for-Predicting-the-Marks-Scored

AIM:

To write a program to predict the marks scored by a student using the simple linear regression model.

Equipments Required:

  1. Hardware – PCs
  2. Anaconda – Python 3.7 Installation / Jupyter notebook

Algorithm

  1. Start the program.

2.Import the standard Libraries.

3.Set variables for assigning dataset values.

4.Import linear regression from sklearn.

5.Assign the points for representing in the graph.

6.Predict the regression for marks by using the representation of the graph.

7.End the program.

Program:

/*
Program to implement the simple linear regression model for predicting the marks scored.
Developed by: Hemanth Kumar R
RegisterNumber:  212223040065
*/
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import mean_absolute_error,mean_squared_error
df=pd.read_csv("C:/Users/SEC/Downloads/student_scores.csv")
df.head()
df.tail()
X=df.iloc[:,:-1].values
X
Y=df.iloc[:,1].values
Y
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test=train_test_split(X,Y,test_size=1/3,random_state=0)
from sklearn.linear_model import LinearRegression
regressor=LinearRegression()
regressor.fit(X_train,Y_train)
Y_pred=regressor.predict(X_test)
Y_pred
Y_test
plt.scatter(X_train,Y_train,color="orange")
plt.plot(X_train,regressor.predict(X_train),color="red")
plt.title("Hours Vs Scores(Training Set)")
plt.xlabel("Hours")
plt.ylabel("Scores")
plt.show()
plt.scatter(X_test,Y_test,color='purple')
plt.plot(X_train,regressor.predict(X_train),color='yellow')
plt.title("Hours vs Scores(Testing set)")
plt.xlabel("Hours")
plt.ylabel("Scores")
plt.show()
mse=mean_squared_error(Y_test,Y_pred)
print('MSE = ',mse)
mae=mean_absolute_error(Y_test,Y_pred)
print('MAE = ',mae)
rmse=np.sqrt(mse)
print("RMSE = ",rmse)  

Output:

df.head()

Img 1

df.tail()

Img 2

Array Value of x

Img 3

Array value of y

Img 4

Values of y prediction

Img 5

Array values of Y test

Img 6

Training set graph

Img 7

Test set graph

Img 8

Values of MSE,MAE and RMSE

Img 9

Result:

Thus the program to implement the simple linear regression model for predicting the marks scored is written and verified using python programming.

About

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Jupyter Notebook 100.0%