[scikit-learn] NearestNeighbors without replacement

Jacob Vanderplas jakevdp at cs.washington.edu
Sun Apr 1 22:13:01 EDT 2018


On Sun, Apr 1, 2018 at 6:36 PM, Randy Ellis <randalljellis at gmail.com> wrote:

> Hello to the Scikit-learn community!
>
> I am doing case-control matching for an electronic health records study.
> My question is, is it possible to run Sklearn's NearestNeighbors function
> without replacement? As in, match the treated group to the untreated group
> without re-using any of the untreated group data points? If so, how? By
> default, it uses replacement. I know this because I tested it on some data
> of mine.
>
> The code I used is in the confirmed answer here:
> https://stats.stackexchange.com/questions/206832/matched-
> pairs-in-python-propensity-score-matching
>
> Thanks so much in advance,
>

No, pairwise matching without replacement is not implemented within
scikit-learn's nearest neighbors routines.

It seems like an algorithm you would have to think carefully about because
the number of potential pairs grows exponentially with the number of
points, and I don't think it's true that choosing the nearest available
neighbor of points in sequence will guarantee you to find the optimal
configuration. You'd also have to carefully define what you mean by
"optimal"... are you seeking to minimize the sum of all distances? The sum
of squared distances? The maximum distance? The results would change
depending on the metric you define. And you'd probably have to figure out
some way to reduce the exponential search space in order to calculate the
result in a reasonable amount of time for your data.

You might look into the literature on propensity score matching; I think
that's one area where this kind of neighbors-without-replacement algorithm
is often used.

Best,
   Jake


>
> --
> *Randall J. Ellis, B.S.*
> PhD Student, Biomedical Science, Mount Sinai
> Special Volunteer, http://www.michaelideslab.org/, NIDA IRP
> Cell: (954)-260-9891 <(954)%20260-9891>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-learn/attachments/20180401/2c27717e/attachment.html>


More information about the scikit-learn mailing list