July 2017
Intermediate to advanced
382 pages
9h 13m
English
The easiest way to perform cross-validation in OpenCV is to do the data splits by hand.
For example, in order to implement two-fold cross-validation, we would follow the following procedure:
In [1]: from sklearn.datasets import load_iris ... import numpy as np ... iris = load_iris() ... X = iris.data.astype(np.float32) ... y = iris.target
In [2]: from sklearn.model_selection import model_selection ... X_fold1, X_fold2, y_fold1, y_fold2 = train_test_split( ... X, y, random_state=37, train_size=0.5 ... )
In [3]: import cv2 ... knn = cv2.ml.KNearest_create() ... knn.setDefaultK(1)
Read now
Unlock full access