Answered step by step
Verified Expert Solution
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 and the shape of y is There are samples countries and features each of the keyvars 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 and a standard deviation of 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 xscaled 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 xscaled
Peek at the head of the new dataframe xscaled
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 e means
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started