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.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Awesome!
Completion rate improved to 4.55
Challenge: Mahalanobis Distance in Practice
Desliza para mostrar el menú
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.
Solución
¡Gracias por tus comentarios!
single