Crate ndarray_glm[−][src]
A rust library for performing GLM regression with data represented in
ndarray
s.
The ndarray-linalg
crate is used to allow
optimization of linear algebra operations with BLAS.
This crate is early alpha and may change rapidly. No guarantees can be made about the accuracy of the fits.
At the moment the docs and CI are blocked by an upstream issue. For more detail see the README.
Examples:
use ndarray_glm::{array, Linear, ModelBuilder, standardize}; let data_y = array![0.3, 1.3, 0.7]; let data_x = array![[0.1, 0.2], [-0.4, 0.1], [0.2, 0.4]]; // The design matrix can optionally be standardized, where the mean of each independent // variable is subtracted and each is then divided by the standard deviation of that variable. let data_x = standardize(data_x); // The interface takes `ArrayView`s to allow for efficient passing of slices. let model = ModelBuilder::<Linear>::data(data_y.view(), data_x.view()).build().unwrap(); // L2 (ridge) regularization can be applied with l2_reg(). let fit = model.fit_options().l2_reg(1e-5).fit().unwrap(); // The result is a flat array with the first term as the intercept. println!("Fit result: {}", fit.result);
The canonical link function is used by default. An alternative link function can be specified as a type parameter to the response struct.
use ndarray_glm::{array, Logistic, logistic_link::Cloglog, ModelBuilder}; let data_y = array![true, false, false, true, true]; let data_x = array![[0.5, 0.2], [0.1, 0.3], [0.2, 0.6], [0.6, 0.3], [0.4, 0.4]]; let model = ModelBuilder::<Logistic<Cloglog>>::data(data_y.view(), data_x.view()).build().unwrap(); let fit = model.fit_options().l2_reg(1e-5).fit().unwrap(); println!("Fit result: {}", fit.result);
Feature summary:
- Generic over floating-point type
- Linear, logistic, Poisson, and binomial regression
- L2 (ridge) regularization
- Statistical tests of fit result
- Alternative and custom link functions
Requirements: See the README for dependency requirements.
Re-exports
pub use model::ModelBuilder; |
Modules
error | define the error enum for the result of regressions |
link | Defines traits for link functions |
logistic_link | Link functions for logistic regression |
model | Collect data for and configure a model |
num | numerical trait constraints |
Macros
array | Create an |
Structs
Linear | Linear regression with constant variance (Ordinary least squares). |
Logistic | Logistic regression |
Poisson | Poisson regression over an unsigned integer type. |
Functions
standardize | Returns a standardization of a design matrix where rows are seperate observations and columns are different dependent variables. Each quantity has its mean subtracted and is then divided by the standard deviation. |
Type Definitions
Array1 | one-dimensional array |
Array2 | two-dimensional array |
ArrayView1 | one-dimensional array view |
ArrayView2 | two-dimensional array view |