joaopfonseca / ml-research

A Python library with utilities for Machine Learning research and algorithm implementations
MIT License
6 stars 2 forks source link

Error when importing ``set_matplotlib_style`` #60

Closed joaopfonseca closed 1 month ago

joaopfonseca commented 11 months ago

Describe the bug

Cannot import mlresearch.utils.set_matplotlib_style.

Steps/Code to Reproduce

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt, os
from mlresearch.utils import set_matplotlib_style
import warnings
warnings.filterwarnings("ignore")

set_matplotlib_style()
%config InlineBackend.figure_format = 'retina' 

Expected Results

No error is thrown (i.e., no output)

Actual Results

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Input In [2], in <cell line: 8>()
      6 import numpy as np
      7 import matplotlib.pyplot as plt, os
----> 8 from mlresearch.utils import set_matplotlib_style
      9 import warnings
     10 warnings.filterwarnings("ignore")

File ~/opt/anaconda3/lib/python3.9/site-packages/mlresearch/_init_.py:45, in <module>
     41     sys.stderr.write("Partial import of imblearn during the build process.\n")
     42     # We are not importing the rest of scikit-learn during the build
     43     # process, as it may not be compiled yet
     44 else:
---> 45     from . import active_learning
     46     from . import data_augmentation
     47     from . import datasets

File ~/opt/anaconda3/lib/python3.9/site-packages/mlresearch/active_learning/_init_.py:4, in <module>
      1 """
      2 Module which contains Active Learning implementations.
      3 """
----> 4 from ._active_learning import StandardAL, AugmentationAL
      5 from ._acquisition_functions import ACQUISITION_FUNCTIONS
      7 _all_ = ["StandardAL", "AugmentationAL", "ACQUISITION_FUNCTIONS"]

File ~/opt/anaconda3/lib/python3.9/site-packages/mlresearch/active_learning/_active_learning.py:5, in <module>
      3 import numpy as np
      4 from sklearn.base import ClassifierMixin, BaseEstimator, clone
----> 5 from sklearn.model_selection import GridSearchCV
      6 from imblearn.pipeline import Pipeline
      7 from imblearn.over_sampling.base import BaseOverSampler

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/model_selection/_init_.py:23, in <module>
     20 from ._split import train_test_split
     21 from ._split import check_cv
---> 23 from ._validation import cross_val_score
     24 from ._validation import cross_val_predict
     25 from ._validation import cross_validate

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/model_selection/_validation.py:32, in <module>
     30 from ..utils.fixes import delayed
     31 from ..utils.metaestimators import _safe_split
---> 32 from ..metrics import check_scoring
     33 from ..metrics._scorer import _check_multimetric_scoring, _MultimetricScorer
     34 from ..exceptions import FitFailedWarning

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/_init_.py:41, in <module>
     37 from ._classification import multilabel_confusion_matrix
     39 from ._dist_metrics import DistanceMetric
---> 41 from . import cluster
     42 from .cluster import adjusted_mutual_info_score
     43 from .cluster import adjusted_rand_score

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/cluster/_init_.py:22, in <module>
     20 from ._supervised import fowlkes_mallows_score
     21 from ._supervised import entropy
---> 22 from ._unsupervised import silhouette_samples
     23 from ._unsupervised import silhouette_score
     24 from ._unsupervised import calinski_harabasz_score

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/cluster/_unsupervised.py:16, in <module>
     14 from ...utils import check_X_y
     15 from ...utils import _safe_indexing
---> 16 from ..pairwise import pairwise_distances_chunked
     17 from ..pairwise import pairwise_distances
     18 from ...preprocessing import LabelEncoder

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/pairwise.py:33, in <module>
     30 from ..utils.fixes import delayed
     31 from ..utils.fixes import sp_version, parse_version
---> 33 from ._pairwise_distances_reduction import PairwiseDistancesArgKmin
     34 from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
     35 from ..exceptions import DataConversionWarning

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/pairwise_distances_reduction/init_.py:89, in <module>
      1 # Pairwise Distances Reductions
      2 # =============================
      3 #
   (...)
     85 #    using Generalized Matrix Multiplication over `float64` data (see the
     86 #    docstring of :class:`GEMMTermComputer64` for details).
---> 89 from ._dispatcher import (
     90     ArgKmin,
     91     ArgKminClassMode,
     92     BaseDistancesReductionDispatcher,
     93     RadiusNeighbors,
     94     sqeuclidean_row_norms,
     95 )
     97 _all_ = [
     98     "BaseDistancesReductionDispatcher",
     99     "ArgKmin",
   (...)
    102     "sqeuclidean_row_norms",
    103 ]

File ~/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/_pairwise_distances_reduction/_dispatcher.py:8, in <module>
      5 from scipy.sparse import issparse
      7 from ... import get_config
----> 8 from .._dist_metrics import BOOL_METRICS, METRIC_MAPPING64
      9 from ._argkmin import (
     10     ArgKmin32,
     11     ArgKmin64,
     12 )
     13 from ._argkmin_classmode import (
     14     ArgKminClassMode32,
     15     ArgKminClassMode64,
     16 )

ImportError: cannot import name 'METRIC_MAPPING64' from 'sklearn.metrics._dist_metrics' (/Users/josefonseca/opt/anaconda3/lib/python3.9/site-packages/sklearn/metrics/_dist_metrics.cpython-39-darwin.so)

Versions

System:
    python: 3.9.12 (main, Apr  5 2022, 01:53:17)  [Clang 12.0.0 ]
executable: /Users/josefonseca/opt/anaconda3/bin/python
   machine: macOS-10.16-x86_64-i386-64bit

Python dependencies:
      sklearn: 1.1.1
          pip: 21.2.4
   setuptools: 61.2.0
        numpy: 1.21.5
        scipy: 1.7.3
       Cython: 0.29.28
       pandas: 1.4.2
   matplotlib: 3.8.0
       joblib: 1.2.0
threadpoolctl: 2.2.0

Built with OpenMP: True

threadpoolctl info:
       filepath: /Users/josefonseca/opt/anaconda3/lib/libmkl_rt.1.dylib
         prefix: libmkl_rt
       user_api: blas
   internal_api: mkl
        version: 2021.4-Product
    num_threads: 10
threading_layer: intel

       filepath: /Users/josefonseca/opt/anaconda3/lib/libomp.dylib
         prefix: libomp
       user_api: openmp
   internal_api: openmp
        version: None
    num_threads: 10
joaopfonseca commented 1 month ago

Cannot replicate bug