Table of Contents

Class KNearest

Namespace
Emgu.CV.ML
Assembly
Emgu.CV.dll

The KNearest classifier

public class KNearest : SharedPtrObject, IDisposable, IStatModel, IAlgorithm
Inheritance
KNearest
Implements
Inherited Members
Extension Methods

Constructors

KNearest()

Create a default KNearest classifier

public KNearest()

Properties

AlgorithmType

Algorithm type

public KNearest.Types AlgorithmType { get; set; }

Property Value

KNearest.Types

DefaultK

Default number of neighbors to use in predict method

public int DefaultK { get; set; }

Property Value

int

Emax

Parameter for KDTree implementation

public int Emax { get; set; }

Property Value

int

IsClassifier

Whether classification or regression model should be trained

public bool IsClassifier { get; set; }

Property Value

bool

Methods

DisposeObject()

Release the classifier and all the memory associated with it

protected override void DisposeObject()

FindNearest(IInputArray, int, IOutputArray, IOutputArray, IOutputArray)

Finds the neighbors and predicts responses for input vectors.

public float FindNearest(IInputArray samples, int k, IOutputArray results, IOutputArray neighborResponses = null, IOutputArray dist = null)

Parameters

samples IInputArray

Input samples stored by rows. It is a single-precision floating-point matrix of <number_of_samples> * k size.

k int

Number of used nearest neighbors. Should be greater than 1.

results IOutputArray

Vector with results of prediction (regression or classification) for each input sample. It is a single-precision floating-point vector with <number_of_samples> elements.

neighborResponses IOutputArray

Optional output values for corresponding neighbors. It is a single- precision floating-point matrix of <number_of_samples> * k size.

dist IOutputArray

Optional output distances from the input vectors to the corresponding neighbors. It is a single-precision floating-point matrix of <number_of_samples> * k size.

Returns

float

If only a single input vector is passed, the predicted value is returned by the method.