LearnKit v0.1.6 LearnKit.Knn View Source
Module for k-nearest neighbours (knn) algorithm
Link to this section Summary
Functions
Add train data to classifier
Classify label of the new feature
Creates classifier with empty data_set
Creates classifier with data_set
Link to this section Types
Link to this section Functions
Add train data to classifier
Parameters
- classifier: %LearnKit.Knn{}
- train data: tuple with label and feature
Examples
iex> classifier = classifier |> LearnKit.Knn.add_train_data({:a1, [-1, -1]})
%LearnKit.Knn{data_set: [a1: [[-1, -1]]]}
Classify label of the new feature
Parameters
- classifier: %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
- normalization: none/minimax/z_normalization, default is none, optional
Examples
iex> classifier |> LearnKit.Knn.classify([feature: [-1, -2], k: 3, weight: "distance"])
{:ok, :a1}
Creates classifier with empty data_set
Examples
iex> classifier = LearnKit.Knn.new
%LearnKit.Knn{data_set: []}
Creates classifier with data_set
Parameters
- data_set: Keyword list with labels and features in tuples
Examples
iex> classifier = LearnKit.Knn.new([{:a1, [[1, 2], [2, 3]]}, {:b1, [[-1, -2]]}])
%LearnKit.Knn{data_set: [a1: [[1, 2], [2, 3]], b1: [[-1, -2]]]}