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.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me a real-world example?
Awesome!
Completion rate improved to 4.55
Challenge: Mahalanobis Distance in Practice
Sveip for å vise menyen
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.
Løsning
Takk for tilbakemeldingene dine!
single