Nearest Neighbour Models

Implicit contains several item-item nearest neighbour models. See this post for more information.

CosineRecommender

class implicit.nearest_neighbours.CosineRecommender(K=20, num_threads=0)

Bases: implicit.nearest_neighbours.ItemItemRecommender

An Item-Item Recommender on Cosine distances between items

TFIDFRecommender

class implicit.nearest_neighbours.TFIDFRecommender(K=20, num_threads=0)

Bases: implicit.nearest_neighbours.ItemItemRecommender

An Item-Item Recommender on TF-IDF distances between items

BM25Recommender

class implicit.nearest_neighbours.BM25Recommender(K=20, K1=1.2, B=0.75, num_threads=0)

Bases: implicit.nearest_neighbours.ItemItemRecommender

An Item-Item Recommender on BM25 distance between items

ItemItemRecommender

class implicit.nearest_neighbours.ItemItemRecommender(K=20, num_threads=0)

Bases: implicit.recommender_base.RecommenderBase

Base class for Item-Item Nearest Neighbour recommender models here.

Parameters
  • K (int, optional) – The number of neighbours to include when calculating the item-item similarity matrix

  • num_threads (int, optional) – The number of threads to use for fitting the model. Specifying 0 means to default to the number of cores on the machine.

save(fileobj_or_path)

Saves the model to a file, using the numpy .npz format

Parameters

file (str or io.IOBase) – Either the filename or an open file-like object to save the model to

See also

load, numpy.savez

classmethod load(fileobj_or_path)

Loads the model from a file

Parameters

fileobj_or_path (str or io.IOBase) – Either the filename or an open file-like object to load the model from

Returns

The model loaded up from disk

Return type

RecommenderBase

See also

save, numpy.load