baseline.py

class ucas_dm.prediction_algorithms.baseline.BaseLineAlgo[source]

Bases: ucas_dm.prediction_algorithms.base_algo.BaseAlgo

A simple recommend algorithm that recommend items in random. Use it as a base-line.

__init__()[source]

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

to_dict()[source]

See BaseAlgo.to_dict for more details.

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