Package com.jml.linear_models
Class MultipleLinearRegressionSGD
java.lang.Object
com.jml.core.Model<double[][],double[]>
com.jml.linear_models.MultipleLinearRegression
com.jml.linear_models.MultipleLinearRegressionSGD
Model for least squares linear regression of multiple variables by stochastic gradient descent.
MultipleLinearRegressionSGD fits a model y = b0 + b1x1 + ... + bnxn to the datasets by minimizing the residuals of the sum of squares (i.e. the
MultipleLinearRegressionSGD fits a model y = b0 + b1x1 + ... + bnxn to the datasets by minimizing the residuals of the sum of squares (i.e. the
sum of square errors
) between the values in the
target dataset and the values predicted by the model. This is minimized using stochastic gradient descent.-
Constructor Summary
ConstructorDescriptionCreates aMultipleLinearRegressionSGD
model.MultipleLinearRegressionSGD(double learningRate)
Creates aMultipleLinearRegressionSGD
model.MultipleLinearRegressionSGD(double learningRate, int maxIterations)
Creates aMultipleLinearRegressionSGD
model.MultipleLinearRegressionSGD(double learningRate, int maxIterations, double threshold)
Creates aMultipleLinearRegressionSGD
model.MultipleLinearRegressionSGD(int maxIterations)
Creates aMultipleLinearRegressionSGD
model. -
Method Summary
Modifier and TypeMethodDescriptionfit(double[][] features, double[] targets)
Fits or trains the model with the given features and targets.double[]
Gets the loss history from the optimizer.
-
Constructor Details
-
MultipleLinearRegressionSGD
public MultipleLinearRegressionSGD()Creates aMultipleLinearRegressionSGD
model. This will use a default learning rate of 0.002. -
MultipleLinearRegressionSGD
public MultipleLinearRegressionSGD(double learningRate, int maxIterations, double threshold)Creates aMultipleLinearRegressionSGD
model. When thefit
method is called,Stochastic Gradient Descent
will use the provided learning rate and will stop if it does not converge within the threshold by the specified number of max iterations.- Parameters:
learningRate
- Learning rate to use duringStochastic Gradient Descent
threshold
- Threshold for early stopping duringStochastic Gradient Descent
. If the loss is less than the specified threshold, gradient descent will stop early.maxIterations
- Maximum number of iterations to run for duringStochastic Gradient Descent
.
-
MultipleLinearRegressionSGD
public MultipleLinearRegressionSGD(double learningRate, int maxIterations)Creates aMultipleLinearRegressionSGD
model. When thefit
method is called,Stochastic Gradient Descent
will use the provided learning rate and will stop if it does not converge by the specified number of max iterations.- Parameters:
learningRate
- Learning rate to use duringStochastic Gradient Descent
.maxIterations
- Maximum number of iterations to run for duringStochastic Gradient Descent
.
-
MultipleLinearRegressionSGD
public MultipleLinearRegressionSGD(double learningRate)Creates aMultipleLinearRegressionSGD
model. When thefit
method is called,Stochastic Gradient Descent
will use the provided learning rate and will stop if it does not converge by the specified number of max iterations.- Parameters:
learningRate
- Learning rate to use duringStochastic Gradient Descent
.
-
MultipleLinearRegressionSGD
public MultipleLinearRegressionSGD(int maxIterations)Creates aMultipleLinearRegressionSGD
model. When thefit
method is called,Stochastic Gradient Descent
will use the provided learning rate and will stop if it does not converge by the specified number of max iterations.- Parameters:
maxIterations
- Maximum number of iterations to run for duringStochastic Gradient Descent
.
-
-
Method Details
-
fit
Fits or trains the model with the given features and targets. For both the features and targets parameters, if they are 2D arrays, then the number of rows in each must match and will be the number of samples in the data. The number of columns in each will be the number of features and targets in a single sample.
For instance, if the features array has shape n-by-m and the targets array has shape n-by-k. Then there are n samples in the dataset, each individual sample has m features, and each individual sample has k targets.- Overrides:
fit
in classMultipleLinearRegression
- Parameters:
features
- The features of the training set.targets
- The targets of the training set.- Returns:
- This. i.e. the trained model.
-
getLossHist
public double[] getLossHist()Gets the loss history from the optimizer.- Returns:
- Returns the loss for each iteration of the optimization algorithm in an array. The index of the array corresponds to the iteration the loss was computed for.
-