Function std_dev::regression::best_fit

source ·
pub fn best_fit(
    predictors: &[f64],
    outcomes: &[f64],
    linear_estimator: &impl LinearEstimator
) -> DynModel
Available on crate feature regression only.
Expand description

Finds the model best fit to the input data. This is done using heuristics and testing of methods.


Panics if the model has less than two parameters or if the two slices have different lengths.


These seemed good to me. Any ideas on improving them are welcome.

  • Power and exponentials only if no data is < 1. This is due to the sub-optimal behaviour of logarithm with values close to and under 0. This restriction might be lifted to just < 1e-9 in the future.
  • Power is heavily favoured if let distance_from_integer = -(0.5 - exponent % 1).abs() + 0.5; distance_from_integer < 0.15 && -2.5 <= exponent <= 3.5
  • Power is also heavily favoured if the same as above occurs but with the reciprocal of the exponent. Then, the range 0.5 < exponent.recip() <= 3.5 is considered.
  • Exponential favoured if R² > 0.8, which seldom happens with exponential regression.
  • Bump the rating of linear, as that’s probably what you want.
  • 2’nd degree polynomial is only considered if n > 15, where n is predictors.len().
  • 3’nd degree polynomial is only considered if n > 50