How to do it...

We'll begin by importing the required libraries, loading the dataset, and preparing the train and test sets:

  1. Import pandas and the required scikit-learn class and function:
import pandas as pdfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_split
  1. Let's load the Boston House Prices dataset from scikit-learn into a pandas dataframe:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)data['MEDV'] = boston_dataset.target
  1. Let's divide the data into train and test sets:
X_train, X_test, y_train, y_test = train_test_split(    data.drop('MEDV', axis=1), data['MEDV'], test_size=0.3, random_state=0)
  1. Let's learn the mean values from the ...

Get Python Feature Engineering Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.