In [1]:
from tensorglue.engine import RecommenderData
from tensorglue.tools.movielens import get_movielens_data
from tensorglue.tools.printing import print_frames
In [2]:
ml_data, ml_genres = get_movielens_data(get_genres=True)
#if you have local copy of the movielens data you can use
#get_movielens_data(local_file="full_path_to_local_file", get_genres=True)
In [3]:
print_frames((ml_data.head(10), ml_genres.head(10)))
Out[3]:
In [4]:
simple_model = RecommenderData(ml_data, 'userid', 'movieid', 'rating')
In [5]:
simple_model._prepare_data(eval_num=3)
In [6]:
simple_model.train_model('svd')
In [7]:
simple_model.evaluate()
Out[7]:
In [8]:
simple_model.train_model('i2i')
In [9]:
simple_model.evaluate()
Out[9]:
In [8]:
context_model = RecommenderData(ml_data, 'userid', 'movieid', 'rating',
context_data=ml_genres.drop('movienm', 1))
In [9]:
context_model.arrange_by = context_model.fields.values
In [10]:
context_model._prepare_data(eval_num=3)
In [11]:
context_model.train_model('svd')
In [12]:
context_model.evaluate()
Out[12]:
In [13]:
context_model.arrange_by = context_model.fields.contextid
In [14]:
context_model._prepare_data(eval_num=3)
In [15]:
context_model.train_model('tensor')
In [16]:
context_model.evaluate()
Out[16]: