The Wayback Machine - https://web.archive.org/web/20240909163625/https://www.geeksforgeeks.org/ml-feature-scaling-part-1/
Open In App

ML | Feature Scaling – Part 1

Last Updated : 25 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow
Companies:
Show Topics
Solve Problem
Medium
21.56%
904

Feature Scaling is a technique to standardize the independent features present in the data in a fixed range. It is performed during the data pre-processing. 

Working: 
Given a data-set with features- Age, Salary, BHK Apartment with the data size of 5000 people, each having these independent data features. 

Each data point is labeled as: 

  • Class1- YES (means with the given Age, Salary, BHK Apartment feature value one can buy the property)
  • Class2- NO (means with the given Age, Salary, BHK Apartment feature value one can’t buy the property).

Using a dataset to train the model, one aims to build a model that can predict whether one can buy a property or not with given feature values. 

Once the model is trained, an N-dimensional (where N is the no. of features present in the dataset) graph with data points from the given dataset, can be created. The figure given below is an ideal representation of the model.  

As shown in the figure, star data points belong to Class1 – Yes and circles represent Class2 – No labels, and the model gets trained using these data points. Now a new data point (diamond as shown in the figure) is given and it has different independent values for the 3 features (Age, Salary, BHK Apartment) mentioned above. The model has to predict whether this data point belongs to Yes or No. 

Prediction of the class of new data points: 
The model calculates the distance of this data point from the centroid of each class group. Finally, this data point will belong to that class, which will have a minimum centroid distance from it. 
The distance can be calculated between centroid and data point using these methods- 

  • Euclidean Distance: It is the square root of the sum of squares of differences between the coordinates (feature values – Age, Salary, BHK Apartment) of data point and centroid of each class. This formula is given by the Pythagorean theorem. 
    d(x, y)=\sqrt[r]{\sum_{k=1}^{n}\left(x_{k}-y_{k}\right)^{r}}
    where x is Data Point value, y is Centroid value and k is no. of feature values, Example: given data set has k = 3
  • Manhattan Distance: It is calculated as the sum of absolute differences between the coordinates (feature values) of data point and centroid of each class. 
    d(x, y)=\sum_{k=1}^{n}\left|x_{k}-y_{k}\right|
     
  • Minkowski Distance: It is a generalization of the above two methods. As shown in the figure, different values can be used for finding r.

Need of Feature Scaling: 
The given data set contains 3 features – Age, Salary, BHK Apartment. Consider a range of 10- 60 for Age, 1 Lac- 40 Lacs for Salary, 1- 5 for BHK of Flat. All these features are independent of each other. 
Suppose the centroid of class 1 is [40, 22 Lacs, 3] and the data point to be predicted is [57, 33 Lacs, 2]. 

Using Manhattan Method, 

Distance = (|(40 - 57)| + |(2200000 - 3300000)| + |(3 - 2)|)

It can be seen that the Salary feature will dominate all other features while predicting the class of the given data point and since all the features are independent of each other i.e. a person’s salary has no relation with his/her age or what requirement of the flat he/she has. This means that the model will always predict wrong. 

So, the simple solution to this problem is Feature Scaling. Feature Scaling Algorithms will scale Age, Salary, BHK in a fixed range say [-1, 1] or [0, 1]. And then no feature can dominate others. 

 


Previous Article
Next Article

Similar Reads

Feature Scaling - Part 3
Prerequisite - Feature Scaling | Set-1 , Set-2 Feature Scaling is one of the most important steps of Data Preprocessing. It is applied to independent variables or features of data. The data sometimes contains features with varying magnitudes and if we do not treat them, the algorithms only take in the magnitude of these features, neglecting the uni
4 min read
Overview of Scaling: Vertical And Horizontal Scaling
Given architecture is an example of a client-server based system. In this, there is a client who sends requests to the server and then the client receives a response from the server accordingly but when the number of users/clients increases, the load on the server increases enormously which makes it difficult for the server to perform efficiently a
4 min read
Python | How and where to apply Feature Scaling?
Feature Scaling or Standardization: It is a step of Data Pre Processing that is applied to independent variables or features of data. It helps to normalize 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 Standa
2 min read
Feature Engineering: Scaling, Normalization, and Standardization
If you are an ML practitioner then you must have come across the term feature scaling which is considered as an unskippable part of the data processing cycle so, that we can achieve stable and fast training of our ML algorithm. In this article, we will learn about different techniques which are used to perform feature scaling in practice. What is F
6 min read
Do Clustering Algorithms Need Feature Scaling in the Pre-Processing Stage?
Answer: Yes, clustering algorithms typically require feature scaling to ensure equal distance consideration across all features.Without scaling, features with larger scales dominate the distance calculations, leading to biased clusters. Here's a comparison table to illustrate the impact of feature scaling on different clustering algorithms: Cluster
1 min read
Logistic Regression and the Feature Scaling Ensemble
Logistic Regression is a widely used classification algorithm in machine learning. However, to enhance its performance further specially when dealing with features of different scales, employing feature scaling ensemble techniques becomes imperative. In this guide, we will dive depth into logistic regression, its significance and how feature sealin
9 min read
Difference Between Feature Selection and Feature Extraction
Machine learning models require input features that are relevant and important to predict the outcome. However, not all features are equally important for a prediction task, and some features might even introduce noise in the model. Feature selection and feature extraction are two methods to handle this problem. In this article, we will explore the
8 min read
Is There Any Difference Between Feature Extraction and Feature Learning?
Answer: Yes, feature extraction involves manually selecting characteristics from data, while feature learning allows models to automatically discover the features to be used for a task.Feature extraction and feature learning represent two methodologies in machine learning for identifying and utilizing relevant information from raw data to improve m
1 min read
Find partitions that maximises sum of count of 0's in left part and count of 1's in right part
Given a binary array nums of length N, The task is to find all possible partitions in given array such that sum of count of 0's in left part and count of 1's in right part is maximized. Example: Input: nums = {0, 0, 1, 0}Output: 2, 4Explanation: Division at indexindex - 0: numsleft is []. numsright is [0, 0, 1, 0]. The sum is 0 + 1 = 1.index - 1: n
7 min read
2D Transformation in Computer Graphics | Set 1 (Scaling of Objects)
We can use a 2 × 2 matrix to change or transform, a 2D vector. This kind of operation, which takes in a 2-vector and produces another 2-vector by a simple matrix multiplication, is a linear transformation. By this simple formula, we can achieve a variety of useful transformations, depending on what we put in the entries of the matrix. For our purpo
5 min read
What is TCP Window Scaling?
In the TCP header, the window size field is of size 16 bits. Using this field TCP users (client or server) can advertise a maximum of 216 = 65536 bytes or 64 KiB as its buffer size to its other end-user. But modern endpoint devices (e.g., phones, tabs, PCs, etc) have much more memory available in their buffers. This 16-bit field was enough during t
5 min read
Computer Graphics - 3D Scaling Transformation
Prerequisite: Computer Graphics – 3D Translation Transformation Scaling Transformation : It is performed to resize the 3D-object that is the dimension of the object can be scaled(alter) in any of the x, y, z direction through Sx, Sy, Sz scaling factors. Matrix representation of Scaling transformation Condition : [Tex]\large S[x, y, z]= \left [ \beg
3 min read
Find instances at end of time frame after auto scaling
Content Removed.
1 min read
Scaling techniques in Machine Learning
Definition: Scaling is a technique of generating an endless sequence of values, upon which the measured objects are placed. Several scaling techniques are employed to review the connection between the objects. Following are the two categories under scaling techniques: Comparative scales: It involves the direct comparison of objects. Comparative sca
5 min read
Multidimensional Scaling (MDS) using Scikit Learn
Multidimensional scaling (MDS) is a dimensionality reduction technique that is used to project high-dimensional data onto a lower-dimensional space while preserving the pairwise distances between the data points as much as possible. MDS is based on the concept of distance and aims to find a projection of the data that minimizes the differences betw
7 min read
System Scaling - Optimization Trade offs
Network Load Balancer (NLB) can handle traffic spikes, handle millions of requests per second however, it doesn't support logging, so use cloudwatch to keep all logs in centralized place. Things to ponder before horizontal scaling. Ensure thread safe code - for horizontal scalingConnection pooling, no direct connection upon instantiationManagement
6 min read
Sklearn | Multi-dimensional Scaling (MDS) Python Implementation from Scratch
Scikit-learn (sklearn) is a Python machine-learning package that is open-source and free to use. It is Python's most popular machine-learning library, and it is extensively used in business and academics. Scikit-learn includes a wide range of machine learning methods, including supervised learning (classification, regression), unsupervised learning
10 min read
Parameters for Feature Selection
Prerequisite : Introduction to Dimensionality Reduction Dimensionality reduction is the process of reducing the number of random variables under consideration, by obtaining a set of principal variables. It can be divided into feature selection and feature extraction. Dimensionality Reduction is an important factor in predictive modeling. Various pr
5 min read
ML | Feature Mapping
Introduction : Feature mapping is a technique used in data analysis and machine learning to transform input data from a lower-dimensional space to a higher-dimensional space, where it can be more easily analyzed or classified. Feature mapping involves selecting or designing a set of functions that map the original data to a new set of features that
12 min read
Feature Matching using Brute Force in OpenCV
In this article, we will do feature matching using Brute Force in Python by using OpenCV library. Prerequisites: OpenCV OpenCV is a python library which is used to solve the computer vision problems. OpenCV is an open source Computer Vision library. So computer vision is a way of teaching intelligence to machine and making them see things just like
13 min read
ML | Extra Tree Classifier for Feature Selection
Prerequisites: Decision Tree Classifier Extremely Randomized Trees Classifier(Extra Trees Classifier) is a type of ensemble learning technique which aggregates the results of multiple de-correlated decision trees collected in a "forest" to output it's classification result. In concept, it is very similar to a Random Forest Classifier and only diffe
6 min read
Pyspark | Linear regression with Advanced Feature Dataset using Apache MLlib
Ames Housing Data: The Ames Housing dataset was compiled by Dean De Cock for use in data science education and expanded version of the often-cited Boston Housing dataset. The dataset provided has 80 features and 1459 instances. Dataset description is as below: For demo few columns are displayed but there are a lot more columns are there in the data
4 min read
Feature Encoding Techniques - Machine Learning
As we all know that better encoding leads to a better model and most algorithms cannot handle the categorical variables unless they are converted into a numerical value. Categorical features are generally divided into 3 types: A. Binary: Either/or Examples: Yes, NoTrue, False B. Ordinal: Specific ordered Groups. Examples: low, medium, highcold, hot
5 min read
How to add Rate the App feature in Android
When you publish your app on google play store it is important to get feedback from the user. Unless the user does not love or hate your app, they are not likely to go out of their way to rate your app. Since high rating indicates the success of your app, and even criticism is required to make the application better. So, it is better to add a rate
2 min read
Feature Selection using Branch and Bound Algorithm
Feature selection is a very important factor in Machine Learning. To get the algorithms to work properly and give near about perfect predictions, i.e to enhance the performance of a predictive model, feature selection is required. Large set of features or redundant ones should be removed. Up to a certain number of features, the accuracy of a classi
4 min read
Feature Subset Selection Process
Feature Selection is the most critical pre-processing activity in any machine learning process. It intends to select a subset of attributes or features that makes the most meaningful contribution to a machine learning activity. In order to understand it, let us consider a small example i.e. Predict the weight of students based on the past informati
12 min read
SVM with Univariate Feature Selection in Scikit Learn
Support Vector Machines (SVM) is a powerful machine learning algorithm used for classification and regression analysis. It is based on the idea of finding the optimal boundary between two classes that maximizes the margin between them. However, the challenge with SVM is that it requires a large amount of computational power and is sensitive to the
10 min read
Joint Feature Selection with multi-task Lasso in Scikit Learn
This article is likely to introduces the concepts of Lasso and multitask Lasso regression and demonstrates how to implement these methods in Python using the scikit-learn library. The article is going to cover the differences between Lasso and multitask Lasso and provide guidance on which method to prefer in different situations. It may also provid
7 min read
Feature Transformation Techniques in Machine Learning
Most machine learning algorithms are statistics dependent, meaning that all of the algorithms are indirectly using a statistical approach to solve the complex problems in the data. In statistics, the normal distribution of the data is one that a statistician desires to be. A normal distribution of the data helps statisticians to solve the complex p
6 min read
Recursive Feature Elimination with Cross-Validation in Scikit Learn
In this article, we will earn how to implement recursive feature elimination with cross-validation using scikit learn package in Python. What is Recursive Feature Elimination (RFE)? Recursive Feature Elimination (RFE) is a feature selection algorithm that is used to select a subset of the most relevant features from a dataset. It is a recursive pro
5 min read