[Python Problem Note 1] The parameter change of the joblib package memory module causes an error to be reported when using mglearn

foreword

In the process of learning machine learning algorithms, I used a package called mglearn, which can be used to beautify drawings

question

When running the program, the program crashes, the following is the Traceback information

Traceback (most recent call last):
  File "example1_flower.py", line 6, in <module>
    import mglearn
  File "D:\软件\python\lib\site-packages\mglearn\__init__.py", line 1, in <module>
    from . import plots
  File "D:\软件\python\lib\site-packages\mglearn\plots.py", line 14, in <module>
    from .plot_pca import plot_pca_illustration, plot_pca_whitening, plot_pca_faces
  File "D:\软件\python\lib\site-packages\mglearn\plot_pca.py", line 7, in <module>
    memory = Memory(cachedir="cache")
TypeError: __init__() got an unexpected keyword argument 'cachedir'

positioning problem

In the plot_pca.py file, the memory class in the joblib package is called and instantiated. I found the source code of this class and found the problem. (Some content has been deleted to save space)

class Memory(Logger):
    """ 
        Parameters
        ----------
        location: str, pathlib.Path or None
            The path of the base directory to use as a data store
            or None. If None is given, no caching is done and
            the Memory object is completely transparent. This option
            replaces cachedir since version 0.12.
    """
    # ------------------------------------------------------------------------
    # Public interface
    # ------------------------------------------------------------------------

    def __init__(self, location=None, backend='local',
                 mmap_mode=None, compress=False, verbose=1, bytes_limit=None,
                 backend_options=None):

It can be found that the parameter cachedir does not appear in the class, and then carefully check the comments:

This option replaces cachedir since version 0.12.

Originally this parameter has been deprecated, the parameter location should be used now.

solution

memory = Memory(cachedir="cache")Change the files plot_pca.py and plot_nmf.py tomemory = Memory(location="cache")

summary

It is very important to develop the habit of reading source code!

Guess you like

Origin blog.csdn.net/m0_46500149/article/details/126919469