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
- Import the standard Libraries.
- Set variables for assigning dataset values.
- Import linear regression from sklearn.
- Assign the points for representing in the graph.
- Predict the regression for the marks by using the representation of the graph.
- Hence we obtained the linear regression for the given dataset.
/*
Program to implement the simple linear regression model for predicting the marks scored.
Developed by: Lokesh N
RegisterNumber:212222100023
*/
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df=pd.read_csv('/content/ml CSV.csv')
df.head(10)
plt.scatter(df['x'],df['y'])
plt.xlabel('x')
plt.ylabel('y')
x=df.iloc[:,0:-1]
y=df.iloc[:,-1]
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)
from sklearn.linear_model import LinearRegression
lr=LinearRegression()
lr.fit(x_train,y_train)
x_train
y_train
lr.predict(x_test.iloc[0].values.reshape(1,1))
plt.scatter(df['x'],df['y'])
plt.xlabel('x')
plt.ylabel('y')
plt.plot(x_train,lr.predict(x_train),color='orange')
lr.coef_
lr.intercept_
Thus the program to implement the simple linear regression model for predicting the marks scored is written and verified using python programming.