4 releases
0.2.0 | Dec 8, 2019 |
---|---|
0.1.3 | Jun 9, 2018 |
0.1.2 | Jun 9, 2018 |
0.1.1 | Jun 9, 2018 |
#1345 in Algorithms
6,183 downloads per month
Used in 12 crates
(9 directly)
13KB
209 lines
linreg-rs
linreg
is a small crate that calculates linear regressions. It works without
stdlib or memory allocation and has few dependencies. Example:
let xs: Vec<f64> = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let ys: Vec<f64> = vec![2.0, 4.0, 5.0, 4.0, 5.0];
assert_eq!(Some((0.6, 2.2)), linear_regression(&xs, &ys));
It supports tuples, separate vectors for x and y values and template floating point types.
lib.rs
:
Linear regression
linreg
calculates linear regressions for two dimensional measurements, also known as
simple linear regression.
Base for all calculations of linear regression is the simple model found in https://en.wikipedia.org/wiki/Ordinary_least_squares#Simple_linear_regression_model.
Example use
use linreg::{linear_regression, linear_regression_of};
// Example 1: x and y values stored in two different vectors
let xs: Vec<f64> = vec![1.0, 2.0, 3.0, 4.0, 5.0];
let ys: Vec<f64> = vec![2.0, 4.0, 5.0, 4.0, 5.0];
assert_eq!(Ok((0.6, 2.2)), linear_regression(&xs, &ys));
// Example 2: x and y values stored as tuples
let tuples: Vec<(f32, f32)> = vec![(1.0, 2.0),
(2.0, 4.0),
(3.0, 5.0),
(4.0, 4.0),
(5.0, 5.0)];
assert_eq!(Ok((0.6, 2.2)), linear_regression_of(&tuples));
// Example 3: directly operating on integer (converted to float as required)
let xs: Vec<u8> = vec![1, 2, 3, 4, 5];
let ys: Vec<u8> = vec![2, 4, 5, 4, 5];
assert_eq!(Ok((0.6, 2.2)), linear_regression(&xs, &ys));
Dependencies
~1.5MB
~38K SLoC