Exemple #1
0
    def save(self, path):
        """
        Save a model.

        The model can be saved, then reloaded later to provide recommendations.

        Parameters
        ----------
        path : str
            The path where the model will be saved.
            This should refer to a file, not to a directory.
            Three items will be stored here: the underlying model parameters, the original ratings,
            and the column names.  These are stored with suffix '.model', '.ratings', and
            '.metadata'.
        """
        sc = CommonSparkContext.Instance().sc
        delete_file_or_dir(path)
        os.makedirs(path)
        model_path, metadata_path = self._file_paths(path)
        # save model
        self.model.save(sc, model_path)
        # save metadata
        model_type = self.__class__.__name__
        metadata = [model_type, self.feature_cols]
        with fileio.open_file(metadata_path, 'w') as f:
            # TODO detect filesystem errors
            pickle.dump(metadata, f)
    def save(self, path):
        """
        Save a model.

        The model can be saved, then reloaded later to provide recommendations.

        Parameters
        ----------
        path : str
            The path where the model will be saved.
            This should refer to a file, not to a directory.
            Three items will be stored here: the underlying model parameters, the original ratings,
            and the column names.  These are stored with suffix '.model', '.ratings', and
            '.metadata'.
        """
        sc = CommonSparkContext.Instance().sc()
        delete_file_or_dir(path)
        os.makedirs(path)
        model_path, ratings_path, metadata_path = self._file_paths(path)
        # save model
        self.model.save(sc, model_path)
        # save ratings
        self.ratings.save(ratings_path)
        # save metadata
        metadata = [self.user_col, self.item_col, self.rating_col]
        with fileio.open_file(metadata_path, 'w') as f:
            # TODO detect filesystem errors
            pickle.dump(metadata, f)
Exemple #3
0
def delete(uri):
    """ Delete a file or directory. """
    parsed_uri = _parse_uri(uri)
    if parsed_uri.scheme == 'file':
        from xframes.util import delete_file_or_dir
        delete_file_or_dir(parsed_uri.path)
    elif parsed_uri.scheme == 'hdfs':
        hdfs_connection = _make_hdfs_connection(parsed_uri)
        hdfs_connection.delete(parsed_uri.path, recursive=True)
    elif parsed_uri.scheme == 'hive':
        pass
    else:
        raise UriError('Invalid URI scheme: {}'.format(parsed_uri.scheme))
Exemple #4
0
def delete(uri):
    """ Delete a file or directory. """
    parsed_uri = _parse_uri(uri)
    if parsed_uri.scheme == 'file':
        from xframes.util import delete_file_or_dir
        delete_file_or_dir(parsed_uri.path)
    elif parsed_uri.scheme == 'hdfs':
        hdfs_connection = _make_hdfs_connection(parsed_uri)
        hdfs_connection.delete(parsed_uri.path, recursive=True)
    elif parsed_uri.scheme == 'hive':
        pass
    else:
        raise UriError('Invalid URI scheme: {}'.format(parsed_uri.scheme))