Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

MAINT: mutual information using upstream KDTree #31347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
Loading
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions 13 sklearn/feature_selection/_mutual_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

import numpy as np
from scipy.sparse import issparse
from scipy.spatial import KDTree
from scipy.special import digamma

from ..metrics.cluster import mutual_info_score
from ..neighbors import KDTree, NearestNeighbors
from ..neighbors import NearestNeighbors
from ..preprocessing import scale
from ..utils import check_random_state
from ..utils._param_validation import Interval, StrOptions, validate_params
Expand Down Expand Up @@ -62,12 +63,12 @@ def _compute_mi_cc(x, y, n_neighbors):

# KDTree is explicitly fit to allow for the querying of number of
# neighbors within a specified radius
kd = KDTree(x, metric="chebyshev")
nx = kd.query_radius(x, radius, count_only=True, return_distance=False)
kd = KDTree(x)
nx = kd.query_ball_point(x, radius, p=np.inf, return_length=True)
nx = np.array(nx) - 1.0

kd = KDTree(y, metric="chebyshev")
ny = kd.query_radius(y, radius, count_only=True, return_distance=False)
kd = KDTree(y)
ny = kd.query_ball_point(y, radius, p=np.inf, return_length=True)
ny = np.array(ny) - 1.0

mi = (
Expand Down Expand Up @@ -140,7 +141,7 @@ def _compute_mi_cd(c, d, n_neighbors):
radius = radius[mask]

kd = KDTree(c)
m_all = kd.query_radius(c, radius, count_only=True, return_distance=False)
m_all = kd.query_ball_point(c, radius, return_length=True)
m_all = np.array(m_all)

mi = (
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.