Module rustlearn::linear_models::sgdclassifier
[−]
[src]
A two-class logistic regression classifier implemented using stochastic gradient descent.
This model implements a two-class logistic regression classifier, using stochastic gradient descent with an adaptive per-parameter learning rate (Adagrad). The model can be regularized using L2 and L1 regularization, and supports fitting on both dense and sparse data.
Repeated calls to the fit
function are equivalent to running
multiple epochs of training.
Examples
Fitting the model on the iris dataset is straightforward:
use rustlearn::prelude::*; use rustlearn::linear_models::sgdclassifier::Hyperparameters; use rustlearn::datasets::iris; let (X, y) = iris::load_data(); let mut model = Hyperparameters::new(4) .learning_rate(1.0) .l2_penalty(0.5) .l1_penalty(0.0) .one_vs_rest(); model.fit(&X, &y).unwrap(); let prediction = model.predict(&X).unwrap();
To run multiple epochs of training, use repeated calls to
fit
:
use rustlearn::prelude::*; use rustlearn::linear_models::sgdclassifier::Hyperparameters; use rustlearn::datasets::iris; let (X, y) = iris::load_data(); let mut model = Hyperparameters::new(4) .learning_rate(1.0) .l2_penalty(0.5) .l1_penalty(0.0) .one_vs_rest(); let num_epochs = 20; for _ in 0..num_epochs { model.fit(&X, &y).unwrap(); } let prediction = model.predict(&X).unwrap();
Structs
Hyperparameters |
Hyperparameters for a |
SGDClassifier |
A two-class linear regression classifier implemented using stochastic gradient descent. |