Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You should see that the shape of x is ( 1 5 2 , 9 ) and the shape of y is ( 1 5

You should see that the shape of x is (152,9) and the shape of y is (152,). There are 152 samples (countries), and 9 features (each of the key_vars) that we are using to make predictions.
Note that the numerical data columns in x represent different quantities and have different scales. A key step in machine learning is standardization: the transformation of features to be on the same scale (with a mean of 0 and a standard deviation of 1). Standardization can substantially increase model accuracy, performance and interpretability.
sklearn provides various utilities to perform standardization. We will use one here called StandardScaler, which will transform a data set so that each resulting column has zero mean and unit standard deviation.
Carrying out this scaling is a little complicated if we want to maintain the basic structure of our dataframe, so we have provided the relevant code in the next code cell below. (The code examples describing StandardScaler in the sklearn documentation typically just extract out the numerical values in numpy arrays. For this exercise, we'd like to keep the labels together in a dataframe.)
Please perform the following steps in the below graded cell:
Import the StandardScaler object
Create and fit a StandardScaler object to our dataframe x
Create a new dataframe x_scaled that contains the scaled (transformed) data, using the column and index labels from our unscaled dataframe x
Print out the mean and standard deviation of each column of x_scaled
Peek at the head of the new dataframe x_scaled
In examining the output, check that the means of each column have been scaled to nearly zero (to within a very small tolerance) and the standard deviations have been scaled to one. Some of the very small numbers might be printed out in scientific notation, where a number like 1.928282e-16 means 1.928282*10**(-16).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions