To write a program to predict the marks scored by a student using the simple linear regression model.
- Hardware โ PCs
- Anaconda โ Python 3.7 Installation / Jupyter notebook
1.Import the standard Libraries
2.Set variables for assigning dataset values
3.Import linear regression from sklearn.
4.Compare the graphs and hence we obtained the linear regression for the given data
/*
Program to implement the simple linear regression model for predicting the marks scored.
Developed by: Naveen S
RegisterNumber: 212222240070
/*
Program to implement the simple linear regression model for predicting the marks scored.
Developed by:Thrikeswar.P
RegisterNumber:212222230162
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('student_scores.csv')
df.head()
df.tail()
#segregating data to variables
X=df.iloc[:,:-1].values
X
Y=df.iloc[:,-1].values
Y
#spitting train and test data
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)
#display predicted values
Y_pred
#display actual values
Y_test
#graph plot for training data
plt.scatter(X_train,Y_train,color="orange")
plt.plot(X_train,regressor.predict(X_train),color="Red")
plt.title("Hours vs Scores (Test set)")
plt.xlabel("Hours")
plt.ylabel("Scores")
plt.show()
plt.scatter(X_test,Y_test,color="orange")
plt.plot(X_train,regressor.predict(X_train),color="black")
plt.title("Hours vs Scores (Test set)")
plt.xlabel("Hours")
plt.ylabel("Scores")
plt.show()
mse=mean_absolute_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)
*/
*/
df head()
df tail()
Array value of X
Array value of y
values of Y prediction
Array value of Y test
Training set Graph
Test set Graph
Values of MSE,MAE and RMSE
Thus the program to implement the simple linear regression model for predicting the marks scored is written and verified using python programming.