LearnKit v0.1.3 LearnKit.NaiveBayes.Gaussian View Source

Module for Gaussian NB algorithm

Link to this section Summary

Functions

Add train data to classificator

Fit train data

Creates classificator with empty data_set

Creates classificator with data_set

Return exact prediction for the feature

Return probability estimates for the feature

Returns the mean accuracy on the given test data and labels

Link to this section Types

Link to this type data_set() View Source
data_set() :: [{label(), features()}]
Link to this type feature() View Source
feature() :: [integer()]
Link to this type features() View Source
features() :: [feature()]
Link to this type fit_data() View Source
fit_data() :: [{label(), fit_features()}]
Link to this type fit_feature() View Source
fit_feature() :: %{
  mean: float(),
  standard_deviation: float(),
  variance: float()
}
Link to this type fit_features() View Source
fit_features() :: [fit_feature()]
Link to this type prediction() View Source
prediction() :: {label(), number()}
Link to this type predictions() View Source
predictions() :: [prediction()]

Link to this section Functions

Link to this function add_train_data(gaussian, arg) View Source
add_train_data(
  %LearnKit.NaiveBayes.Gaussian{data_set: data_set(), fit_data: term()},
  point()
) :: %LearnKit.NaiveBayes.Gaussian{data_set: data_set(), fit_data: term()}

Add train data to classificator

Parameters

  • classificator: %LearnKit.NaiveBayes.Gaussian{}
  • train data: tuple with label and feature

Examples

iex> classificator = classificator |> LearnKit.NaiveBayes.Gaussian.add_train_data({:a1, [-1, -1]})
%LearnKit.NaiveBayes.Gaussian{data_set: [a1: [[-1, -1]]], fit_data: []}
Link to this function fit(gaussian) View Source
fit(%LearnKit.NaiveBayes.Gaussian{data_set: data_set(), fit_data: term()}) ::
  %LearnKit.NaiveBayes.Gaussian{data_set: data_set(), fit_data: fit_data()}

Fit train data

Parameters

  • classificator: %LearnKit.NaiveBayes.Gaussian{}

Examples

iex> classificator = classificator |> LearnKit.NaiveBayes.Gaussian.fit
%LearnKit.NaiveBayes.Gaussian{
  data_set: [a1: [[-1, -1]]],
  fit_data: [
    a1: [
      %{mean: -1.0, standard_deviation: 0.0, variance: 0.0},
      %{mean: -1.0, standard_deviation: 0.0, variance: 0.0}
    ]
  ]
}
Link to this function new() View Source
new() :: %LearnKit.NaiveBayes.Gaussian{data_set: [], fit_data: term()}

Creates classificator with empty data_set

Examples

iex> classificator = LearnKit.NaiveBayes.Gaussian.new
%LearnKit.NaiveBayes.Gaussian{data_set: [], fit_data: []}
Link to this function new(data_set) View Source
new(data_set()) :: %LearnKit.NaiveBayes.Gaussian{
  data_set: data_set(),
  fit_data: term()
}

Creates classificator with data_set

Parameters

  • data_set: Keyword list with labels and features in tuples

Examples

iex> classificator = LearnKit.NaiveBayes.Gaussian.new([{:a1, [[1, 2], [2, 3]]}, {:b1, [[-1, -2]]}])
%LearnKit.NaiveBayes.Gaussian{data_set: [a1: [[1, 2], [2, 3]], b1: [[-1, -2]]], fit_data: []}
Link to this function predict(gaussian, feature) View Source
predict(
  %LearnKit.NaiveBayes.Gaussian{data_set: term(), fit_data: fit_data()},
  feature()
) :: {:ok, prediction()}

Return exact prediction for the feature

Parameters

  • classificator: %LearnKit.NaiveBayes.Gaussian{}

Examples

iex> classificator |> LearnKit.NaiveBayes.Gaussian.predict([1, 2])
{:ok, {:a1, 0.334545454}}
Link to this function predict_proba(gaussian, feature) View Source
predict_proba(
  %LearnKit.NaiveBayes.Gaussian{data_set: term(), fit_data: fit_data()},
  feature()
) :: {:ok, predictions()}

Return probability estimates for the feature

Parameters

  • classificator: %LearnKit.NaiveBayes.Gaussian{}

Examples

iex> classificator |> LearnKit.NaiveBayes.Gaussian.predict_proba([1, 2])
{:ok, [a1: 0.0359, a2: 0.0039]}
Link to this function score(gaussian) View Source
score(%LearnKit.NaiveBayes.Gaussian{data_set: data_set(), fit_data: fit_data()}) ::
  {:ok, number()}

Returns the mean accuracy on the given test data and labels

Parameters

  • classificator: %LearnKit.NaiveBayes.Gaussian{}

Examples

iex> classificator |> LearnKit.NaiveBayes.Gaussian.score
{:ok, 0.857143}