Class KNearest
K nearest neighbors classifier
Implements
Inherited Members
Namespace: OpenCvSharp.ML
Assembly: OpenCvSharp.dll
Syntax
public class KNearest : StatModel, ICvPtrHolder
Constructors
| Improve this Doc View SourceKNearest(IntPtr)
Creates instance by raw pointer cv::ml::KNearest*
Declaration
protected KNearest(IntPtr p)
Parameters
Type | Name | Description |
---|---|---|
IntPtr | p |
Properties
| Improve this Doc View SourceAlgorithmType
Algorithm type, one of KNearest::Types.
Declaration
public KNearest.Types AlgorithmType { get; set; }
Property Value
Type | Description |
---|---|
KNearest.Types |
DefaultK
Default number of neighbors to use in predict method.
Declaration
public int DefaultK { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Emax
Parameter for KDTree implementation
Declaration
public int Emax { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsClassifier
Whether classification or regression model should be trained.
Declaration
public bool IsClassifier { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
Methods
| Improve this Doc View SourceCreate()
Creates the empty model
Declaration
public static KNearest Create()
Returns
Type | Description |
---|---|
KNearest |
DisposeManaged()
Releases managed resources
Declaration
protected override void DisposeManaged()
Overrides
| Improve this Doc View SourceFindNearest(InputArray, Int32, OutputArray, OutputArray, OutputArray)
Finds the neighbors and predicts responses for input vectors.
Declaration
public float FindNearest(InputArray samples, int k, OutputArray results, OutputArray neighborResponses = null, OutputArray dist = null)
Parameters
Type | Name | Description |
---|---|---|
InputArray | samples | Input samples stored by rows.
It is a single-precision floating-point matrix of |
System.Int32 | k | Number of used nearest neighbors. Should be greater than 1. |
OutputArray | results | Vector with results of prediction (regression or classification) for each
input sample. It is a single-precision floating-point vector with |
OutputArray | neighborResponses | neighborResponses Optional output values for corresponding neighbors.
It is a single-precision floating-point matrix of |
OutputArray | dist | Optional output distances from the input vectors to the corresponding neighbors.
It is a single-precision floating-point matrix of |
Returns
Type | Description |
---|---|
System.Single |
Load(String)
Loads and creates a serialized model from a file.
Declaration
public static KNearest Load(string filePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath |
Returns
Type | Description |
---|---|
KNearest |
LoadFromString(String)
Loads algorithm from a String.
Declaration
public static KNearest LoadFromString(string strModel)
Parameters
Type | Name | Description |
---|---|---|
System.String | strModel | he string variable containing the model you want to load. |
Returns
Type | Description |
---|---|
KNearest |