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.
Ratkaisu
Kiitos palautteestasi!
single
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Awesome!
Completion rate improved to 4.55
Challenge: Mahalanobis Distance in Practice
Pyyhkäise näyttääksesi valikon
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.
Ratkaisu
Kiitos palautteestasi!
single