Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fit(self, weighted, show_progress=True):
""" Computes and stores the similarity matrix """
self.similarity = all_pairs_knn(weighted, self.K,
show_progress=show_progress,
num_threads=self.num_threads).tocsr()
self.scorer = NearestNeighboursScorer(self.similarity)
def __setstate__(self, state):
self.__dict__.update(state)
if self.similarity is not None:
self.scorer = NearestNeighboursScorer(self.similarity)
else:
self.scorer = None
def load(cls, filename):
# numpy.save automatically appends a npz suffic, numpy.load doesn't apparently
if not filename.endswith(".npz"):
filename = filename + ".npz"
m = numpy.load(filename)
similarity = csr_matrix((m['data'], m['indices'], m['indptr']), shape=m['shape'])
ret = cls()
ret.similarity = similarity
ret.scorer = NearestNeighboursScorer(similarity)
ret.K = m['K']
return ret