Skip to main content

Linmod

Struct Linmod 

Source
pub struct Linmod { /* private fields */ }
Expand description

Linear-model wrapper covering least-squares (MSE) regression and logistic regression. Use Linmod::fit to fit the model on training data, then Linmod::coefficients to inspect the fitted weights or Linmod::predict / Linmod::evaluate to apply the model.

Data is laid out column-major by default (one column per feature, lda = n_samples). To pass row-major data, call Linmod::handle_mut and set_string_option("storage order", "row-major") before fitting.

Implementations§

Source§

impl Linmod

Source

pub fn new_mse() -> Result<Self>

Build a new MSE (L2) regression model in f64 precision.

Source

pub fn new_logistic() -> Result<Self>

Build a new logistic regression model in f64 precision.

Source

pub fn handle_mut(&mut self) -> &mut Handle

Borrow the underlying handle to set algorithm-specific options (regularisation, solver choice, storage order, …).

Source

pub fn kind(&self) -> LinmodKind

Family of linear model that this handle was constructed for.

Source

pub fn fit( &mut self, n_samples: usize, n_features: usize, x: &[f64], y: &[f64], ) -> Result<()>

Fit the model on n_samples × n_features training data (column-major by default) with a length-n_samples response vector y.

Source

pub fn coefficients(&self) -> Result<Vec<f64>>

Retrieve the fitted model coefficients. For MSE regression with no intercept this is a vector of length n_features; with an intercept or for logistic regression it may be longer (the library decides the layout).

Source

pub fn predict( &mut self, n_samples: usize, n_features: usize, x: &[f64], predictions: &mut [f64], ) -> Result<()>

Apply the model to n_samples × n_features new data, writing n_samples predicted values into predictions. For MSE regression these are continuous responses; for logistic regression they are integer class indices stored as floats.

Source

pub fn evaluate( &mut self, n_samples: usize, n_features: usize, x: &[f64], y: &[f64], predictions: &mut [f64], ) -> Result<f64>

Apply the model and also compute the model loss against the supplied observations y. Returns the scalar loss.

Trait Implementations§

Source§

impl Debug for Linmod

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Linmod

§

impl !RefUnwindSafe for Linmod

§

impl !Sync for Linmod

§

impl Forget for Linmod

§

impl Move for Linmod

§

impl Send for Linmod

§

impl Unpin for Linmod

§

impl UnsafeUnpin for Linmod

§

impl UnwindSafe for Linmod

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.