def _setup_memory(self):
        """Setup Memory object for memory caching.
        """
        if self.memory:
            if isinstance(self.memory, str):
                if self.memory == "auto":
                    # Create a temporary folder to store the transformers of the pipeline
                    self._cachedir = mkdtemp()
                else:
                    if not os.path.isdir(self.memory):
                        try:
                            os.makedirs(self.memory)
                        except:
                            raise ValueError(
                                'Could not create directory for memory caching: {}'.format(self.memory)
                            )
                    self._cachedir = self.memory

                self._memory = Memory(cachedir=self._cachedir, verbose=0)
            elif isinstance(self.memory, Memory):
                self._memory = self.memory
            else:
                raise ValueError(
                    'Could not recognize Memory object for pipeline caching. '
                    'Please provide an instance of sklearn.external.joblib.Memory,'
                    ' a path to a directory on your system, or \"auto\".'
                )
Setup Memory object for memory caching.