0% found this document useful (0 votes)
4 views5 pages

HK 18 ML

The document outlines a machine learning assignment by Saniya Pathan, focusing on a simple linear regression model to predict student marks based on study time. It includes data loading, dataset splitting, model training, predictions, and visualizations of both training and test sets. The results show a perfect prediction accuracy with mean absolute error, mean squared error, and root mean squared error all equal to zero.

Uploaded by

Shadowhere K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

HK 18 ML

The document outlines a machine learning assignment by Saniya Pathan, focusing on a simple linear regression model to predict student marks based on study time. It includes data loading, dataset splitting, model training, predictions, and visualizations of both training and test sets. The results show a perfect prediction accuracy with mean absolute error, mean squared error, and root mean squared error all equal to zero.

Uploaded by

Shadowhere K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

11/21/22, 11:41 PM Untitled0.

ipynb - Colaboratory

MACHINE LEARNING ASSIGNMENT 1

SANIYA PATHAN

ROLL NUMBER 46

import numpy as np import


pandas as pd import
matplotlib.pyplot as plt
import seaborn as sns import
plotly.express as px

from google.colab import files


uploaded =files.upload()

Choose Files Student_Marks.csv


Student_Marks.csv(text/csv) - 1615 bytes, last modified: 11/21/2022 - 100% done
Saving Student_Marks.csv to Student_Marks.csv

SPLITTING THE DATASET


INTO TRAINING AND TEST
SET

data=pd.read_csv("Student_Marks.csv") x=data.iloc[:,-1].values y=data.iloc[:,-


1].values from sklearn.model_selection import train_test_split x_train, x_test,
y_train, y_test = train_test_split(x, y, test_size = 0.2, random_state = 0)

data.head()
number_courses time_study
Marks
0 3 4.508 19.202
1 4 0.096 7.734
2 4 3.133 13.811

3 6 7.909 53.018

4 8 7.811 55.299

https://colab.research.google.com/drive/1HX3Tuk350baJsuMe_JXqvQafOi7Kr45G#scrollTo=WhG8nOadYJGp&printMode=true 1/5
11/21/22, 11:41 PM Untitled0.ipynb - Colaboratory

TRAINING THE SIMPLE


LINEAR REGRESSION MODEL
ON THE TRAINING SET

#x_train= x_train.reshape(-1, 1)
#x_test = x_test.reshape(-1, 1)

from sklearn.linear_model import LinearRegression


regressor=LinearRegression()
regressor.fit(x_train,y_train)

LinearRegression()

PREDICTING THE TEST


RESULTS

y_pred=regressor.predict(x_test)
print(y_pred)

[12.647 23.149 13.811 18.238 6.217 42.426 30.548


7.014 53.158
19.128
36.653 23.916 49.544 17.672 17.264 24.172 12.209 16.517 39.965
20.348]

print(y_test)

[12.647 23.149 13.811 18.238 6.217 42.426 30.548


7.014 53.158
19.128
36.653 23.916 49.544 17.672 17.264 24.172 12.209 16.517 39.965 20.348]

VISUALISING THE TRAINING SET

plt.scatter(x_train,y_train,color='red')
plt.plot(x_train,regressor.predict(x_train),color='
blue') plt.title('time study vs markstraining
set)') plt.xlabel('time') plt.ylabel('marks')
plt.show()

https://colab.research.google.com/drive/1HX3Tuk350baJsuMe_JXqvQafOi7Kr45G#scrollTo=WhG8nOadYJGp&printMode=true 2/5
11/21/22, 11:41 PM Untitled0.ipynb - Colaboratory

VISUALISING THE TEST SET


RESULTS

plt.scatter(x_test,y_test,color='red')
plt.plot(x_train,regressor.predict(x_train),color='
blue') plt.title('time study vs marks(test set)')
plt.xlabel('time') plt.ylabel('marks') plt.show()

print(regressor.intercept_)

0.0

print(regressor.coef_)

[1.]

https://colab.research.google.com/drive/1HX3Tuk350baJsuMe_JXqvQafOi7Kr45G#scrollTo=WhG8nOadYJGp&printMode=true 3/5
11/21/22, 11:41 PM Untitled0.ipynb - Colaboratory

from sklearn import


metrics import math
import numpy as np
print("mean absolute error:", metrics.mean_absolute_error(y_test,y_pred))
print("MSE:",metrics.mean_squared_error(y_test,y_pred))
print("RMSE:",math.sqrt(metrics.mean_squared_error(y_test,y_pred)))

mean absolute error: 0.0


MSE: 0.0
RMSE: 0.0

time_study=data.time_study.to_nump
y() Marks=data.Marks.to_numpy()
plt.scatter(time_study,Marks)
<matplotlib.collections.PathCollec
tion at 0x7f2c135e8110>

https://colab.research.google.com/drive/1HX3Tuk350baJsuMe_JXqvQafOi7Kr45G#scrollTo=WhG8nOadYJGp&printMode=true 4/5
11/21/22, 11:41 PM Untitled0.ipynb - Colaboratory

Double-click (or enter) to edit

Colab paid products - Cancel contracts here


 0s completed at 11:41 PM

https://colab.research.google.com/drive/1HX3Tuk350baJsuMe_JXqvQafOi7Kr45G#scrollTo=WhG8nOadYJGp&printMode=true 5/5

You might also like