Bootstrapping can be implemented with the following procedure:
- Load the dataset. Since we already did this earlier, we don't have to do it again.
- Instantiate the classifier:
In [15]: knn = cv2.ml.KNearest_create() ... knn.setDefaultK(1)
- From our dataset with N samples, randomly choose N samples with replacement to form a bootstrap. This can be done most easily with the choice function from NumPy's random module. We tell the function to draw len(X) samples in the [0, len(X)-1] range with replacement (replace=True). The function then returns a list of indices, from which we form our bootstrap:
In [16]: idx_boot = np.random.choice(len(X), size=len(X), ... replace=True) ... X_boot = X[idx_boot, ...