Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

____________________________________________________________________________

Machine Learning

WEEK-6
NAME : G. Sai hari shashank varma DATE : 20-3-2024

HTNO : 22R25A6607 BRANCH : CSM- B

PROBLEM STATEMENT:

1. Build a linear regression model using python for a particular data


set by

a) Splitting Training data and Test data.

b) Evaluate the model (intercept and slope).

c) Visualize the training set and testing set

d) predicting the test set result

e) compare actual output values with predicted values

PYTHON PROGRAM:

import pandas as pd

import numpy as np

import matplotlib.pyplot as plt

data = pd.read_csv("student_scores.csv")

#print(data)

#print(data.head())

#print(data.describe())

x = data.iloc[:, :-1].values
y = data.iloc[:, -1].values

#print(x)

#print(y)

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)

#print(x_train)

#print(x_test)

#print(y_train)

#print(y_testfrom sklearn.linear_model import LinearRegression

regressor = LinearRegression()

regressor.fit(x_train, y_train)

#print(regressor.intercept_)

#print(regressor.coef_)

y_pred = regressor.predict(x_test)

df = pd.DataFrame({'Actual' : y_test, 'Predict' : y_pred})

#print(df)

plt.scatter(x_train, y_train, color = 'red')

plt.plot(x_train, regressor.predict(x_train), color = 'blue')

plt.title("Hours vs Percentage")

plt.xlabel("Hours Studied")

plt.ylabel("Percentage Score")

plt.show()

plt.scatter(x_test, y_test, color = 'red')

plt.plot(x_test, regressor.predict(x_test), color = 'blue')


plt.title("Hours vs Percentage")

plt.xlabel("Hours Studied")

plt.ylabel("Percentage Score")

plt.show()

OUTPUT:

You might also like