emel v0.3.0 Emel.Ml.KNearestNeighbors View Source
A non-parametric method used for classification and regression. In both cases, the input consists of the k closest training examples in the feature space.
Link to this section Summary
Functions
Returns the function that classifies an item by finding the k
nearest neighbors
It searches through the entire dataset
and returns the k
most similar items to the item
Returns the function that calculates the average value of the dependent_variable
of the k
nearest neighbors
Link to this section Functions
Returns the function that classifies an item by finding the k
nearest neighbors.
Examples
iex> f = Emel.Ml.KNearestNeighbors.classifier([%{x1: 7.0, x2: 7.0, y: "bad"},
...> %{x1: 7.0, x2: 4.0, y: "bad"},
...> %{x1: 3.0, x2: 4.0, y: "good"},
...> %{x1: 1.0, x2: 4.0, y: "good"}],
...> [:x1, :x2], :y, 3)
...> f.(%{x1: 3.0, x2: 7.0})
"good"
It searches through the entire dataset
and returns the k
most similar items to the item
.
Examples
iex> Emel.Ml.KNearestNeighbors.k_nearest_neighbors(%{x1: 3.0, x2: 7.0},
...> [%{x1: 7.0, x2: 7.0, y: "bad"},
...> %{x1: 7.0, x2: 4.0, y: "bad"},
...> %{x1: 3.0, x2: 4.0, y: "good"},
...> %{x1: 1.0, x2: 4.0, y: "good"}],
...> [:x1, :x2],
...> 3)
[%{x1: 3.0, x2: 4.0, y: "good"},
%{x1: 1.0, x2: 4.0, y: "good"},
%{x1: 7.0, x2: 7.0, y: "bad"}]
Returns the function that calculates the average value of the dependent_variable
of the k
nearest neighbors.
Examples
iex> f = Emel.Ml.KNearestNeighbors.predictor([%{x1: 0.0, x2: 0.0, x3: 0.0, y: 0.0},
...> %{x1: 0.5, x2: 0.5, x3: 0.5, y: 1.5},
...> %{x1: 1.0, x2: 1.0, x3: 1.0, y: 3.0},
...> %{x1: 1.5, x2: 1.5, x3: 1.5, y: 4.5},
...> %{x1: 2.0, x2: 2.0, x3: 2.0, y: 6.0},
...> %{x1: 2.5, x2: 2.5, x3: 2.5, y: 7.5},
...> %{x1: 3.0, x2: 3.3, x3: 3.0, y: 9.0}],
...> [:x1, :x2, :x3], :y, 2)
...> f.(%{x1: 1.725, x2: 1.725, x3: 1.725})
5.25