Giter Club home page Giter Club logo

implementation-of-linear-regression-using-gradient-descent's Introduction

Implementation-of-Linear-Regression-Using-Gradient-Descent

AIM:

To write a program to implement the linear regression using gradient descent.

Equipments Required:

  1. Hardware โ€“ PCs
  2. Anaconda โ€“ Python 3.7 Installation / Moodle-Code Runner

Algorithm

  1. Use the standard libraries in python for finding linear regression.
  2. Set variables for assigning dataset values.
  3. Import linear regression from sklearn.
  4. Assign the points for representing in the graph.
  5. Predict the regression for marks by using the representation of the graph.
  6. Compare the graphs and hence we obtained the linear regression for the given datas.

Program:

/*
Program to implement the linear regression using gradient descent.
Developed by: 212221230071
RegisterNumber:  NITHISHWAR S
*/


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
dataset = pd.read_csv('/content/student_scores - student_scores.csv')
dataset.head()
dataset.tail()
x  = dataset.iloc[:,:-1].values 
y  = dataset.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 = 1/3,random_state=0)
regressor = LinearRegression()
regressor.fit(x_train,y_train)
y_pred=regressor.predict(x_test)
plt.scatter(x_train,y_train,color = "green")
plt.plot(x_train,regressor.predict(x_train),color= "purple")
plt.title("hours Vs scores(train)")
plt.xlabel("hours")
plt.ylabel("scores")
plt.show()
plt.scatter(x_test,y_test,color = "blue")
plt.plot(x_test,regressor.predict(x_test),color= "black")
plt.title("hours Vs scores(train)")
plt.xlabel("hours")
plt.ylabel("scores")
plt.show()

Output:

image

Result:

Thus the program to implement the linear regression using gradient descent is written and verified using python programming.

implementation-of-linear-regression-using-gradient-descent's People

Contributors

akilamohan avatar nithish74 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.