0% found this document useful (0 votes)
12 views

Linear Regression

This Python code performs linear regression on sample dataset data to predict GPA (Y) based on SAT scores (X). It loads and prepares the data, fits a linear regression model to the data, predicts Y values and plots the original and predicted lines on a scatter plot with SAT on the x-axis and GPA on the y-axis.

Uploaded by

anish.t.p
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Linear Regression

This Python code performs linear regression on sample dataset data to predict GPA (Y) based on SAT scores (X). It loads and prepares the data, fits a linear regression model to the data, predicts Y values and plots the original and predicted lines on a scatter plot with SAT on the x-axis and GPA on the y-axis.

Uploaded by

anish.t.p
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Linear regression

Program

import numpy as np
import matplotlib.pyplot as plt 
import pandas as pd  
from sklearn.linear_model import LinearRegression
data = pd.read_csv('sample_dataset.csv')  
X = data.iloc[:, 0].values.reshape(-1, 1) 
Y = data.iloc[:, 1].values.reshape(-1, 1)  
linear_regressor = LinearRegression()  
linear_regressor.fit(X, Y)  
Y_pred = linear_regressor.predict(X)  
plt.scatter(X, Y)
plt.plot(X, Y_pred, color='red')
plt.title('Test Data')
plt.xlabel('SAT')
plt.ylabel('GPA')
plt.show()

Output
Linear regression

Program

import numpy as np
import matplotlib.pyplot as plt 
import pandas as pd  
from sklearn.linear_model import LinearRegression
data = pd.read_csv('sample_dataset.csv')  
X = data.iloc[:, 0].values.reshape(-1, 1) 
Y = data.iloc[:, 1].values.reshape(-1, 1)  
linear_regressor = LinearRegression()  
linear_regressor.fit(X, Y)  
Y_pred = linear_regressor.predict(X)  
plt.plot(X, Y_pred, color='red')
plt.title('Test Data')
plt.xlabel('SAT')
plt.ylabel('GPA')
plt.show()

Output

You might also like