示例#1
0
    def load(self, path):
        """
        Load method allows Shapash user to use pickled SmartExplainer.
        To use this method you must first declare your SmartExplainer object
        Watch the following example

        Parameters
        ----------
        path : str
            File path of the pickle file.

        Example
        --------
        >>> xpl = SmartExplainer()
        >>> xpl.load('path_to_pkl/xpl.pkl')
        """
        dict_to_load = load_pickle(path)
        if isinstance(dict_to_load, dict):
            for elem in dict_to_load.keys():
                setattr(self, elem, dict_to_load[elem])
            self._case, self._classes = self.check_model()
            self.state = self.choose_state(self.contributions)
        else:
            raise ValueError(
                "pickle file must contain dictionary"
            )
示例#2
0
def load_smartpredictor(path):
    """
    load_smartpredictor allows Shapash users to load SmartPredictor Object already saved into a pickle.

    Parameters
    ----------
    path : str
        File path of the pickle file.

    Example
    --------
    >>> predictor = load_smartpredictor('path_to_pkl/predictor.pkl')
    """
    dict_to_load = load_pickle(path)
    if isinstance(dict_to_load, dict):
        predictor = SmartPredictor(
            features_dict=dict_to_load['features_dict'],
            model=dict_to_load['model'],
            columns_dict=dict_to_load['columns_dict'],
            explainer=dict_to_load['explainer'],
            features_types=dict_to_load['features_types'],
            label_dict=dict_to_load['label_dict'],
            preprocessing=dict_to_load['preprocessing'],
            postprocessing=dict_to_load['postprocessing'])
        return predictor
    else:
        raise ValueError("pickle file must contain dictionary")