pub struct FtrlRegressor { /* private fields */ }Expand description
FTRL regressor with squared loss.
Learns y ≈ w · x + b incrementally. The gradient of the squared loss
w.r.t. the prediction is prediction - target, so each feature’s
gradient is (prediction - target) * x_i.
§Examples
use rill_ml::models::{FtrlConfig, FtrlRegressor};
use rill_ml::sparse::SparseFeatures;
use rill_ml::SparseRegressor;
let mut model = FtrlRegressor::new(FtrlConfig::default()).unwrap();
let sf = SparseFeatures::from_sorted(vec![(0, 1.0), (1, 2.0)]).unwrap();
let _pred = model.predict(&sf).unwrap();
model.learn(&sf, 3.0).unwrap();Implementations§
Source§impl FtrlRegressor
impl FtrlRegressor
Sourcepub fn new(config: FtrlConfig) -> Result<Self, RillError>
pub fn new(config: FtrlConfig) -> Result<Self, RillError>
Create a new FTRL regressor.
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 FtrlRegressor
impl Clone for FtrlRegressor
Source§fn clone(&self) -> FtrlRegressor
fn clone(&self) -> FtrlRegressor
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 FtrlRegressor
impl Debug for FtrlRegressor
Source§impl SparseRegressor for FtrlRegressor
impl SparseRegressor for FtrlRegressor
Source§fn samples_seen(&self) -> u64
fn samples_seen(&self) -> u64
How many training samples the model has seen so far.
Source§fn predict(&self, features: &SparseFeatures) -> Result<f64, RillError>
fn predict(&self, features: &SparseFeatures) -> Result<f64, RillError>
Predict the target for the given sparse features. Read more
Auto Trait Implementations§
impl Freeze for FtrlRegressor
impl RefUnwindSafe for FtrlRegressor
impl Send for FtrlRegressor
impl Sync for FtrlRegressor
impl Unpin for FtrlRegressor
impl UnsafeUnpin for FtrlRegressor
impl UnwindSafe for FtrlRegressor
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