To begin, we will import the required packages, load the dataset, and prepare the train and test sets:
- Import pandas and the required scikit-learn classes and function:
import pandas as pdfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import RobustScaler
- 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
- 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) ...