Reader small image

You're reading from  The Applied Data Science Workshop - Second Edition

Product typeBook
Published inJul 2020
Reading LevelIntermediate
PublisherPackt
ISBN-139781800202504
Edition2nd Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Alex Galea
Alex Galea
author image
Alex Galea

Alex Galea has been professionally practicing data analytics since graduating with a masters degree in physics from the University of Guelph, Canada. He developed a keen interest in Python while researching quantum gases as part of his graduate studies. Alex is currently doing web data analytics, where Python continues to play a key role in his work. He is a frequent blogger about data-centric projects that involve Python and Jupyter Notebooks.
Read more about Alex Galea

Right arrow

2. Data Exploration with Jupyter

Activity 2.01: Building a Third-Order Polynomial Model

Solution:

  1. 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']
  2. 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.

  3. Verify what x looks like by executing the following code:
    x[:3]

    The output is as follows:

    array([[4.98],
           [9.14],
           ...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
The Applied Data Science Workshop - Second Edition
Published in: Jul 2020Publisher: PacktISBN-13: 9781800202504

Author (1)

author image
Alex Galea

Alex Galea has been professionally practicing data analytics since graduating with a masters degree in physics from the University of Guelph, Canada. He developed a keen interest in Python while researching quantum gases as part of his graduate studies. Alex is currently doing web data analytics, where Python continues to play a key role in his work. He is a frequent blogger about data-centric projects that involve Python and Jupyter Notebooks.
Read more about Alex Galea