LearnKit v0.1.6 LearnKit.NaiveBayes.Gaussian View Source
Module for Gaussian NB algorithm
Link to this section Summary
Functions
Add train data to classifier
Fit train data
Creates classifier with empty data_set
Creates classifier with data_set
Normalize train data
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 section Functions
Add train data to classifier
Parameters
- classifier: %LearnKit.NaiveBayes.Gaussian{}
- train data: tuple with label and feature
Examples
iex> classifier = classifier |> LearnKit.NaiveBayes.Gaussian.add_train_data({:a1, [-1, -1]})
%LearnKit.NaiveBayes.Gaussian{data_set: [a1: [[-1, -1]]], fit_data: []}
Fit train data
Parameters
- classifier: %LearnKit.NaiveBayes.Gaussian{}
Examples
iex> classifier = classifier |> 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 classifier with empty data_set
Examples
iex> classifier = LearnKit.NaiveBayes.Gaussian.new
%LearnKit.NaiveBayes.Gaussian{data_set: [], fit_data: []}
Creates classifier with data_set
Parameters
- data_set: Keyword list with labels and features in tuples
Examples
iex> classifier = 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: []}
Normalize train data
Parameters
- classifier: %LearnKit.NaiveBayes.Gaussian{}
- type: none/minimax/z_normalization, default is none, optional
Examples
iex> classifier = classifier |> LearnKit.NaiveBayes.Gaussian.normalize_train_data("minimax")
%LearnKit.NaiveBayes.Gaussian{
data_set: [a1: [[0.6666666666666666, 0.8], [1.0, 1.0]], b1: [[0.0, 0.0]]],
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
- classifier: %LearnKit.NaiveBayes.Gaussian{}
Examples
iex> classifier |> 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
- classifier: %LearnKit.NaiveBayes.Gaussian{}
Examples
iex> classifier |> LearnKit.NaiveBayes.Gaussian.predict_proba([1, 2])
{:ok, [a1: 0.0359, a2: 0.0039]}
Returns the mean accuracy on the given test data and labels
Parameters
- classifier: %LearnKit.NaiveBayes.Gaussian{}
Examples
iex> classifier |> LearnKit.NaiveBayes.Gaussian.score
{:ok, 0.857143}