Data Scaling Techniques
Lesson Introduction
Hello! Today, we are diving into the world of data scaling techniques. Imagine you are playing a game where you need to fit different shapes into matching holes. If your shapes vary greatly in size, it can be challenging. Similarly, in data analysis and machine learning, features (or columns) in your dataset may have vastly different scales. This can affect the performance of your analysis or model.
Our goal for this lesson is to understand two key data scaling techniques: Standard Scaling and Min-Max Scaling. By the end of this lesson, you'll be able to apply these techniques to scale features in a dataset, making them easier to work with.
Understanding Standard Scaling
Standard Scaling is like leveling the playing field for your data. It transforms your data so it has a mean (average) of 0 and a standard deviation (how spread out the numbers are) of 1. This is especially useful when you want your data to follow a standard normal distribution.
The formula for standard scaling is:
Where:
- is the original value.
- is the mean of the values.
- is the standard deviation of the values.
In simpler terms, you subtract the average value from each data point and then divide by how much your data varies from the average.
Applying Standard Scaling
Let's use the Titanic dataset to perform Standard Scaling on the age and fare columns.
Output:
Note: The Titanic
agecolumn contains missing values. Pandas’mean()andstd()skip missing values by default, so the scaling parameters are calculated only from non-missing ages. Missing ages will remainNaNafter scaling. Also,Series.std()uses the sample standard deviation by default, equivalent toddof=1, which can differ slightly from tools like scikit-learn’sStandardScaler, which uses population standard deviation.
