LearnKit v0.1.3 LearnKit.Knn View Source
Module for k-nearest neighbours (knn) algorithm
Link to this section Summary
Functions
Add train data to classificator
Classify label of the new feature
Creates classificator with empty data_set
Creates classificator with data_set
Link to this section Types
Link to this section Functions
Add train data to classificator
Parameters
- classificator: %LearnKit.Knn{}
- train data: tuple with label and feature
Examples
iex> classificator = classificator |> LearnKit.Knn.add_train_data({:a1, [-1, -1]})
%LearnKit.Knn{data_set: [a1: [[-1, -1]]]}
Classify label of the new feature
Parameters
- classificator: %LearnKit.Knn{}
- options: keyword list with options
Options
- feature: feature for classification, required, example: [1, 2, 3]
- k: number of nearest neighbours, default is 3, optional
- algorithm: brute, optional
- weight: uniform/distance, default is uniform, optional
Examples
iex> classificator |> LearnKit.Knn.classify([feature: [-1, -2], k: 3, weight: "distance"])
{:ok, :a1}
Creates classificator with empty data_set
Examples
iex> classificator = LearnKit.Knn.new
%LearnKit.Knn{data_set: []}
Creates classificator with data_set
Parameters
- data_set: Keyword list with labels and features in tuples
Examples
iex> classificator = LearnKit.Knn.new([{:a1, [[1, 2], [2, 3]]}, {:b1, [[-1, -2]]}])
%LearnKit.Knn{data_set: [a1: [[1, 2], [2, 3]], b1: [[-1, -2]]]}