Class PolynomialRegressionSGD

java.lang.Object
com.jml.core.Model<double[],​double[]>
com.jml.linear_models.PolynomialRegression
com.jml.linear_models.PolynomialRegressionSGD

public class PolynomialRegressionSGD extends PolynomialRegression
Model for least squares regression of polynomials using 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 Details

    • PolynomialRegressionSGD

      public PolynomialRegressionSGD()
      Creates a PolynomialRegressionSGD model. This will use a default learning rate of 0.002.
    • PolynomialRegressionSGD

      public PolynomialRegressionSGD(int degree, double learningRate, int maxIterations, double threshold)
      Creates a PolynomialRegressionSGD model. When the fit 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:
      degree - Degree of the polynomial to fit.
      learningRate - Learning rate to use during Stochastic Gradient Descent
      threshold - Threshold for early stopping during Stochastic Gradient Descent. If the loss is less than the specified threshold, gradient descent will stop early.
      maxIterations - Maximum number of iterations to run for during Stochastic Gradient Descent.
    • PolynomialRegressionSGD

      public PolynomialRegressionSGD(int degree, double learningRate, int maxIterations)
      Creates a PolynomialRegressionSGD model. When the fit 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:
      degree - Degree of the polynomial to fit.
      learningRate - Learning rate to use during Stochastic Gradient Descent.
      maxIterations - Maximum number of iterations to run for during Stochastic Gradient Descent.
    • PolynomialRegressionSGD

      public PolynomialRegressionSGD(int degree, double learningRate)
      Creates a PolynomialRegressionSGD model. When the fit 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:
      degree - Degree of the polynomial to fit.
      learningRate - Learning rate to use during Stochastic Gradient Descent.
    • PolynomialRegressionSGD

      public PolynomialRegressionSGD(int degree)
      Creates a PolynomialRegressionSGD model. When the fit method is called, Stochastic Gradient Descent will fit a polynomial of the specified degree using gradient descent.
      Parameters:
      degree - Degree of the polynomial to fit.
  • Method Details

    • fit

      public PolynomialRegressionSGD fit(double[] features, double[] targets)
      Fits or trains the model with the given features and targets.
      Overrides:
      fit in class PolynomialRegression
      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 in args are 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.