Challenge: Mahalanobis Distance in Practice
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:
[
D(x) = \sqrt{(x - \mu)^T \Sigma^{-1} (x - \mu)}
]
4. Store all distances in an array distances.
5. Classify points as outliers if distance > threshold (use threshold = 2.5).
6. Print both arrays (distances and outliers) for verification.
Use NumPy only.
Soluzione
Grazie per i tuoi commenti!
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Awesome!
Completion rate improved to 4.55
Challenge: Mahalanobis Distance in Practice
Scorri per mostrare il menu
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:
[
D(x) = \sqrt{(x - \mu)^T \Sigma^{-1} (x - \mu)}
]
4. Store all distances in an array distances.
5. Classify points as outliers if distance > threshold (use threshold = 2.5).
6. Print both arrays (distances and outliers) for verification.
Use NumPy only.
Soluzione
Grazie per i tuoi commenti!
single