Repository navigation
ENH Paired haversine - #22705
ENH Paired haversine#22705jona-sassenhagen wants to merge 41 commits into
Conversation
…hagen/scikit-learn into jona/paired_haversine_take_2
|
@jnothman would you have time to review? |
There was a problem hiding this comment.
Thanks @jona-sassenhagen for your work.
I would like to see tested the error about the dimensions.
| if not (len(X.shape) == len(Y.shape) == 2) or not (X.shape[1] == Y.shape[1] == 2): | ||
| raise ValueError( | ||
| "For paired distances and the metric `haversine`, " | ||
| "X and Y should both be of shape (n_samples, 2), " | ||
| "but X.shape is {0} and Y.shape is {1}".format(X.shape, Y.shape) | ||
| ) |
There was a problem hiding this comment.
Do you mind adding a test verifying that the ValueError is raised?
There was a problem hiding this comment.
Sorry, I see now that you added it already... I'd rather have an independent test checking the error message too... but I guess this is not essential...
There was a problem hiding this comment.
@cmarmo Does that mean you're ok with the test as is?
There was a problem hiding this comment.
I find more readable to have a separate test. But I think it is better to have another opinion, just to avoid double back and forth.
I'm labeling this one as "Waiting for review": let's hope someone will jump in quickly... :)
|
ping @jnothman |
|
@agramfort maybe you can take a look? |
agramfort
left a comment
There was a problem hiding this comment.
@jona-sassenhagen I am mostly concerned about the organization of the tests
| Y = np.tile(X[0, :], (5, 1)) | ||
| S = haversine_distances(X, Y[0].reshape(1, -1)).ravel() | ||
| S2 = paired_haversine_distances(X, Y).ravel() | ||
| assert_array_almost_equal(S, S2) |
There was a problem hiding this comment.
This test should test the function pairwise_distances with parameter haversine
There was a problem hiding this comment.
You see that no paired_xxx function are tested in this test function. What I would suggest is that you don’t pop the haversine function from the global but amend the test so that you only have 2 features if haversine is used. You could for example just take the first two columns so haversine is tested like all others.
There was a problem hiding this comment.
D'uh. That's an obvious mistake.
There was a problem hiding this comment.
If I don't pop it, I get a bunch of errors like this:
test_agglomerative_clustering
ValueError: For paired distances and the metric `haversine`, X and Y should both be of shape (n_samples, 2), but X.shape is (9900, 50) and Y.shape is (9900, 50)
from places like this
for metric in PAIRED_DISTANCES.keys():
# Compare our (structured) implementation to scipy
clustering = AgglomerativeClustering(
n_clusters=10,
connectivity=np.ones((n_samples, n_samples)),
metric=metric,
linkage="complete",
)
Should I manually exempt all of them? I.e.,
for metric in PAIRED_DISTANCES.keys():
if metric == 'paired_haversine':
continue
# Compare our (structured) implementation to scipy
clustering = AgglomerativeClustering(
n_clusters=10,
connectivity=np.ones((n_samples, n_samples)),
metric=metric,
linkage="complete",
)
|
Hi @jona-sassenhagen are you interested in finalizing this pull request? Thanks for your work so far. |
|
Hi @cmarmo - yeah sorry, got distracted. I will finish it. |
|
I'm getting this test failure: I'm not sure how to resolve it. Should I just coerce to |
A couple things going on in this PR:
The point here is that we don't know if we want to keep on maintaining public In fact, it is relatively easy to construction your own And even if we do choose to continue maintaining At the end of the day, the questions are:
I am -0 on the first, and -1 on the second. |
I think we must since users are using it.
I think we better remove them and point users to |
In that case, do we want to potentially opt for a generic function which leverages |
|
I don't feel qualified to speak to the larger question of how the pairwise/paired API should look like. But wouldn't it be orthogonal to that to add the function in this PR as private? And continue the discussion of how to continue with paired elsewhere? |
Potentially if we get the exact same results numerically and if there are no performance regression. To me, this decision goes beyond the scope of this PR; what do you think of discussing the implementation of |
Yes, I think that is at least fine 👍
I will create an issue for it on Monday, but if anyone else prefers to do so before then, feel free. |
|
@jona-sassenhagen: I would proceed as you propose. 👍 |
…hagen/scikit-learn into jona/paired_haversine_take_2
|
Thank you for your work! Can't wait for it to merge |
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
|
Thx everyone, I accepted the docstring suggestions, please merge when green. |
…hagen/scikit-learn into jona/paired_haversine_take_2
|
@cmarmo I think you're a member now, could you approve and merge? |
adrinjalali
left a comment
There was a problem hiding this comment.
Since in a discussion we had in our drafting meeting, we were not sure if this should be included or weather paired_distances should be deprecated altogether, I'm putting a "request changes" here to mark that for now.
|
Hi @adrinjalali , I think this was discussed and resolved above? E.g. around here #22705 (comment) |
|
I don't see any resolution in the discussion. I'm proposing |
|
@adrinjalali @jjerphan Do we have an idea of how widely both @adrinjalali Would your opinion changed if we could make it a generic and thin wrapper around using |
|
At this time there is no change to the API from this PR and I thought discussion of the API should happen in a separate and dedicated issue? |
|
Would the wrapper be anything other than |
Closes #17212
There is a PR in #17258 , but it has grown stale.
(I also realised there was an issue in the original implementation, in that the existing haversine expects the input to be in radians.)
WIP because I cannot build sklearn to test locally right now.