public class KNearest extends StatModel
Modifier and Type | Field and Description |
---|---|
static int |
BRUTE_FORCE |
static int |
KDTREE |
COMPRESSED_INPUT, PREPROCESSED_INPUT, RAW_OUTPUT, UPDATE_MODEL
Modifier | Constructor and Description |
---|---|
protected |
KNearest(long addr) |
Modifier and Type | Method and Description |
---|---|
static KNearest |
__fromPtr__(long addr) |
static KNearest |
create()
Creates the empty model
The static method creates empty %KNearest classifier.
|
protected void |
finalize() |
float |
findNearest(Mat samples,
int k,
Mat results)
Finds the neighbors and predicts responses for input vectors.
|
float |
findNearest(Mat samples,
int k,
Mat results,
Mat neighborResponses)
Finds the neighbors and predicts responses for input vectors.
|
float |
findNearest(Mat samples,
int k,
Mat results,
Mat neighborResponses,
Mat dist)
Finds the neighbors and predicts responses for input vectors.
|
int |
getAlgorithmType()
SEE: setAlgorithmType
|
int |
getDefaultK()
SEE: setDefaultK
|
int |
getEmax()
SEE: setEmax
|
boolean |
getIsClassifier()
SEE: setIsClassifier
|
static KNearest |
load(String filepath)
Loads and creates a serialized knearest from a file
Use KNearest::save to serialize and store an KNearest to disk.
|
void |
setAlgorithmType(int val)
getAlgorithmType SEE: getAlgorithmType
|
void |
setDefaultK(int val)
getDefaultK SEE: getDefaultK
|
void |
setEmax(int val)
getEmax SEE: getEmax
|
void |
setIsClassifier(boolean val)
getIsClassifier SEE: getIsClassifier
|
calcError, empty, getVarCount, isClassifier, isTrained, predict, predict, predict, train, train, train
clear, getDefaultName, getNativeObjAddr, save
public static final int BRUTE_FORCE
public static final int KDTREE
public static KNearest __fromPtr__(long addr)
public static KNearest create()
public static KNearest load(String filepath)
filepath
- path to serialized KNearestpublic boolean getIsClassifier()
public float findNearest(Mat samples, int k, Mat results, Mat neighborResponses, Mat dist)
samples
- Input samples stored by rows. It is a single-precision floating-point matrix of
<number_of_samples> * k
size.k
- Number of used nearest neighbors. Should be greater than 1.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.neighborResponses
- Optional output values for corresponding neighbors. It is a single-
precision floating-point matrix of <number_of_samples> * k
size.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.
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors.
In case of regression, the predicted result is a mean value of the particular vector's neighbor
responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will
allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted
value is returned by the method.
The function is parallelized with the TBB library.public float findNearest(Mat samples, int k, Mat results, Mat neighborResponses)
samples
- Input samples stored by rows. It is a single-precision floating-point matrix of
<number_of_samples> * k
size.k
- Number of used nearest neighbors. Should be greater than 1.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.neighborResponses
- Optional output values for corresponding neighbors. It is a single-
precision floating-point matrix of <number_of_samples> * k
size.
is a single-precision floating-point matrix of <number_of_samples> * k
size.
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors.
In case of regression, the predicted result is a mean value of the particular vector's neighbor
responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will
allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted
value is returned by the method.
The function is parallelized with the TBB library.public float findNearest(Mat samples, int k, Mat results)
samples
- Input samples stored by rows. It is a single-precision floating-point matrix of
<number_of_samples> * k
size.k
- Number of used nearest neighbors. Should be greater than 1.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.
precision floating-point matrix of <number_of_samples> * k
size.
is a single-precision floating-point matrix of <number_of_samples> * k
size.
For each input vector (a row of the matrix samples), the method finds the k nearest neighbors.
In case of regression, the predicted result is a mean value of the particular vector's neighbor
responses. In case of classification, the class is determined by voting.
For each input vector, the neighbors are sorted by their distances to the vector.
In case of C++ interface you can use output pointers to empty matrices and the function will
allocate memory itself.
If only a single input vector is passed, all output matrices are optional and the predicted
value is returned by the method.
The function is parallelized with the TBB library.public int getAlgorithmType()
public int getDefaultK()
public int getEmax()
public void setAlgorithmType(int val)
val
- automatically generatedpublic void setDefaultK(int val)
val
- automatically generatedpublic void setEmax(int val)
val
- automatically generatedpublic void setIsClassifier(boolean val)
val
- automatically generatedGenerated on Wed Oct 9 2019 23:24:43 UTC / OpenCV 4.1.2