LearnKit v0.1.3 LearnKit.Regression.Linear View Source
Module for Linear Regression algorithm
Link to this section Summary
Functions
Fit train data
Creates predictor with empty data_set
Creates predictor with data_set
Predict using the linear model
Returns the coefficient of determination R^2 of the prediction
Link to this section Types
Link to this section Functions
Fit train data
Parameters
- predictor: %LearnKit.Regression.Linear{}
- options: keyword list with options
Options
- method: method for fit, “least squares”/“gradient descent”, default is “least squares”, optional
Examples
iex> predictor = predictor |> LearnKit.Regression.Linear.fit
%LearnKit.Regression.Linear{
coefficients: [-1.5, 4.0],
factors: [1, 2, 3, 4],
results: [3, 6, 10, 15]
}
iex> predictor = predictor |> LearnKit.Regression.Linear.fit([method: "gradient descent"])
%LearnKit.Regression.Linear{
coefficients: [-1.4975720508482548, 3.9992148848913356],
factors: [1, 2, 3, 4],
results: [3, 6, 10, 15]
}
Link to this function
new()
View Source
new() :: %LearnKit.Regression.Linear{coefficients: [], factors: [], results: []}
Creates predictor with empty data_set
Examples
iex> predictor = LearnKit.Regression.Linear.new
%LearnKit.Regression.Linear{factors: [], results: [], coefficients: []}
Creates predictor with data_set
Parameters
- factors: Array of predictor variables
- results: Array of criterion variables
Examples
iex> predictor = LearnKit.Regression.Linear.new([1, 2, 3, 4], [3, 6, 10, 15])
%LearnKit.Regression.Linear{factors: [1, 2, 3, 4], results: [3, 6, 10, 15], coefficients: []}
Link to this function
predict(linear, samples)
View Source
predict( %LearnKit.Regression.Linear{ coefficients: coefficients(), factors: term(), results: term() }, list() ) :: {:ok, list()}
Predict using the linear model
Parameters
- predictor: %LearnKit.Regression.Linear{}
- samples: Array of variables
Examples
iex> predictor |> LearnKit.Regression.Linear.predict([4, 8, 13])
{:ok, [14.5, 30.5, 50.5]}
Link to this function
score(linear)
View Source
score(%LearnKit.Regression.Linear{ coefficients: coefficients(), factors: factors(), results: results() }) :: {:ok, number()}
Returns the coefficient of determination R^2 of the prediction
Parameters
- predictor: %LearnKit.Regression.Linear{}
Examples
iex> predictor |> LearnKit.Regression.Linear.score
{:ok, 0.9876543209876543}