Show / Hide Table of Contents

Class KNearest

K nearest neighbors classifier

Inheritance
System.Object
DisposableObject
DisposableCvObject
Algorithm
StatModel
KNearest
Implements
ICvPtrHolder
Inherited Members
StatModel.GetVarCount()
StatModel.Empty()
StatModel.IsTrained()
StatModel.Train(TrainData, Int32)
StatModel.Train(InputArray, SampleTypes, InputArray)
StatModel.CalcError(TrainData, Boolean, OutputArray)
StatModel.Predict(InputArray, OutputArray, StatModel.Flags)
Algorithm.Write(FileStorage)
Algorithm.Read(FileNode)
Algorithm.Save(String)
Algorithm.GetDefaultName()
DisposableCvObject.ptr
DisposableCvObject.CvPtr
DisposableObject.DataHandle
DisposableObject.IsDisposed
DisposableObject.IsEnabledDispose
DisposableObject.AllocatedMemory
DisposableObject.AllocatedMemorySize
DisposableObject.Dispose()
DisposableObject.Dispose(Boolean)
DisposableObject.AllocGCHandle(Object)
DisposableObject.AllocMemory(Int32)
DisposableObject.NotifyMemoryPressure(Int64)
DisposableObject.ThrowIfDisposed()
Namespace: OpenCvSharp.ML
Assembly: OpenCvSharp.dll
Syntax
public class KNearest : StatModel, ICvPtrHolder

Constructors

| Improve this Doc View Source

KNearest(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 Source

AlgorithmType

Algorithm type, one of KNearest::Types.

Declaration
public KNearest.Types AlgorithmType { get; set; }
Property Value
Type Description
KNearest.Types
| Improve this Doc View Source

DefaultK

Default number of neighbors to use in predict method.

Declaration
public int DefaultK { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

Emax

Parameter for KDTree implementation

Declaration
public int Emax { get; set; }
Property Value
Type Description
System.Int32
| Improve this Doc View Source

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 Source

Create()

Creates the empty model

Declaration
public static KNearest Create()
Returns
Type Description
KNearest
| Improve this Doc View Source

DisposeManaged()

Releases managed resources

Declaration
protected override void DisposeManaged()
Overrides
DisposableObject.DisposeManaged()
| Improve this Doc View Source

DisposeUnmanaged()

Declaration
protected override void DisposeUnmanaged()
Overrides
DisposableCvObject.DisposeUnmanaged()
| Improve this Doc View Source

FindNearest(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 [number_of_samples] * k size.

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 [number_of_samples] elements.

OutputArray neighborResponses

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

OutputArray dist

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
Type Description
System.Single
| Improve this Doc View Source

Get()

Declaration
public override IntPtr Get()
Returns
Type Description
IntPtr
| Improve this Doc View Source

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
| Improve this Doc View Source

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

Implements

ICvPtrHolder
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX