Coder Social home page Coder Social logo

tkonduri / multiple-linear-regression-model Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shashankg5/multiple-linear-regression-model

0.0 0.0 0.0 13 KB

Implementing Multiple Linear Regression model using ordinary least squares (OLS) and gradient descent approach.

Python 100.00%

multiple-linear-regression-model's Introduction

LinearRegressionModel

Implementing Linear Regression model using Spark

src : Consists of python source code linreg.py linreg-gd.py

out : Consists of the two output files yxlin.out yxlin2.out using ordinary least squares estimate

gd-out : Consists of the two output files yxlin.out yxlin2.out using gradient descent

#########################################################################################

Used the closed form expression for the ordinary least squares estimate of the linear regression coefficients

Steps for running the code:

-> Putting the input files in the hdfs
hdfs dfs -put yxlin.csv
hdfs dfs -put yxlin2.csv

-> Going to the root directory and then going to the bin directory
cd /usr/lib/spark/bin

-> Running the spark program for the two input files
spark-submit /users/shashank/linreg.py yxlin.csv
spark-submit /users/shashank/linreg.py yxlin2.csv

########################################################################################

Gradient Descent approach to calculate regression coefficients : alpha= 0.001 and iterations = 500

The following formula is used for gradient descent: beta = beta+alphasummation(Xtrans (Y - Xbeta))

First, the summation term is calculated by mapper and emitted as "keyA". The reducer adds up all the terms which has "keyA". The above term is multiplied by alpha and added to previous beta value to get the new beta value.

I have assumed the initial Beta value to be a matrix of all 0's.

Steps for running the code:

-> Putting the input files in the hdfs
hdfs dfs -put yxlin.csv
hdfs dfs -put yxlin2.csv

-> Going to the root directory and then going to the bin directory
cd /usr/lib/spark/bin

-> Running the spark program for the two input files
spark-submit /users/shashank/linreg-gd.py yxlin.csv 0.001 500
spark-submit /users/shashank/linreg-gd.py yxlin2.csv 0.001 500

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.