Bagging works with samples in a way that is similar to that of pasting, but it allows replacement. Also, theoretically elaborated by Leo Breiman, bagging is implemented in a specific scikit-learn class for regression and one for classification. You just have to decide the algorithm that you'd like to use for the training. Plug it into BaggingClassifier, or BaggingRegressor for regression problems, and set a sufficiently high number of estimators (and consequently a high number of samples):
In: import numpy as np from sklearn.model_selection import cross_val_score from sklearn.ensemble import BaggingClassifier from sklearn.neighbors import KNeighborsClassifier hypothesis = BaggingClassifier(KNeighborsClassifier(n_neighbors=1), ...