public class LinearRegression extends Object
Linear Regression with BGD(batch gradient descent) algorithm is an iterative algorithm and works as follows:
Giving a data set and target set, the BGD try to find out the best parameters for the data set
to fit the target set.
In each iteration, the algorithm computes the gradient of the cost function and use it to
update all the parameters.
The algorithm terminates after a fixed number of iterations (as in this implementation).
With enough iteration, the algorithm can minimize the cost function and find the best parameters
This is the Wikipedia entry for the
Linear regression
and
Gradient descent algorithm
.
This implementation works on one-dimensional data and finds the best two-dimensional theta to fit the target.
Input files are plain text files and must be formatted as follows:
- Data points are represented as two double values separated by a blank character. The first
one represent the X(the training data) and the second represent the Y(target). Data points are
separated by newline characters.
For example "-0.02 -0.04\n5.3 10.6\n"
gives two data points
(x=-0.02, y=-0.04) and (x=5.3, y=10.6).
This example shows how to use:
- Bulk iterations - Broadcast variables in bulk iterations
Modifier and Type | Class and Description |
---|---|
static class |
LinearRegression.Data |
static class |
LinearRegression.Data$ |
static class |
LinearRegression.Params
A set of parameters -- theta0, theta1.
|
static class |
LinearRegression.Params$ |
static class |
LinearRegression.SubUpdate
Compute a single BGD type update for every parameters.
|
Constructor and Description |
---|
LinearRegression() |
public static void main(String[] args)
Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.