Repository navigation
Conversation
|
Tests are failing because the paired metrics expect data of the shape |
|
@jona-sassenhagen Yes, the paired metrics expect data of shape |
|
Maybe you could check if it is only the unit tests which loop over all paired metrics and just fix it for the unit tests by looping over a new collection |
|
@jona-sassenhagen I'll create a new collection called |
|
@jnothman Please have a look at this PR when you get a chance. Thanks |
|
@jnothman tests are green on this PR— could you review it? |
| a = np.sin(dlat / 2.0) ** 2 + np.cos(lat1) * np.cos(lat2) * \ | ||
| np.sin(dlon / 2.0) ** 2 | ||
| c = 2 * np.arcsin(np.sqrt(a)) | ||
| km = 6367 * c |
There was a problem hiding this comment.
I would maybe explain this magic number
There was a problem hiding this comment.
Ok, I'll add some description
| # Test the pairwise_distance helper function. | ||
| rng = np.random.RandomState(0) | ||
|
|
||
| if metric == "haversine": |
There was a problem hiding this comment.
I think you still need to compare to the pairwise distance implementation, as with other metrics below. It would be clearer, in my opinion, to use the conditional block only to change X and Y. To handle the lack of sparse support, check below that an appropriate error is raised if the sparse case doesn't just work.
There was a problem hiding this comment.
Would you mind giving me an example of how to do that if you have some time?
| # Test paired haversine distance | ||
| # The data should be valid latitude and longitude | ||
|
|
||
| X = rng.random_sample((5, 2)) |
There was a problem hiding this comment.
Please generate data with a more appropriate range for haversine
There was a problem hiding this comment.
Do you mean more data? i.e X = rng.random_sample((20, 2))
Can you give me some examples?
There was a problem hiding this comment.
added new fake data below
There was a problem hiding this comment.
I mean that this input ranges from 0 to 1, unlike haversine input
| assert_array_almost_equal(D, [1., 2.]) | ||
|
|
||
|
|
||
| def test_paired_haversine_distances(): |
There was a problem hiding this comment.
This shouldn't be needed if the above comprise to pairwise_distances
There was a problem hiding this comment.
added new data.
I'll have this remove if you want
There was a problem hiding this comment.
X = np.array([[-34.83333, -58.5166646], [-43.63284, -63.9876712]])
Y = np.array([[49.0083899664, 2.53844117956], [57.23313, 4.993234]])44214ce to
38d68ef
Compare
|
Test failures |
| Parameters | ||
| ---------- | ||
| X : ndarray (n_samples, n_features) | ||
| X : ndarray (n_samples, n_features) or, (n_samples, 2) |
There was a problem hiding this comment.
I don't think this needs changing. For haversine, n_features=2, but that doesn't mean the general case is insufficient
| >>> paired_distances(X, Y) | ||
| array([0., 1.]) | ||
|
|
||
| The haversine metric only accept array of shape (n_samples, 2) |
There was a problem hiding this comment.
| The haversine metric only accept array of shape (n_samples, 2) | |
| The haversine metric only accepts array of shape (n_samples, 2) |
There was a problem hiding this comment.
I'm not sure that another example here was needed
| 'manhattan': paired_manhattan_distances, | ||
| 'cityblock': paired_manhattan_distances} | ||
|
|
||
| PAIRED_DISTANCES_WITHOUT_RESTRICTIONS = { |
There was a problem hiding this comment.
I don't understand why this was introduced in the public API. I understand if haversine needs distinguishing from others in testing, but why here? I also don't understand what "without restrictions" intends, when haversine is restricted to dense and 2 features
|
What's preventing this one from being merged? @acharles7 seems like this shouldn't be too hard? |
|
@acharles7 ping |
|
@jnothman I would be interested in taking over this PR. Should I make a new PR based on this? |
|
Yes that would be fine, @jona-sassenhagen |
|
Closing this one as superseded by #22705. |
Reference Issues/PRs
Added feature to calculate haversine distance between 2 paired arrays with equal dimension as mentioned in #17212
What does this implement/fix? Explain your changes.
Added a new feature in the metrics module to calculate haversine distance b/w 2 arrays
Currently, paired_distances supports the following options:
Now, using this PR, we can calculate haversine distance between two paired arrays of shape
(n_samples, 2),haversine:paired_haversine_distancesin paired_distancesAny other comments?
It seems like this would be a useful distance measure to have in sklearn