Module regression

Source
Available on crate feature regression only.
Expand description

Various regression models to fit the best line to your data. All written to be understandable.

Vocabulary:

  • Predictors - the independent values (usually denoted x) from which we want a equation to get the:
  • outcomes - the dependant variables. Usually y or f(x).
  • model - create an equation which optimally (can optimize for different priorities) fits the data.

The *Coefficients structs implement Predictive which calculates the predicted outcomes using the model and their determination; and Display which can be used to show the equations.

Linear regressions are often used by other regression methods. All linear regressions therefore implement the LinearEstimator trait. You can use the *Linear structs to choose which method to use.

§Info on implementation

Details and comments on implementation can be found as docs under each item.

§Power & exponent

See derived for the implementations.

I reverse the exponentiation to get a linear model. Then, I solve it using the method linked above. Then, I transform the returned variables to fit the target model.

This is not very good, as the errors of large values are reduced compared to small values when taking the logarithm. I have plans to address this bias in the future. The current behaviour is however still probably the desired behaviour, as small values are often relatively important to larger.

Many programs (including LibreOffice Calc) simply discards negative & zero values. I chose to go the explicit route and add additional terms to satisfy requirements. This is naturally a fallback, and should be a warning sign your data is bad.

Under these methods the calculations are inserted, and how to handle the data.

Re-exports§

pub use binary_search::Options as BinarySearchOptions;
pub use derived::exponential_ols;ols
pub use derived::power_ols;ols
pub use gradient_descent::ParallelOptions as GradientDescentParallelOptions;
pub use gradient_descent::SimultaneousOptions as GradientDescentSimultaneousOptions;
pub use ols::OlsEstimator;ols
pub use spiral::SpiralLinear;
pub use spiral::SpiralLogisticWithCeiling;
pub use theil_sen::LinearTheilSen;
pub use theil_sen::PolynomialTheilSen;
pub use trig::*;

Modules§

arbitrary_linear_algebraarbitrary-precision
This module enables the use of rug::Float inside of nalgebra.
binary_search
A random binary searching n-variable optimizer.
derived
Estimators derived from others, usual LinearEstimator.
gradient_descent
Assumes the fitness function has a minimal slope when the value is optimal (i.e. e.g. (x-4.).abs() will not work, since it’s slope is constant and then changes sign)
models
The models (functions) we can use regression to optimize for.
olsols
Ordinary least squares implementation.
random_subset_regressionrandom_subset_regression
Improves speed of regression by only taking a few points into account.
spiral
Spiral estimator, a robust sampling estimator. This should be more robust than theil_sen.
theil_sen
Theil-Sen estimator, a robust linear (also implemented as polynomial) estimator. Up to ~27% of values can be outliers - erroneous data far from the otherwise good data - without large effects on the result.
trig
Traits and coefficients of trigonometric functions.

Structs§

DynModel
Generic model. This enables easily handling results from several models.
ExponentialCoefficients
The coefficients of a exponential function (kb^x).
LinearCoefficients
The coefficients of a line.
LogisticCoefficients
The coefficients of a logistic function.
PolynomialCoefficients
The length of the inner vector is degree + 1.
PowerCoefficients
The coefficients of a power (also called growth) function (kx^e).

Traits§

Determination
Helper trait to make the method take a generic iterator.
ExponentialEstimator
Implemented by all estimators yielding an exponential regression.
LinearEstimator
Implemented by all estimators yielding a linear 2 variable regression (a line).
LogisticEstimator
Implemented by all estimators yielding an logistic regression.
PolynomialEstimator
Implemented by all estimators yielding a polynomial regression.
PowerEstimator
Implemented by all estimators yielding a power regression.
Predictive
Something that can predict the outcome from a predictor.

Functions§

best_fit
Finds the model best fit to the input data. This is done using heuristics and testing of methods.
best_fit_olsols
Convenience function for best_fit using OlsEstimator.