Header menu logo FSharp.Stats

KNN.Seq Module

Functions and values

Function or value Description

Seq.predict distance labeledPoints k x

Full Usage: Seq.predict distance labeledPoints k x

Parameters:
    distance : Distance<'a> - the distance function, e.g. `euclidean`
    labeledPoints : ('a * 'l) seq - the array of classified (or labeled) points [in the format (point, label)], used for the classification
    k : int - The _positive_ number of nearest neighbors from x to look for.
    x : 'a - The point to classify

Returns: 'l option The most common label from the k nearest neighbors for x.
Modifiers: inline
Type parameters: 'a, 'l

The [k-nearest neighbors algorithm](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) to classify a new data point into the target class, depending on the features of its neighboring data points.

distance : Distance<'a>

the distance function, e.g. `euclidean`

labeledPoints : ('a * 'l) seq

the array of classified (or labeled) points [in the format (point, label)], used for the classification

k : int

The _positive_ number of nearest neighbors from x to look for.

x : 'a

The point to classify

Returns: 'l option

The most common label from the k nearest neighbors for x.

Example

 let points = seq { [ 2.0; 4.0 ]; [ 1.0; 3.0 ]; [ 2.0; 4.0 ]; [ 3.0; 2.0 ]; [ 2.0; 1.0 ]; [ 5.0; 6.0 ]; [ 4.0; 5.0 ]; [ 4.0; 6.0 ]; [ 6.0; 6.0 ]; [ 5.0; 4.0 ] }
 let labels = seq { "red"; "red"; "red"; "red"; "red"; "blue"; "blue"; "blue"; "blue"; "blue" }
 let labeledPoints = Seq.zip points labels
 let prediction = FSharp.Stats.ML.Unsupervised.KNN.Seq.KNN.Seq.predict FSharp.Stats.DistanceMetrics.euclidean labeledPoints 3

 let color = prediction [3.0; 3.0] // should be: Some "red"
 let color = prediction [6.0; 6.0] // should be: Some "blue"
val points: float list seq
Multiple items
val seq: sequence: 'T seq -> 'T seq

--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
val labels: string seq
val labeledPoints: (float list * string) seq
module Seq from Microsoft.FSharp.Collections
val zip: source1: 'T1 seq -> source2: 'T2 seq -> ('T1 * 'T2) seq
val prediction: (float list -> obj)
namespace Microsoft.FSharp
val color: obj

Type something to start searching.