Search code examples
python-3.xanaconda3automlpycaret

import issue with pycaret library in juypter notebook in anaconda environment in mac OS


Encountered issue shown in the following section during pycaret library import in locally installed jupyter notebook in Anaconda Navigator 2.5.1 in Mac OS 10.13.6, python 3.8 environment. Error stack was received while importing from pycaret.classification import * and same error will also be encountered with other classes (i.e. from pycaret.classification import * and from pycaret.regression import validate_params) though the installation of pycaret was successful.

Suspecting pycaret library issue, attempt !pip install pycaret --upgrade, !pip uninstall pycaret, and !pip install pycaret but no lock in resolving the issue. Also, tried downgrading to pycaret 2.3.3, as in pycaret version 2.3.3, the prefer_skip_nested_validation argument was made optional. Unfortunately, downgrade couldn't successed due to many dependency failures, it may be because of the version released 27 months back and has had many updates in the dependent packages. Any suggestion resolving the import issue would be appreciated.

> --------------------------------------------------------------------------- TypeError                                 Traceback (most recent call
> last) Cell In[47], line 1
> ----> 1 from pycaret.classification import *
> 
> File
> //anaconda3/lib/python3.8/site-packages/pycaret/classification/__init__.py:1
> ----> 1 from pycaret.classification.functional import (
>       2     add_metric,
>       3     automl,
>       4     blend_models,
>       5     calibrate_model,
>       6     check_drift,
>       7     check_fairness,
>       8     compare_models,
>       9     convert_model,
>      10     create_api,
>      11     create_app,
>      12     create_docker,
>      13     create_model,
>      14     dashboard,
>      15     deploy_model,
>      16     ensemble_model,
>      17     evaluate_model,
>      18     finalize_model,
>      19     get_allowed_engines,
>      20     get_config,
>      21     get_current_experiment,
>      22     get_engine,
>      23     get_leaderboard,
>      24     get_logs,
>      25     get_metrics,
>      26     interpret_model,
>      27     load_experiment,
>      28     load_model,
>      29     models,
>      30     optimize_threshold,
>      31     plot_model,
>      32     predict_model,
>      33     pull,
>      34     remove_metric,
>      35     save_experiment,
>      36     save_model,
>      37     set_config,
>      38     set_current_experiment,
>      39     setup,
>      40     stack_models,
>      41     tune_model,
>      42 )
>      43 from pycaret.classification.oop import ClassificationExperiment
>      45 __all__ = [
>      46     "ClassificationExperiment",
>      47     "setup",    (...)
>      86     "check_drift",
>      87 ]
> 
> File
> //anaconda3/lib/python3.8/site-packages/pycaret/classification/functional.py:8
>       5 import pandas as pd
>       6 from joblib.memory import Memory
> ----> 8 from pycaret.classification.oop import ClassificationExperiment
>       9 from pycaret.internal.parallel.parallel_backend import ParallelBackend
>      10 from pycaret.loggers.base_logger import BaseLogger
> 
> File
> //anaconda3/lib/python3.8/site-packages/pycaret/classification/oop.py:16
>      13 from joblib.memory import Memory
>      14 from scipy.optimize import shgo
> ---> 16 from pycaret.containers.metrics.classification import get_all_metric_containers
>      17 from pycaret.containers.models.classification import (
>      18     ALL_ALLOWED_ENGINES,
>      19     get_all_model_containers,
>      20     get_container_default_engines,
>      21 )
>      22 from pycaret.internal.display import CommonDisplay
> 
> File
> //anaconda3/lib/python3.8/site-packages/pycaret/containers/metrics/classification.py:13
>       1 # Module: containers.metrics.classification
>       2 # Author: Antoni Baum (Yard1) <[email protected]>
>       3 # License: MIT    (...)
>       8 # `ClassificationMetricContainer` as a base, set all of the required parameters in the `__init__` and then call `super().__init__`
>       9 # to complete the process. Refer to the existing classes for examples.
>      11 from typing import Any, Dict, Optional, Union
> ---> 13 from sklearn import metrics
>      14 from sklearn.metrics._scorer import _BaseScorer
>      16 import pycaret.containers.base_container
> 
> File
> //anaconda3/lib/python3.8/site-packages/sklearn/metrics/__init__.py:20
>      17 from ._ranking import roc_curve
>      18 from ._ranking import top_k_accuracy_score
> ---> 20 from ._classification import accuracy_score
>      21 from ._classification import balanced_accuracy_score
>      22 from ._classification import class_likelihood_ratios
> 
> File
> //anaconda3/lib/python3.8/site-packages/sklearn/metrics/_classification.py:146
>     142     else:
>     143         return sample_score.sum()
> --> 146 @validate_params(
>     147     {
>     148         "y_true": ["array-like", "sparse matrix"],
>     149         "y_pred": ["array-like", "sparse matrix"],
>     150         "normalize": ["boolean"],
>     151         "sample_weight": ["array-like", None],
>     152     }
>     153 )
>     154 def accuracy_score(y_true, y_pred, *, normalize=True, sample_weight=None):
>     155     """Accuracy classification score.
>     156 
>     157     In multilabel classification, this function computes subset accuracy:    (...)
>     217     0.5
>     218     """
>     220     # Compute accuracy for each possible representation
> 
> TypeError: validate_params() missing 1 required keyword-only argument:
> 'prefer_skip_nested_validation'

Solution

  • I faced the same issue and referred to a post, and I was trying this in Jupyter Notebook in Conda environment. !pip install --pre pycaret It successfully install package but while I am importing package it was giving error : enter image description here

    ModuleNotFoundError: No module named 'pycaret'
    

    The same package it successfully installed and run fine in Google colab as below.

    enter image description here

    It clearly indicates that the environment where we are installing and trying to run in Pycarate having some issues. I could not find any way to fix that.

    But I found some workaround like below. Please execute command I hope it will help.

    1. conda info --envs. It will list the available env in your python.
    2. conda activate <Select_one_Env> Select_one_Env is the potential sample env name that is going to be selected. You select the best env for your use case.

    I believe you are already doing the above 2 steps. The following steps will bypass the Jupyter Notebook and try to work with ipython .

    ipython Is similar to Jupyter Notebook but is in a shell or console terminal.

    Once the target env is selected use the following command.

    • ipython run this shell command to start iPython shell.
    • After ipython shell starts you can run the same pip install command like !pip install --pre pycaret It will install the pycrate package. After the package is successfully installed run the following command.

    enter image description here

    • from pycaret.classification import * You can import
    • enter image description here

    Now you will be able to run pycrate package in ipython shell.

    Hope, It will help to solve the issue.