Scaling Numerical Features Using RobustScaler in Pandas
15. Scaling Numerical Features Using Scikit-learn's RobustScaler
Write a Pandas program to scale numerical features using Scikit-learn's RobustScaler.
This exercise shows how to scale numerical features using Scikit-learn's RobustScaler to reduce the effect of outliers.
Sample Solution :
Code :
Output:
ID Name Age Gender Salary Target 0 1 Sara -0.8 Female -0.666667 0 1 2 Ophrah 0.2 Male 0.000000 1 2 3 Torben -1.4 Male 0.666667 0 3 4 Masaharu 1.2 Male 1.333333 1 4 5 Kaya NaN Female -0.333333 0 5 6 Abaddon 0.0 Male NaN 1
Explanation:
- Loaded the dataset using Pandas.
- Initialized RobustScaler to scale features while reducing the influence of outliers.
- Applied RobustScaler to the 'Age' and 'Salary' columns.
- Displayed the scaled dataset.
For more Practice: Solve these Related Problems:
- Write a Pandas program to scale numerical features using RobustScaler and compare the results with standard scaling.
- Write a Pandas program to apply RobustScaler to a DataFrame and verify that the scaled features are less affected by outliers.
- Write a Pandas program to use RobustScaler on selected columns and plot the distribution before and after scaling.
- Write a Pandas program to combine RobustScaler with other preprocessing steps and output a transformed dataset.
Go to:
Previous: Applying Polynomial Features for Feature Expansion.
Next: Saving the Processed Dataset to a CSV File.
Python-Pandas Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.