In [ ]:
from fastai.collab import * # Quick access to collab filtering functionality
collab
models use data in a DataFrame
of user, items, and ratings.
In [ ]:
path = untar_data(URLs.ML_SAMPLE)
path
Out[ ]:
In [ ]:
ratings = pd.read_csv(path/'ratings.csv')
series2cat(ratings, 'userId', 'movieId')
ratings.head()
Out[ ]:
In [ ]:
data = CollabDataBunch.from_df(ratings, seed=42)
In [ ]:
y_range = [0, 5.5]
That's all we need to create and train a model:
In [ ]:
learn = collab_learner(data, n_factors=50, y_range=y_range)
learn.fit_one_cycle(4, 5e-3)
In [ ]:
learn.predict(ratings.iloc[0])
Out[ ]:
In [ ]: