On this page, we show how to first set up recommenders in F#, and then use them to make predictions.
To use the examples on this page,
download the MovieLens 100k ratings dataset from the
GroupLens Research website and unzip it.
Of course you can also use your own data ;-)
Rating Prediction
open System open MyMediaLite.IO open MyMediaLite.RatingPrediction open MyMediaLite.Eval (* load the data *) let train_data = RatingData.Read "u1.base" let test_data = RatingData.Read "u1.test" (* set up the recommender *) let recommender = new UserItemBaseline(Ratings=train_data) recommender.Train() (* measure the accuracy on the test data set *) let result = recommender.Evaluate(test_data) Console.WriteLine(result) (* make a prediction for a certain user and item *) let prediction = recommender.Predict(1, 1) Console.WriteLine(prediction)
Item Prediction from Positive-Only Feedback
open System open MyMediaLite.IO open MyMediaLite.ItemRecommendation open MyMediaLite.Eval (* load the data *) let train_data = ItemData.Read "u1.base" let test_data = ItemData.Read "u1.test" (* set up the recommender *) let recommender = new UserKNN(K=20u, Feedback=train_data) recommender.Train() (* measure the accuracy on the test data set *) let result = recommender.Evaluate(test_data, train_data) Console.WriteLine(result) (* make a prediction for a certain user and item *) let prediction = recommender.Predict(1, 1) Console.WriteLine(prediction)