public class LinearRegression extends Object
Linear Regression with BGD(batch gradient descent) algorithm is an iterative clustering 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 find the two-dimensional theta.
It find the best Theta parameter to fit the target.
Input files are plain text files and must be formatted as follows:
"-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:
Modifier and Type | Class and Description |
---|---|
static class |
LinearRegression.Data
A simple data sample, x means the input, and y means the target.
|
static class |
LinearRegression.Params
A set of parameters -- theta0, theta1.
|
static class |
LinearRegression.SubUpdate
Compute a single BGD type update for every parameters.
|
static class |
LinearRegression.Update
Compute the final update by average them.
|
static class |
LinearRegression.UpdateAccumulator
Accumulator all the update.
|
Constructor and Description |
---|
LinearRegression() |
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.