R Tutorial: The importance of scale
Skills:
ML Maths Basics90%
Key Takeaways
Explains the importance of scale in cluster analysis using R
Full Transcript
when calculating the distance between two players on a soccer field we use two features X and y both of these features are the coordinates of the players and both are measured in the same manner because of this they are comparable to one another and can be used together to calculate the Euclidean distance between the players but what happens when the features aren't measured in the same manner or to put it another way when the values of these features aren't comparable to one another to answer this question let's walk through an example imagine you're provided with a data set that contains the heights and weights for a large number of men in the United States the height feature is measured in feet and the weight feature and pounds you are interested in calculating the distance between these individuals let us start by comparing observations 1 & 2 here both men are the same height 6 feet but they differ slightly in weight in this case the difference is 2 pounds if we calculated the Euclidean distance between them we would get a value of 2 now let's look at observations 1 & 3 in this comparison the weights are the same but the height is different by to eat if we calculate the distance once more you guessed it it's also 2 the distances between both pairs are identical if we saw these three men standing side by side would you really believe that one observation is just as similar as the other 2 of course not then why are there distances the same this happens because these features are on different scales meaning they have different averages and different expected variability while in these comparisons these features only vary by a magnitude of 2 we intuitively know that a change in two pounds is very different than a change in two repeat so how can we adjust these features to calculate a distance a better aligns with our expectations to do this we need to convert our features to be on a similar scale with one another there are various methods for doing this but for this course we will use the method called standardization this entails updating each measurement for feature by subtracting the average value of that feature and then dividing by its standard deviation doing this across our features places them on a similar scale where each feature has a mean of 0 and a standard deviation of 1 going back to the previous scenario we can use the mean and standard deviation of the height and weight features to standardize the value for our three observations now if we calculate the Euclidean distances between them voila the values makes sense they agree with our intuition 1 & 3 are much less similar to one another and 1 & 2 in our we can use the scale function to standardize height and weight to the same scale if height weight is our matrix of observations similar to what we've just seen using the scale functions with the default parameters will normalize each feature column to a mean of 0 and a variance of 1 in the next exercise you will have a chance to further explore how scales can affect your ability to interpret the distance value
Original Description
Want to learn more? Take the full course at https://learn.datacamp.com/courses/cluster-analysis-in-r at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
When calculating the distance between two players on a soccer field, you used two features, x and y.
Both of these features are the coordinates of the players and both are measured in the same manner.
Because of this, they are comparable to one another and can be used together to calculate the euclidean distance between the players.
But, what happens when the features aren't measured in the same manner or to put it another way, when the values of these features aren't comparable to one another?
To answer this question let's walk through an example.
Imagine you are provided with a dataset that contains the heights and weights for a large number of men in the United States. The height feature is measured in feet and the weight feature in pounds.
You are interested in calculating the distance between these individuals.
Let us start by comparing observations one and two.
Both men are the same height, six feet. But they differ slightly in weight. In this case the difference is two pounds.
If we calculated the euclidean distance between them we would get a value of two.
Now let's look at observations one and three.
In this comparison, the weights are the same, but the height is different by two feet.
If we calculate the distance once more...
...you guessed it. It's also two.
The distances between both pairs are identical.
If we saw these three men standing side by side, would you really believe that observation one is just as similar to three as it is to two?
Of course not.
Then why are their distances the same?
This happens because these features are on different scales. Meaning they have different averages and different expected variability.
While in these comparisons these features only vary by a magnitude of two, we intuitively know that
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from DataCamp · DataCamp · 32 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
▶
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
SQL Server Tutorial: Date manipulation
DataCamp
R Tutorial: Intermediate Interactive Data Visualization with plotly in R
DataCamp
R Tutorial: Adding aesthetics to represent a variable
DataCamp
R Tutorial: Moving Beyond Simple Interactivity
DataCamp
Python Tutorial: Why use ML for marketing? Strategies and use cases
DataCamp
Python Tutorial: Preparation for modeling
DataCamp
Python Tutorial: Machine Learning modeling steps
DataCamp
R Tutorial: The prior model
DataCamp
R Tutorial: Data & the likelihood
DataCamp
R Tutorial: The posterior model
DataCamp
R Tutorial: An Introduction to plotly
DataCamp
R Tutorial: Plotting a single variable
DataCamp
R Tutorial: Bivariate graphics
DataCamp
Python Tutorial: Customer Segmentation in Python
DataCamp
Python Tutorial: Time cohorts
DataCamp
Python Tutorial: Calculate cohort metrics
DataCamp
Python Tutorial: Cohort analysis visualization
DataCamp
R Tutorial: Building Dashboards with flexdashboard
DataCamp
R Tutorial: Anatomy of a flexdashboard
DataCamp
R Tutorial: Layout basics
DataCamp
R Tutorial: Advanced layouts
DataCamp
Python Tutorial: Time Series Analysis in Python
DataCamp
Python Tutorial: Correlation of Two Time Series
DataCamp
Python Tutorial: Simple Linear Regressions
DataCamp
Python Tutorial: Autocorrelation
DataCamp
R Tutorial: The gapminder dataset
DataCamp
R Tutorial: The filter verb
DataCamp
R Tutorial: The arrange verb
DataCamp
R Tutorial: The mutate verb
DataCamp
R Tutorial: What is cluster analysis?
DataCamp
R Tutorial: Distance between two observations
DataCamp
R Tutorial: The importance of scale
DataCamp
R Tutorial: Measuring distance for categorical data
DataCamp
Python Tutorial: Plotting multiple graphs
DataCamp
Python Tutorial: Customizing axes
DataCamp
Python Tutorial: Legends, annotations, & styles
DataCamp
Python Tutorial: Introduction to iterators
DataCamp
Python Tutorial: Playing with iterators
DataCamp
Python Tutorial: Using iterators to load large files into memory
DataCamp
SQL Tutorial: Introduction to Relational Databases in SQL
DataCamp
SQL Tutorial: Tables: At the core of every database
DataCamp
SQL Tutorial: Update your database as the structure changes
DataCamp
Python Tutorial: Classification-Tree Learning
DataCamp
Python Tutorial: Decision-Tree for Classification
DataCamp
Python Tutorial: Decision-Tree for Regression
DataCamp
Python Tutorial: Census Subject Tables
DataCamp
Python Tutorial: Census Geography
DataCamp
Python Tutorial: Using the Census API
DataCamp
R Tutorial: A/B Testing in R
DataCamp
R Tutorial: Baseline Conversion Rates
DataCamp
R Tutorial: Designing an Experiment - Power Analysis
DataCamp
R Tutorial: Introduction to qualitative data
DataCamp
R Tutorial: Understanding your qualitative variables
DataCamp
R Tutorial: Making Better Plots
DataCamp
SQL Tutorial: OLTP and OLAP
DataCamp
SQL Tutorial: Storing data
DataCamp
SQL Tutorial: Database design
DataCamp
Python Tutorial: Introduction to spaCy
DataCamp
Python Tutorial: Statistical Models
DataCamp
Python Tutorial: Rule-based Matching
DataCamp
More on: ML Maths Basics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
The Future of Technical Education: AI, Projects, and Industry Collaboration
Dev.to AI
I Asked Gemini AI to Preview My Haircut Before My Salon Appointment - Here’s What Happened
Medium · AI
Top Five Free AI Tools in the Industry
Medium · ChatGPT
7 Best AI Tools for Research, Coding, and Development in 2026
Medium · Data Science
🎓
Tutor Explanation
DeepCamp AI