Randomized search with scikit-learn
From a practical standpoint, RandomizedSearchCV
is more important than a regular grid search. This is because with a medium amount of data, or with a model involving a few parameters, it is too computationally expensive to try every parameter combination involved in a complete grid search.
Computational resources are probably better spent stratifying sampling very well, or improving randomization procedures.
Getting ready
As before, load the last two features of the iris dataset. Split the data into training and testing sets:
from sklearn import datasets iris = datasets.load_iris() X = iris.data[:,2:] y = iris.target from sklearn.model_selection import train_test_split X_train, X_test, y_train, y_test = train_test_split(X, y, stratify = y,random_state = 7)
How to do it...
- Instantiate a nearest neighbors classifier:
from sklearn.neighbors import KNeighborsClassifier knn_clf = KNeighborsClassifier()
- Prepare a parameter distribution, which is necessary for a...