-
-
Couldn't load subscription status.
- Fork 49k
Open
@Nachi2006
Description
Feature description
Description
The current implementation of the K-Nearest Neighbors (KNN) algorithm in machine_learning/k_nearest_neighbors/ uses the Euclidean Distance by default.
To enhance the algorithm's functionality and completeness, this issue proposes adding two additional distance metrics that are commonly used in the KNN algorithm:
- Manhattan Distance (L1 norm)
- Minkowski Distance (Lp norm), which is a generalized form that includes both Euclidean (p=2) and Manhattan (p=1) as special cases.
Proposed changes
- Modify the KNN implementation (
k_nearest_neighbors.pyor similar file) to include a new parameter, perhapsdistance_metric(e.g., set to 'euclidean' by default), that accepts 'manhattan' and 'minkowski' as values. - Implement the calculation for the Manhattan Distance.
- Implement the calculation for the Minkowski Distance, using an additional parameter
pfor the power (e.g., defaulting top=2ifdistance_metricis 'minkowski'). - Add comprehensive unit tests to ensure that the algorithm performs correctly when using these new distance metrics.