emel/ml/naive_bayes
A simple probabilistic classifier based on applying Bayes’ theorem with naive independence assumptions between the features. It makes classifications using the maximum posteriori decision rule in a Bayesian setting.
Functions
pub fn classifier(data: List(Map(String, String)), features: List(
String,
), class: String) -> fn(Map(String, String)) -> String
Returns the function that classifies an item by using the Naive Bayes Algorithm.
Data = [
#{"outlook" => "Sunny", "temperature" => "Hot", "humidity" => "High", "wind" => "Weak", "decision" => "No"},
#{"outlook" => "Sunny", "temperature" => "Hot", "humidity" => "High", "wind" => "Strong", "decision" => "No"},
#{"outlook" => "Overcast", "temperature" => "Hot", "humidity" => "High", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Rain", "temperature" => "Mild", "humidity" => "High", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Rain", "temperature" => "Cool", "humidity" => "Normal", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Rain", "temperature" => "Cool", "humidity" => "Normal", "wind" => "Strong", "decision" => "No"},
#{"outlook" => "Overcast", "temperature" => "Cool", "humidity" => "Normal", "wind" => "Strong", "decision" => "Yes"},
#{"outlook" => "Sunny", "temperature" => "Mild", "humidity" => "High", "wind" => "Weak", "decision" => "No"},
#{"outlook" => "Sunny", "temperature" => "Cool", "humidity" => "Normal", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Rain", "temperature" => "Mild", "humidity" => "Normal", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Sunny", "temperature" => "Mild", "humidity" => "Normal", "wind" => "Strong", "decision" => "Yes"},
#{"outlook" => "Overcast", "temperature" => "Mild", "humidity" => "High", "wind" => "Strong", "decision" => "Yes"},
#{"outlook" => "Overcast", "temperature" => "Hot", "humidity" => "Normal", "wind" => "Weak", "decision" => "Yes"},
#{"outlook" => "Rain", "temperature" => "Mild", "humidity" => "High", "wind" => "Strong", "decision" => "No"}
],
Features = ["outlook", "temperature", "humidity", "wind"],
Class = "decision",
F = emel@ml@naive_bayes:classifier(Data, Features, Class),
F(#{"outlook" => "Sunny", "temperature" => "Mild", "humidity" => "Normal", "wind" => "Strong"}).
% "Yes"