Skip to content
Search

OpenCV:MachineLearning

lastmod 2024-04-24created 2023-10-113 edits

Algorithms

  • ANN_MLP - An artificial neural network multi-layer perceptron. It can train a neural network with multiple hidden layers and predict results for input data.
  • DTrees - Binary decision trees algorithm. The DTrees class serves as the parent class of the ml::Boost class, which implements the boosting algorithm, and the ml::RTree class, which implements the random tree algorithm.
  • Boost - Boosting algorithm. A method of building a high-performing classifier by assigning appropriate weights to many weak classifiers.
  • RTrees - Random tree or Korean: 랜덤 포레스트(random forest) algorithm. It predicts an input feature vector with many trees and aggregates the results to perform classification or regression.
  • EM - Stands for Expectation Maximization. A clustering algorithm using a Gaussian mixture model.
  • KNearest - K-Nearest Neighbors algorithm. The k-nearest neighbors algorithm finds the k training data points adjacent to the sample data and assigns the most frequent class among them as the class of the sample data.
  • LogisticRegression - Logistic regression. A type of binary classification algorithm.
  • NormalBayesClassifier - Normal Bayes classifier. The normal Bayes classifier assumes that the feature vectors of each class follow a normal distribution. The overall data distribution can therefore be expressed as a Gaussian mixture model. The normal Bayes classifier computes the mean vector and covariance matrix of each class from the training data and uses them for prediction.
  • SVM - Support vector machine algorithm. It finds the hyperplane that separates the data of two classes with the largest margin. Using the kernel trick, it can also classify nonlinear data, and it can be applied to multi-class classification and regression.
  • SVMSDG - Stochastic gradient descent SVM. Applying stochastic gradient descent to SVM enables fast training even on large datasets.

APIs

Creating machine learning algorithm objects

Objects can be created with cv2.ml.XXX_create().

  • cv2.ml.SVM_create()
  • cv2.ml.KNearet_create()
  • etc ...

Each machine learning algorithm object is created as the return value.

Training machine learning algorithms

Training is done with a train function such as cv2.ml_SVM.train. Appropriate arguments must be passed.

Arguments:

  • samples - Training data matrix.
  • layout - How the training data is laid out.
    • cv2.ROW_SAMPLE - Each sample consists of one row
    • cv2.COL_SAMPLE - Each sample consists of one column
  • responses - Matrix of responses (labels) corresponding to each training sample.
  • retval - True if training succeeds.

Prediction with machine learning algorithms

Inference is done with a predict function such as cv2.ml_SVM.predict.

Arguments:

  • samples - Matrix with input vectors stored row by row.
  • results - Matrix storing the prediction (classification or regression) results for each input sample.
  • flags - Additional flags.
    • Default is 0.
    • If cv2.ml.STAT_MODEL_RAW_OUTPUT is specified, outputs the actual computed value instead of the class label.
  • retval - Depends on the algorithm

See also

Favorite site

author Zer0 sitemap