LearnKit v0.1.6 LearnKit.Regression.Polynomial View Source

Module for Polynomial Regression algorithm

Link to this section Summary

Functions

Creates polynomial predictor with data_set

Predict using the polynomial model

Returns the coefficient of determination R^2 of the prediction

Link to this section Types

Link to this type coefficients() View Source
coefficients() :: [number()]
Link to this type factors() View Source
factors() :: [number()]
Link to this type results() View Source
results() :: [number()]

Link to this section Functions

Link to this function fit(polynomial, options \\ []) View Source

Fit train data

Parameters

  • predictor: %LearnKit.Regression.Polynomial{}
  • options: keyword list with options

Options

  • degree: nth degree of polynomial model, default set to 2

Examples

iex> predictor = predictor |> LearnKit.Regression.Polynomial.fit
%LearnKit.Regression.Polynomial{
  coefficients: [0.9999999999998295, 1.5000000000000853, 0.4999999999999787],
  degree: 2,
  factors: [1, 2, 3, 4],
  results: [3, 6, 10, 15]
}

iex> predictor = predictor |> LearnKit.Regression.Polynomial.fit([degree: 3])
%LearnKit.Regression.Polynomial{
  coefficients: [1.0000000000081855, 1.5000000000013642, 0.5,
   8.526512829121202e-14],
  degree: 3,
  factors: [1, 2, 3, 4],
  results: [3, 6, 10, 15]
}
Link to this function new(factors, results) View Source
new(factors(), results()) :: %LearnKit.Regression.Polynomial{
  coefficients: [],
  degree: 2,
  factors: factors(),
  results: results()
}

Creates polynomial predictor with data_set

Parameters

  • factors: Array of predictor variables
  • results: Array of criterion variables

Examples

iex> predictor = LearnKit.Regression.Polynomial.new([1, 2, 3, 4], [3, 6, 10, 15])
%LearnKit.Regression.Polynomial{factors: [1, 2, 3, 4], results: [3, 6, 10, 15], coefficients: [], degree: 2}
Link to this function predict(polynomial, samples) View Source
predict(
  %LearnKit.Regression.Polynomial{
    coefficients: coefficients(),
    degree: degree(),
    factors: term(),
    results: term()
  },
  list()
) :: {:ok, list()}
predict(
  %LearnKit.Regression.Polynomial{
    coefficients: coefficients(),
    degree: degree(),
    factors: term(),
    results: term()
  },
  number()
) :: {:ok, number()}

Predict using the polynomial model

Parameters

  • predictor: %LearnKit.Regression.Polynomial{}
  • sample: Sample variable

Examples

iex> predictor |> LearnKit.Regression.Polynomial.predict(5)
{:ok, 20.999999999999723}
Link to this function score(regression) 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}
Link to this function sum_of_x_i_with_k(ks, factors) View Source
Link to this function x_y_matrix(xs, ys, degree, matrix) View Source