2. Data Exploration with Jupyter
Activity 2.01: Building a Third-Order Polynomial Model
Solution:
- Load the necessary libraries and the dataset from scikit-learn, as follows:
import pandas as pd import matplotlib.pyplot as plt import numpy as np from sklearn import datasets boston = datasets.load_boston() df = pd.DataFrame(data=boston['data'], \ columns=boston['feature_names'],) df['MEDV'] = boston['target']
- First, we will pull out our dependent feature and target variable from
df
, as follows:y = df['MEDV'].values x = df['LSTAT'].values.reshape(-1,1)
This is identical to what we did earlier for the linear model.
- Verify what
x
looks like by executing the following code:x[:3]
The output is as follows:
array([[4.98], [9.14], ...