collaborate_based_algo.py

class ucas_dm.prediction_algorithms.collaborate_based_algo.CollaborateBasedAlgo(sim_func='cosine', user_based=True, k=1)[source]

Bases: ucas_dm.prediction_algorithms.surprise_base_algo.SurpriseBaseAlgo

Collaborative filtering algorithm.

__init__(sim_func='cosine', user_based=True, k=1)[source]
Parameters:
  • sim_func – similarity function: ‘cosine’,’msd’,’pearson’,’pearson_baseline’
  • user_based – True–> user-user filtering strategy;False–> item-item filtering strategy
  • k – The (max) number of neighbors to take into account for aggregation
_init_surprise_model()[source]

Sub-class should implement this method which return a prediction algorithm from package ‘Surprise’.

Returns:A surprise-based recommend model
to_dict()[source]

See BaseAlgo.to_dict for more details.

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