emel/ml/linear_regression

A linear approach to modelling the relationship between a list of independent variables and a dependent variable.

Functions

pub fn predictor(data: List(#(List(Float), Float))) -> fn(
  List(Float),
) -> Float

Returns the linear function that predicts the value of the dependent variable.

Data = [
  {[1.794638, 15.15426], 0.510998918},
  {[3.220726, 229.6516], 105.6583692},
  {[5.780040, 3480.201], 1776.99}
],
F = emel@ml@linear_regression:predictor(Data),
F([3.0, 230.0]).
% 106.74114058686602
pub fn regression_coefficients(points: List(List(Float))) -> Result(
  List(Float),
  String,
)

The list of the predictor function’s coefficients based on observations (points).

Points = [[1.0, 1.0, 1.0], [1.0, 2.0, 3.0], [2.0, 1.0, 0.0]],
emel@ml@linear_regression:regression_coefficients(Points).
% {ok, [0.0, -1.0, 2.0]}