Section 1. Chapter 8
single
Challenge: Mahalanobis Distance in Practice
Swipe to show menu
Task
Swipe to start coding
You are given a small 2D dataset. Your goal is to compute the Mahalanobis distance of each observation from the data center and use it to detect outliers.
Steps:
- Compute the mean vector of the dataset.
- Compute the covariance matrix and its inverse.
- For each observation, compute Mahalanobis distance using the formula:
- Store all distances in an array
distances. - Classify points as outliers if
distance > threshold(usethreshold = 2.5). - Print both arrays (
distancesandoutliers) for verification.
Use NumPy only.
Solution
Everything was clear?
Thanks for your feedback!
Section 1. Chapter 8
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat