Skip to content

[BUG] Upcoming changes to scipy.stats.mode in 1.11 #937

Closed
@hayesall

Description

@hayesall

Describe the bug

scipy.stats.mode adds a FutureWarning in 1.9 for an upcoming API change:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.mode.html

Steps/Code to Reproduce

from collections import Counter
import numpy as np
from imblearn.over_sampling import SMOTEN

X = np.array(["A"] * 10 + ["B"] * 20 + ["C"] * 30, dtype=object).reshape(-1, 1)
y = np.array([0] * 20 + [1] * 40, dtype=np.int32)

sampler = SMOTEN(random_state=0)
X_res, y_res = sampler.fit_resample(X, y)

print(f"Class counts after resampling {Counter(y_res)}")

Actual Results

/home/hayesall/imbalanced-learn/imblearn/over_sampling/_smote/base.py:789: FutureWarning: Unlike other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode` typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of `keepdims` will become False, the `axis` over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set `keepdims` to True or False to avoid this warning.
  stats.mode(X_class[nn_indices[samples_indices]], axis=1).mode, axis=1

Versions

System, Dependency Information

System Information

  • python : 3.8.13 (default, Oct 21 2022, 23:50:54) [GCC 11.2.0]
  • executable: /home/hayesall/miniconda3/envs/imblearn/bin/python
  • machine : Linux-5.10.142-19739-g5899aa8f604c-x86_64-with-glibc2.17

Python Dependencies

  • pip : 22.2.2
  • setuptools: 65.5.0
  • imblearn : 0.10.0.dev0
  • sklearn : 1.1.3
  • numpy : 1.23.4
  • scipy : 1.9.3
  • Cython : None
  • pandas : None
  • keras : None
  • tensorflow: None
  • joblib : 1.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions