from lightfm.datasets import fetch_movielens from lightfm import LightFM # Fetch the movie lens dataset data = fetch_movielens(min_rating=4.0) # Create the model model = LightFM(loss='warp') # Train the model model.fit(data['train'], epochs=30, num_threads=2) # Evaluate the model train_precision = precision_at_k(model, data['train'], k=10).mean() test_precision = precision_at_k(model, data['test'], k=10).mean() print('Train precision: ', train_precision) print('Test precision: ', test_precision)In this code example, we use LightFM to train a recommendation model on the MovieLens dataset. We use the weighted approximate-rank pairwise (WARP) loss for matrix factorization. We then evaluate the precision of the model on the training and testing dataset using the precision_at_k metric. LightFM is a package library.