pub type LogisticRegression<F> = LogisticRegressionParams<F, Ix1>;
Expand description
A two-class logistic regression model.
Logistic regression combines linear models with
the sigmoid function sigm(x) = 1/(1+exp(-x))
to learn a family of functions that map the feature space to [0,1]
.
Logistic regression is used in binary classification
by interpreting the predicted value as the probability that the sample
has label 1
. A threshold can be set in the fitted model to decide the minimum
probability needed to classify a sample as 1
, which defaults to 0.5
.
In this implementation any binary set of labels can be used, not necessarily 0
and 1
.
l2 regularization is used by this algorithm and is weighted by parameter alpha
. Setting alpha
close to zero removes regularization and the problem solved minimizes only the
empirical risk. On the other hand, setting alpha
to a high value increases
the weight of the l2 norm of the linear model coefficients in the cost function.
§Examples
Here’s an example on how to train a logistic regression model on the winequality
dataset
use linfa::traits::{Fit, Predict};
use linfa_logistic::LogisticRegression;
// Example on using binary labels different from 0 and 1
let dataset = linfa_datasets::winequality().map_targets(|x| if *x > 6 { "good" } else { "bad" });
let model = LogisticRegression::default().fit(&dataset).unwrap();
let prediction = model.predict(&dataset);
Aliased Type§
struct LogisticRegression<F>(/* private fields */);