I want to apply k nearest neighbour with a custom distance function. I have not found a way to pass this function using packages like FNN or class. Is there a way to pass a function or distance matrix to an existing knn algorithm in some R package or do I have to write it from scratch?
Background
To elaborate on my problem: my data includes columns for
- start latitude
- start longitude
- start country
- end latitude
- end longitude
- end country
- start+end country
- means of transportation
- distance
- price
and I want to estimate the price based on the other factors. The distance function needs to include the haversine distance to measure the similarity of start and end points' latitude and longitude, so I cannot use a built-in distance like euclidean or minkowski.
Open for Python suggestions
If somebody believes that for some reason this would be much easier to do in Python (provided the same programming skills in both languages) using some fancy package, I am also very open to additional information about this.