<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 In this exercise, you'll apply what you learned in the Scaling and normalization tutorial.
Setup
The questions below will give you feedback on your work. Run the following cell to set up the feedback system.
Step1:  Get our environment set up
To practice scaling and normalization, we're going to use a dataset of Kickstarter campaigns. (Kickstarter is a website where people can ask people to invest in various projects and concept products.)
The next code cell loads in the libraries and dataset we'll be using.
Step2:  Let's start by scaling the goals of each campaign, which is how much money they were asking for.  After scaling, all values lie between 0 and 1.
Step3:  1) Practice scaling
We just scaled the "usd_goal_real" column. What about the "goal" column?
Begin by running the code cell below to create a DataFrame original_goal_data containing the "goal" column.
Step4:  Use original_goal_data to create a new DataFrame scaled_goal_data with values scaled between 0 and 1. You must use the minmax_scaling() function.
Step5:  2) Practice normalization
Now you'll practice normalization. We begin by normalizing the amount of money pledged to each campaign.
Step6:  The values have changed significantly with normalization!
In the next code cell, you'll take a look at the distribution of the normalized data, where it should now resemble a normal distribution.
Step7:  We used the "usd_pledged_real" column. Follow the same process to normalize the "pledged" column.
Step8:  How does the normalized "usd_pledged_real" column look different from when we normalized the "pledged" column?  Or, do they look mostly the same?
Once you have an answer, run the code cell below.
<ASSISTANT_TASK:>
Python Code:
from learntools.core import binder
binder.bind(globals())
from learntools.data_cleaning.ex2 import *
print("Setup Complete")
Explanation: In this exercise, you'll apply what you learned in the Scaling and normalization tutorial.
Setup
The questions below will give you feedback on your work. Run the following cell to set up the feedback system.
End of explanation
# modules we'll use
import pandas as pd
import numpy as np
# for Box-Cox Transformation
from scipy import stats
# for min_max scaling
from mlxtend.preprocessing import minmax_scaling
# plotting modules
import seaborn as sns
import matplotlib.pyplot as plt
# read in all our data
kickstarters_2017 = pd.read_csv("../input/kickstarter-projects/ks-projects-201801.csv")
# set seed for reproducibility
np.random.seed(0)
Explanation: Get our environment set up
To practice scaling and normalization, we're going to use a dataset of Kickstarter campaigns. (Kickstarter is a website where people can ask people to invest in various projects and concept products.)
The next code cell loads in the libraries and dataset we'll be using.
End of explanation
# select the usd_goal_real column
original_data = pd.DataFrame(kickstarters_2017.usd_goal_real)
# scale the goals from 0 to 1
scaled_data = minmax_scaling(original_data, columns=['usd_goal_real'])
print('Original data\nPreview:\n', original_data.head())
print('Minimum value:', float(original_data.min()),
      '\nMaximum value:', float(original_data.max()))
print('_'*30)
print('\nScaled data\nPreview:\n', scaled_data.head())
print('Minimum value:', float(scaled_data.min()),
      '\nMaximum value:', float(scaled_data.max()))
Explanation: Let's start by scaling the goals of each campaign, which is how much money they were asking for.  After scaling, all values lie between 0 and 1.
End of explanation
# select the usd_goal_real column
original_goal_data = pd.DataFrame(kickstarters_2017.goal)
Explanation: 1) Practice scaling
We just scaled the "usd_goal_real" column. What about the "goal" column?
Begin by running the code cell below to create a DataFrame original_goal_data containing the "goal" column.
End of explanation
# TODO: Your code here
scaled_goal_data = ____
# Check your answer
q1.check()
# Lines below will give you a hint or solution code
#_COMMENT_IF(PROD)_
q1.hint()
#_COMMENT_IF(PROD)_
q1.solution()
#%%RM_IF(PROD)%%
# scale the goals from 0 to 1
scaled_goal_data = minmax_scaling(original_goal_data, columns=['goal'])
q1.assert_check_passed()
Explanation: Use original_goal_data to create a new DataFrame scaled_goal_data with values scaled between 0 and 1. You must use the minmax_scaling() function.
End of explanation
# get the index of all positive pledges (Box-Cox only takes positive values)
index_of_positive_pledges = kickstarters_2017.usd_pledged_real > 0
# get only positive pledges (using their indexes)
positive_pledges = kickstarters_2017.usd_pledged_real.loc[index_of_positive_pledges]
# normalize the pledges (w/ Box-Cox)
normalized_pledges = pd.Series(stats.boxcox(positive_pledges)[0], 
                               name='usd_pledged_real', index=positive_pledges.index)
print('Original data\nPreview:\n', positive_pledges.head())
print('Minimum value:', float(positive_pledges.min()),
      '\nMaximum value:', float(positive_pledges.max()))
print('_'*30)
print('\nNormalized data\nPreview:\n', normalized_pledges.head())
print('Minimum value:', float(normalized_pledges.min()),
      '\nMaximum value:', float(normalized_pledges.max()))
Explanation: 2) Practice normalization
Now you'll practice normalization. We begin by normalizing the amount of money pledged to each campaign.
End of explanation
# plot normalized data
ax = sns.histplot(normalized_pledges, kde=True)
ax.set_title("Normalized data")
plt.show()
Explanation: The values have changed significantly with normalization!
In the next code cell, you'll take a look at the distribution of the normalized data, where it should now resemble a normal distribution.
End of explanation
# TODO: Your code here!
Explanation: We used the "usd_pledged_real" column. Follow the same process to normalize the "pledged" column.
End of explanation
# Check your answer (Run this code cell to receive credit!)
q2.check()
# Line below will give you a hint
#_COMMENT_IF(PROD)_
q2.hint()
#%%RM_IF(PROD)%%
# get the index of all positive pledges (Box-Cox only takes positive values)
index_positive_pledges = kickstarters_2017.pledged > 0
# get only positive pledges (using their indexes)
positive_pledges_only = kickstarters_2017.pledged.loc[index_positive_pledges]
# normalize the pledges (w/ Box-Cox)
normalized_values = pd.Series(stats.boxcox(positive_pledges_only)[0], 
                              name='pledged', index=positive_pledges_only.index)
# plot normalized data
ax = sns.histplot(normalized_values, kde=True)
ax.set_title("Normalized data")
Explanation: How does the normalized "usd_pledged_real" column look different from when we normalized the "pledged" column?  Or, do they look mostly the same?
Once you have an answer, run the code cell below.
End of explanation
<END_TASK>