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
impl Linmod
Sourcepub fn new_logistic() -> Result<Self>
pub fn new_logistic() -> Result<Self>
Build a new logistic regression model in f64 precision.
Sourcepub fn handle_mut(&mut self) -> &mut Handle
pub fn handle_mut(&mut self) -> &mut Handle
Borrow the underlying handle to set algorithm-specific options (regularisation, solver choice, storage order, …).
Sourcepub fn kind(&self) -> LinmodKind
pub fn kind(&self) -> LinmodKind
Family of linear model that this handle was constructed for.
Sourcepub fn fit(
&mut self,
n_samples: usize,
n_features: usize,
x: &[f64],
y: &[f64],
) -> Result<()>
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.
Sourcepub fn coefficients(&self) -> Result<Vec<f64>>
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).
Sourcepub fn predict(
&mut self,
n_samples: usize,
n_features: usize,
x: &[f64],
predictions: &mut [f64],
) -> Result<()>
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.