Package com.jml.linear_models
Class PolynomialRegressionSGD
java.lang.Object
com.jml.core.Model<double[],double[]>
com.jml.linear_models.PolynomialRegression
com.jml.linear_models.PolynomialRegressionSGD
Model for least squares regression of polynomials using
PolynomialRegression fits a model y = b0 + b1x + b2x2 + ... + bnxn to the datasets by minimizing the residuals of the sum of squares between the values in the target dataset and the values predicted by the model. This is solved using Stochastic Gradient Descent.
Stochastic Gradient Descent.PolynomialRegression fits a model y = b0 + b1x + b2x2 + ... + bnxn to the datasets by minimizing the residuals of the sum of squares between the values in the target dataset and the values predicted by the model. This is solved using Stochastic Gradient Descent.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aPolynomialRegressionSGDmodel.PolynomialRegressionSGD(int degree)Creates aPolynomialRegressionSGDmodel.PolynomialRegressionSGD(int degree, double learningRate)Creates aPolynomialRegressionSGDmodel.PolynomialRegressionSGD(int degree, double learningRate, int maxIterations)Creates aPolynomialRegressionSGDmodel.PolynomialRegressionSGD(int degree, double learningRate, int maxIterations, double threshold)Creates aPolynomialRegressionSGDmodel. -
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 training.
-
Constructor Details
-
PolynomialRegressionSGD
public PolynomialRegressionSGD()Creates aPolynomialRegressionSGDmodel. This will use a default learning rate of 0.002. -
PolynomialRegressionSGD
public PolynomialRegressionSGD(int degree, double learningRate, int maxIterations, double threshold)Creates aPolynomialRegressionSGDmodel. When thefitmethod is called,Stochastic Gradient Descentwill use the provided learning rate and will stop if it does not converge within the threshold by the specified number of max iterations.- Parameters:
degree- Degree of the polynomial to fit.learningRate- Learning rate to use duringStochastic Gradient Descentthreshold- 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.
-
PolynomialRegressionSGD
public PolynomialRegressionSGD(int degree, double learningRate, int maxIterations)Creates aPolynomialRegressionSGDmodel. When thefitmethod is called,Stochastic Gradient Descentwill use the provided learning rate and will stop if it does not converge by the specified number of max iterations.- Parameters:
degree- Degree of the polynomial to fit.learningRate- Learning rate to use duringStochastic Gradient Descent.maxIterations- Maximum number of iterations to run for duringStochastic Gradient Descent.
-
PolynomialRegressionSGD
public PolynomialRegressionSGD(int degree, double learningRate)Creates aPolynomialRegressionSGDmodel. When thefitmethod is called,Stochastic Gradient Descentwill use the provided learning rate and will stop if it does not converge by the specified number of max iterations.- Parameters:
degree- Degree of the polynomial to fit.learningRate- Learning rate to use duringStochastic Gradient Descent.
-
PolynomialRegressionSGD
public PolynomialRegressionSGD(int degree)Creates aPolynomialRegressionSGDmodel. When thefitmethod is called,Stochastic Gradient Descentwill fit a polynomial of the specified degree using gradient descent.- Parameters:
degree- Degree of the polynomial to fit.
-
-
Method Details
-
fit
Fits or trains the model with the given features and targets.- Overrides:
fitin classPolynomialRegression- Parameters:
features- The features of the training set.targets- The targets of the training set.- Returns:
- Returns details of the fitting / training process.
- Throws:
IllegalArgumentException- Can be thrown for the following reasons
- If key, value pairs inargsare unspecified or invalid arguments.
- If the features and targets are not correctly sized per the specification when the model was compiled.
-
getLossHist
public double[] getLossHist()Gets the loss history from training.- Returns:
- The loss of every iteration stored in a List.
-