How to do it...

  1. Load the data from the California housing dataset once again. Observe how we create bins once more to stratify a continuous variable:
%matplotlib inlineimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom sklearn.datasets import fetch_california_housingcali_housing = fetch_california_housing()X = cali_housing.datay = cali_housing.targetbins = np.arange(6) from __future__ import divisionfrom sklearn.model_selection import train_test_splitbinned_y = np.digitize(y, bins)from sklearn.ensemble import RandomForestRegressor, AdaBoostRegressor, ExtraTreesRegressor, GradientBoostingRegressor from sklearn.model_selection import GridSearchCV
  1. Now split the pair, X and y, into three X and y pairs, input and output, ...

Get scikit-learn Cookbook - Second Edition 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.