Class KNearest
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
DefaultK
Default number of neighbors to use in predict method
public int DefaultK { get; set; }
Property Value
Emax
Parameter for KDTree implementation
public int Emax { get; set; }
Property Value
IsClassifier
Whether classification or regression model should be trained
public bool IsClassifier { get; set; }
Property Value
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
IInputArrayInput samples stored by rows. It is a single-precision floating-point matrix of <number_of_samples> * k size.
k
intNumber of used nearest neighbors. Should be greater than 1.
results
IOutputArrayVector 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
IOutputArrayOptional output values for corresponding neighbors. It is a single- precision floating-point matrix of <number_of_samples> * k size.
dist
IOutputArrayOptional 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.