Class KNearest
- Namespace
- OpenCvSharp.ML
- Assembly
- OpenCvSharp.dll
K nearest neighbors classifier
public class KNearest : StatModel, IDisposable, ICvPtrHolder
- Inheritance
-
KNearest
- Implements
- Inherited Members
Constructors
KNearest(nint)
Creates instance by raw pointer cv::ml::KNearest*
protected KNearest(nint p)
Parameters
pnint
Properties
AlgorithmType
Algorithm type, one of KNearest::Types.
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
Create()
Creates the empty model
public static KNearest Create()
Returns
DisposeManaged()
Releases managed resources
protected override void DisposeManaged()
FindNearest(InputArray, int, OutputArray, OutputArray?, OutputArray?)
Finds the neighbors and predicts responses for input vectors.
public float FindNearest(InputArray samples, int k, OutputArray results, OutputArray? neighborResponses = null, OutputArray? dist = null)
Parameters
samplesInputArrayInput samples stored by rows. It is a single-precision floating-point matrix of
[number_of_samples] * ksize.kintNumber of used nearest neighbors. Should be greater than 1.
resultsOutputArrayVector with results of prediction (regression or classification) for each input sample. It is a single-precision floating-point vector with
[number_of_samples]elements.neighborResponsesOutputArrayneighborResponses Optional output values for corresponding neighbors. It is a single-precision floating-point matrix of
[number_of_samples] * ksize.distOutputArrayOptional output distances from the input vectors to the corresponding neighbors. It is a single-precision floating-point matrix of
[number_of_samples] * ksize.
Returns
Load(string)
Loads and creates a serialized model from a file.
public static KNearest Load(string filePath)
Parameters
filePathstring
Returns
LoadFromString(string)
Loads algorithm from a String.
public static KNearest LoadFromString(string strModel)
Parameters
strModelstringhe string variable containing the model you want to load.