Package com.jml.linear_models
Class Perceptron
java.lang.Object
com.jml.core.Model<double[][],double[][]>
com.jml.linear_models.Perceptron
A perceptron is a linear model that is equivalent to a single layer neural network.
When a perceptron model is saved, it will be saved as a neural network model. When the activation of a perceptron is the sigmoid function, it is a linear classifier that is analogous to logistic regression.
When a perceptron model is saved, it will be saved as a neural network model. When the activation of a perceptron is the sigmoid function, it is a linear classifier that is analogous to logistic regression.
-
Constructor Summary
ConstructorDescriptionCreates a perceptron with default hyper-parameters.Perceptron(double learningRate, int epochs, int batchSize, double threshold)
Creates a perceptron with specified hyper-parameters and the sigmoid activation function.Perceptron(double learningRate, int epochs, int batchSize, double threshold, ActivationFunction activation)
Creates a perceptron with specified hyper-parameters and activation function. -
Method Summary
Modifier and TypeMethodDescriptionfit(double[][] features, double[][] targets)
Fits or trains the model with the given features and targets.linalg.Matrix
Gets the parameters of the trained model.inspect()
Forms a string of the important aspects of the model.
same asModel.toString()
double[][]
predict(double[][] features)
Uses fitted/trained model to make prediction on single feature.linalg.Matrix
predict(linalg.Matrix X, linalg.Matrix w)
Makes a prediction using a model by specifying the parameters of the model.void
Saves a trained model to the specified file path.toString()
Forms a string of the important aspects of the model.
-
Constructor Details
-
Perceptron
public Perceptron()Creates a perceptron with default hyper-parameters. The default parameters are listed below.Learning Rate: 0.01 Epochs: 10 Batch Size: 1 Threshold: 1e-5 Activation: Sigmoid Function
-
Perceptron
public Perceptron(double learningRate, int epochs, int batchSize, double threshold)Creates a perceptron with specified hyper-parameters and the sigmoid activation function.
To specify an activation function, seePerceptron(double, int, int, double, ActivationFunction)
.- Parameters:
learningRate
- Learning rate to use during training.epochs
- Number of epochs to train the perceptron for.batchSize
- Batch size to use during training.threshold
- Threshold for early stopping of training. If the loss of the perceptron model falls below this value during training, training will end before the specified number of epochs.
-
Perceptron
public Perceptron(double learningRate, int epochs, int batchSize, double threshold, ActivationFunction activation)Creates a perceptron with specified hyper-parameters and activation function.- Parameters:
learningRate
- Learning rate to use during training.epochs
- Number of epochs to train the perceptron for.batchSize
- Batch size to use during training.threshold
- Threshold for early stopping of training. If the loss of the perceptron model falls below this value during training, training will end before the specified number of epochs.activation
- Activation function to use in the perceptron.
-
-
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. -
predict
public double[][] predict(double[][] features)Uses fitted/trained model to make prediction on single feature. -
predict
public linalg.Matrix predict(linalg.Matrix X, linalg.Matrix w)Makes a prediction using a model by specifying the parameters of the model. Unlike the other predict method, no model needs to be trained to use this method since the parameters provided define a model. -
getParams
public linalg.Matrix getParams()Gets the parameters of the trained model. -
saveModel
Saves a trained model to the specified file path. -
inspect
Forms a string of the important aspects of the model.
same asModel.toString()
-
toString
Forms a string of the important aspects of the model.
-