'Saves the model as a gzipped pickle file at the given path.
The advantage is that cached vectors and cosine similarity are stored.'

def save(self, path, update=False, final=False):

    if update:
        classes = self.classes
        self.document_frequency('')
        self.inverted_index
        self.vector
        self.posterior_probability('', '')
        self.chi_squared('')
        self.information_gain('')
        for d1 in self.documents:
            for d2 in self.documents:
                self.cosine_similarity(d1, d2)
    if self._classifier:
        p = (path + '.tmp')
        self._classifier.save(p, final)
        self._classifier = open(p, 'rb').read()
        os.remove(p)
    f = gzip.GzipFile(path, 'wb')
    f.write(cPickle.dumps(self, 1))
    f.close()
