base_algo.py

class ucas_dm.prediction_algorithms.base_algo.BaseAlgo[source]

Bases: object

Do not use this class directly. The interface of all recommend algorithms.

__init__()[source]

Initialize self. See help(type(self)) for accurate signature.

classmethod load(fname)[source]

Load an object previously saved from a file

Parameters:fname – file path
Returns:object loaded from file
save(fname, ignore=None)[source]

Save an object to a file.

Parameters:
  • fname – file path
  • ignore – a set of attributes that should’t be saved by super class, but subclass may have to handle these special attributes.
to_dict()[source]

Convert algorithm model to a dict which contains algorithm’s type and it’s main hyper-parameters.

Returns:A dict contains type and hyper-parameters.
top_k_recommend(u_id, k)[source]

Calculate the top-K recommend items

Parameters:
  • u_id – users’ identity (user’s id)
  • k – the number of the items that the recommender should return
Returns:

(v,id) v is a list contains predict rate or distance, id is a list contains top-k highest rated or nearest items

train(train_set)[source]

Do some train-set-dependent work here: for example calculate sims between users or items

Parameters:train_set – A pandas.DataFrame contains two attributes: user_id and item_id,which represents the user view record during a period of time.
Returns:return a model that is ready to give recommend