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
-
Read the given dataset
-
Assign values for x and y and plot them
-
Split the dataset into train and test data
-
Import linear regression and train the data
-
find Y predict
-
Plot train and test data
-
Calculate mse,mae and rmse
/*
Program to implement the simple linear regression model for predicting the marks scored.
Developed by:S.SRIMATHI
RegisterNumber:212220040160
import numpy as np
import pandas as pd
dataset=pd.read_csv('/content/student_scores.csv')
dataset.head()
dataset.tail()
#assingning hrs to x and scores to y
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,1].values
print(x)
print(y)
x=dataset.iloc[:,:-1].values
y=dataset.iloc[:,1].values
print(x)
print(y)
import matplotlib.pyplot as plt
from sklearn.metrics import mean_absolute_error, mean_squared_error
plt.scatter(x_train,y_train,color='grey')
plt.plot(x_train,reg.predict(x_train),color='magenta')
plt.title('Training set(H vs S)')
plt.xlabel('Hours')
plt.ylabel('Scores')
plt.show()
plt.scatter(x_test,y_test,color='magenta')
plt.plot(x_test,reg.predict(x_test),color='grey')
plt.title('Test set(H vs S)')
plt.xlabel('Hours')
plt.ylabel('Scores')
plt.show()
print(y_predict)
print(y_test)
mse=mean_squared_error(y_test,y_predict)
print('MSE = ',mse)
mae=mean_absolute_error(y_test,y_predict)
print('MAE = ',mae)
import numpy as np
np. sqrt(3)
rmse=np.sqrt(mse)
print('RMSE = ',rmse)
*/
Thus the program to implement the simple linear regression model for predicting the marks scored is written and verified using python programming.