Grid search on random forest

Grid search has been performed by changing various hyperparameters with the following settings. However, readers are encouraged to try other parameters to explore further in this space.

  • Number of trees is (1000,2000,3000)
  • Maximum depth is (100,200,300)
  • Minimum samples per split are (2,3)
  • Minimum samples in leaf node are (1,2)

Import Pipeline as follows:

>>> from sklearn.pipeline import Pipeline>>> from sklearn.model_selection import train_test_split,GridSearchCV

The Pipeline function creates the combinations which will be applied one by one sequentially to determine the best possible combination:

>>> pipeline = Pipeline([ ('clf',RandomForestClassifier(criterion='gini'))])>>> parameters = { ... 'clf__n_estimators':(1000,2000,3000), ...

Get Statistics for Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.