ml.Machine Learning
ocl::KNearestNeighbour
The class implements K-Nearest Neighbors model as described in the beginning of this section.
ocl::KNearestNeighbour
Computes the weighted sum of two arrays.
class CV_EXPORTS KNearestNeighbour: public CvKNearest
{
public:
KNearestNeighbour();
~KNearestNeighbour();
bool train(const Mat& trainData, Mat& labels, Mat& sampleIdx = Mat().setTo(Scalar::all(0)),
bool isRegression = false, int max_k = 32, bool updateBase = false);
void clear();
void find_nearest(const oclMat& samples, int k, oclMat& lables);
private:
/* hidden */
};
ocl::KNearestNeighbour::train
Trains the model.
The method trains the K-Nearest model. It follows the conventions of the generic :ocv:func:`CvStatModel::train` approach with the following limitations:
- Only
CV_ROW_SAMPLE
data layout is supported. - Input variables are all ordered.
- Output variables can be either categorical (
is_regression=false
) or ordered (is_regression=true
). - Variable subsets (
var_idx
) and missing measurements are not supported.
ocl::KNearestNeighbour::find_nearest
Finds the neighbors and predicts responses for input vectors.
ocl::kmeans
Finds centers of clusters and groups input samples around the clusters.
ocl::distanceToCenters
For each samples in source
, find its closest neighour in centers
.
The method is a utility function which maybe used for multiple clustering algorithms such as K-means.