Calculator Inputs
Formula Used
Weighted: Dw(A, B) = Σ wi|Ai − Bi|
Normalised: Σ|Ai − Bi| ÷ Σ(|Ai| + |Bi|)
Manhattan distance adds absolute feature differences. It avoids squared differences entirely. Each dimension contributes independently to the final distance score.
How to Use
- Choose vector, dataset, or matrix mode.
- Select a distance variant and scaling method.
- Enter vectors or paste a structured dataset.
- Configure weights, missing values, and KNN settings.
- Submit, inspect details, then export the results.
Example Data
| Example | Vector A | Vector B | Calculation | Distance |
|---|---|---|---|---|
| Basic | [1, 2, 3] | [4, 0, 5] | 3 + 2 + 2 | 7 |
| Identical | [2, 2] | [2, 2] | 0 + 0 | 0 |
| Negative values | [-2, 4] | [3, -1] | 5 + 5 | 10 |
Machine Learning Applications
K-nearest neighbours
Rank training samples by absolute differences. Select the closest observations. Their classes can determine the query prediction reliably.
Clustering
Measure separation without squared penalties. Compare within-cluster and between-cluster distances. Scaled features improve meaningful cluster comparisons across dimensions.
Anomaly detection
Compare new points against reference observations. Large distances can indicate unusual behaviour. Threshold selection still requires validation using representative training data.
Frequently Asked Questions
What is Manhattan distance?
It sums absolute coordinate differences between two points. The metric resembles city-block travel. Movement follows feature axes instead of diagonal shortcuts.
Why scale features first?
Large numeric ranges can dominate the distance. Scaling balances feature influence. Choose parameters learned from training data whenever possible.
How does weighted Manhattan distance work?
Each feature difference receives a non-negative weight. Larger weights increase feature influence. Normalised weights can simplify interpretation across repeated experiments.
Can the calculator perform KNN classification?
Yes, dataset mode ranks every training observation. Top neighbours receive votes. Distance-weighted voting gives closer samples greater predictive influence.
What happens with missing values?
You can reject, ignore, or replace them. Mean replacement uses available feature values. Review warnings before trusting any imputed distance calculation.
Is Manhattan distance always between zero and one?
Standard distance has no fixed upper bound. Normalised distance stays bounded here. Its denominator uses both vectors' total absolute magnitude.
How is Euclidean distance different?
Euclidean distance squares differences before aggregation. Manhattan distance uses absolute differences. Manhattan can be more robust against isolated extremes.
Can categorical columns be included?
Only the selected label column may remain categorical. Feature columns must be numeric. Encode categories numerically before using them as features.
What does the matrix mode provide?
It compares every dataset row with others. The coloured table highlights separation. Labelled data also receives within-class and between-class summaries.