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.
§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.
Trait Implementations§
Source§impl Clone for FtrlClassifier
impl Clone for FtrlClassifier
Source§fn clone(&self) -> FtrlClassifier
fn clone(&self) -> FtrlClassifier
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FtrlClassifier
impl Debug for FtrlClassifier
Source§impl SparseClassifier for FtrlClassifier
impl SparseClassifier for FtrlClassifier
Source§fn samples_seen(&self) -> u64
fn samples_seen(&self) -> u64
How many training samples the model has seen so far.
Source§fn predict_proba(&self, features: &SparseFeatures) -> Result<f64, RillError>
fn predict_proba(&self, features: &SparseFeatures) -> Result<f64, RillError>
Predict the probability of the positive class.
Auto Trait Implementations§
impl Freeze for FtrlClassifier
impl RefUnwindSafe for FtrlClassifier
impl Send for FtrlClassifier
impl Sync for FtrlClassifier
impl Unpin for FtrlClassifier
impl UnsafeUnpin for FtrlClassifier
impl UnwindSafe for FtrlClassifier
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more