pub struct FtrlClassifier { /* private fields */ }Expand description
FTRL binary classifier with log loss.
Predicts P(y=1 | x) = sigmoid(w · x + b). The gradient of the log loss
w.r.t. the logit simplifies to probability - target, so each feature’s
gradient is (probability - target) * x_i.
The returned probability lies in [0, 1]. Extreme logits can produce
exactly 0.0 or 1.0 after sigmoid; downstream consumers such as
crate::loss::log_loss::BinaryLogLoss clip internally.
§Examples
use rill_ml::models::{FtrlClassifier, FtrlConfig};
use rill_ml::sparse::SparseFeatures;
use rill_ml::SparseClassifier;
let mut model = FtrlClassifier::new(FtrlConfig::default()).unwrap();
let sf = SparseFeatures::from_sorted(vec![(0, 1.0)]).unwrap();
let _proba = model.predict_proba(&sf).unwrap();
model.learn(&sf, true).unwrap();Implementations§
Source§impl FtrlClassifier
impl FtrlClassifier
Sourcepub fn new(config: FtrlConfig) -> Result<Self, RillError>
pub fn new(config: FtrlConfig) -> Result<Self, RillError>
Create a new FTRL classifier.
Returns an error if the configuration is invalid.
Sourcepub const fn config(&self) -> &FtrlConfig
pub const fn config(&self) -> &FtrlConfig
The model configuration.
Sourcepub fn weights(&self) -> Vec<(FeatureId, f64)>
pub fn weights(&self) -> Vec<(FeatureId, f64)>
Return the current non-zero feature weights, sorted by FeatureId.
Features whose FTRL weight is exactly zero (due to L1 soft-thresholding or never having been updated) are excluded.
Sourcepub fn feature_count(&self) -> usize
pub fn feature_count(&self) -> usize
Number of distinct features the model has seen.
Sourcepub fn resource_diagnostics(&self) -> FtrlResourceDiagnostics
pub fn resource_diagnostics(&self) -> FtrlResourceDiagnostics
Report feature-capacity and new-feature admission diagnostics.
Trait Implementations§
Source§impl Clone for FtrlClassifier
impl Clone for FtrlClassifier
Source§fn clone(&self) -> FtrlClassifier
fn clone(&self) -> FtrlClassifier
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more