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

Link to this function add_train_data(knn, arg) View Source
add_train_data(%LearnKit.Knn{data_set: data_set()}, point()) :: %LearnKit.Knn{
  data_set: data_set()
}

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]]]}
Link to this function classify(knn, options \\ []) View Source
classify(%LearnKit.Knn{data_set: data_set()}, [tuple()]) :: {:ok, label()}

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}
Link to this function new() View Source
new() :: %LearnKit.Knn{data_set: []}

Creates classificator with empty data_set

Examples

iex> classificator = LearnKit.Knn.new
%LearnKit.Knn{data_set: []}
Link to this function new(data_set) View Source
new(data_set()) :: %LearnKit.Knn{data_set: 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]]]}