Struct linfa_linear::TweedieRegressor
source · pub struct TweedieRegressor<A> {
pub coef: Array1<A>,
pub intercept: A,
/* private fields */
}
Expand description
Generalized Linear Model (GLM) with a Tweedie distribution
The Regressor can be used to model different GLMs depending on
power
,
which determines the underlying distribution.
Power | Distribution |
---|---|
0 | Normal |
1 | Poisson |
(1, 2) | Compound Poisson Gamma |
2 | Gamma |
3 | Inverse Gaussian |
NOTE: No distribution exists between 0 and 1
Learn more from sklearn’s excellent User Guide
Examples
Here’s an example on how to train a GLM on the diabetes
dataset
use linfa::traits::{Fit, Predict};
use linfa_linear::TweedieRegressor;
use linfa::prelude::SingleTargetRegression;
let dataset = linfa_datasets::diabetes();
let model = TweedieRegressor::params().fit(&dataset).unwrap();
let pred = model.predict(&dataset);
let r2 = pred.r2(&dataset).unwrap();
println!("r2 from prediction: {}", r2);
Fields§
§coef: Array1<A>
Estimated coefficients for the linear predictor
intercept: A
Intercept or bias added to the linear model
Implementations§
source§impl<F: Float> TweedieRegressor<F>
impl<F: Float> TweedieRegressor<F>
pub fn params() -> TweedieRegressorParams<F>
Trait Implementations§
source§impl<A: Clone> Clone for TweedieRegressor<A>
impl<A: Clone> Clone for TweedieRegressor<A>
source§fn clone(&self) -> TweedieRegressor<A>
fn clone(&self) -> TweedieRegressor<A>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<A: Debug> Debug for TweedieRegressor<A>
impl<A: Debug> Debug for TweedieRegressor<A>
source§impl<A: PartialEq> PartialEq for TweedieRegressor<A>
impl<A: PartialEq> PartialEq for TweedieRegressor<A>
source§fn eq(&self, other: &TweedieRegressor<A>) -> bool
fn eq(&self, other: &TweedieRegressor<A>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl<A: Float, D: Data<Elem = A>> PredictInplace<ArrayBase<D, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>> for TweedieRegressor<A>
impl<A: Float, D: Data<Elem = A>> PredictInplace<ArrayBase<D, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>> for TweedieRegressor<A>
impl<A> StructuralPartialEq for TweedieRegressor<A>
Auto Trait Implementations§
impl<A> RefUnwindSafe for TweedieRegressor<A>where
A: RefUnwindSafe,
impl<A> Send for TweedieRegressor<A>where
A: Send,
impl<A> Sync for TweedieRegressor<A>where
A: Sync,
impl<A> Unpin for TweedieRegressor<A>where
A: Unpin,
impl<A> UnwindSafe for TweedieRegressor<A>where
A: UnwindSafe + RefUnwindSafe,
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