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

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 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]]]}
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

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

Creates classifier with empty data_set

Examples

iex> classifier = 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 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]]]}