Feature Scaling or Standardization: It is a step of Data Pre Processing which is applied to independent variables or features of data. It basically helps to normalise the data within a particular range. Sometimes, it also helps in speeding up the calculations in an algorithm.
Package Used:
sklearn.preprocessing
Import:
from sklearn.preprocessing import StandardScaler
Formula used in Backend
Standardisation replaces the values by their Z scores.

Mostly the Fit method is used for Feature scaling
fit(X, y = None) Computes the mean and std to be used for later scaling.
import pandas as pd from sklearn.preprocessing import StandardScaler # Read Data from CSV data = read_csv('Geeksforgeeks.csv') data.head() # Initialise the Scaler scaler = StandardScaler() # To scale data scaler.fit(data) |
Why and Where to Apply Feature Scaling?
Real world dataset contains features that highly vary in magnitudes, units, and range. Normalisation should be performed when the scale of a feature is irrelevant or misleading and not should Normalise when the scale is meaningful.
The algorithms which use Euclidean Distance measure are sensitive to Magnitudes. Here feature scaling helps to weigh all the features equally.
Formally, If a feature in the dataset is big in scale compared to others then in algorithms where Euclidean distance is measured this big scaled feature becomes dominating and needs to be normalized.
Examples of Algorithms where Feature Scaling matters
1. K-Means uses the Euclidean distance measure here feature scaling matters.
2. K-Nearest-Neighbours also require feature scaling.
3. Principal Component Analysis (PCA): Tries to get the feature with maximum variance, here too feature scaling is required.
4. Gradient Descent: Calculation speed increase as Theta calculation becomes faster after feature scaling.
Note: Naive Bayes, Linear Discriminant Analysis, and Tree-Based models are not affected by feature scaling.
In Short, any Algorithm which is Not Distance based is Not affected by Feature Scaling.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Overview of Scaling: Vertical And Horizontal Scaling
- ML | Feature Scaling - Part 1
- ML | Feature Scaling – Part 2
- Apply a function to each row or column in Dataframe using pandas.apply()
- Image Processing in Python (Scaling, Rotating, Shifting and Edge Detection)
- Python - Scaling image using pgmagic
- PyQtGraph – Scaling Error Bar Graph
- PyQtGraph – Getting Scaling of Error Bar Graph
- Feature matching using ORB algorithm in Python-OpenCV
- Parameters for Feature Selection
- ML | Feature Mapping
- Feature Extraction Techniques - NLP
- ML | Chi-square Test for feature selection
- Chi-Square Test for Feature Selection - Mathematical Explanation
- ML | Extra Tree Classifier for Feature Selection
- Pyspark | Linear regression with Advanced Feature Dataset using Apache MLlib
- Sklearn | Feature Extraction with TF-IDF
- Feature Encoding Techniques - Machine Learning
- PyQt5 QDockWidget – Getting Feature change signal
- Python | Pandas.apply()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai

