private MyRecommender() { UserMapping = new EntityMapping(); ItemMapping = new EntityMapping(); // load the data var data = RatingData.Read("../mymedialite/data/ml-100k/u.data", UserMapping, ItemMapping); // set up the recommender recommender = (IncrementalRatingPredictor) Model.Load("bmf.model"); recommender.Ratings = data; }
private void CreateRecommender() { BiasedMatrixFactorization recommender = new BiasedMatrixFactorization(); Console.Error.Write("Reading in ratings ... "); TimeSpan time = Wrap.MeasureTime(delegate() { recommender.Ratings = RatingData.Read(ratings_file, user_mapping, item_mapping); }); Console.Error.WriteLine("done ({0,0:0.##}).", time.TotalSeconds.ToString(CultureInfo.InvariantCulture)); //Console.Error.Write("Reading in additional ratings ... "); //string[] rating_files = Directory.GetFiles("../../saved_data/", "user-ratings-*"); //Console.Error.WriteLine("done."); foreach (var indices_for_item in recommender.Ratings.ByItem) if (indices_for_item.Count > 0) movies_by_frequency.Add(new Tuple<int, float>(recommender.Ratings.Items[indices_for_item[0]], indices_for_item.Count)); movies_by_frequency = movies_by_frequency.OrderByDescending(x => x.Item2).ToList(); for (int i = 0; i < n_movies; i++) top_n_movies.Add( movies_by_frequency[i].Item1 ); Console.Error.Write("Loading prediction model ... "); recommender.UpdateUsers = true; recommender.UpdateItems = false; recommender.BiasReg = 0.001f; recommender.Regularization = 0.045f; recommender.NumIter = 60; time = Wrap.MeasureTime(delegate() { recommender.LoadModel(model_file); }); Console.Error.WriteLine("done ({0,0:0.##}).", time.TotalSeconds.ToString(CultureInfo.InvariantCulture)); rating_predictor = recommender; current_user_id = user_mapping.ToInternalID(current_user_external_id.ToString()); //rating_predictor.AddUser(current_user_id); // add movies that were not in the training set //rating_predictor.AddItem( item_mapping.InternalIDs.Count - 1 ); PredictAllRatings(); }