示例#1
0
        /// <summary>
        /// Get a list of all users and their ratings on every article
        /// </summary>
        public UserProductRatingsTable GetUserProductRatingsTable(IRater rater)
        {
            UserProductRatingsTable table = new UserProductRatingsTable();

            table.UserIndexToID = db.Users.OrderBy(x => x.Id)
                                  .Select(x => x.Id).Distinct().ToList();
            table.ProductIndexToID = db.Products.OrderBy(x => x.Id)
                                     .Select(x => x.Id).Distinct().ToList();

            foreach (ObjectId userId in table.UserIndexToID)
            {
                table.Users.Add(new UserProductRatings(userId, table.ProductIndexToID.Count));
            }

            var userProductRatingGroup = db.UserActions
                                         .GroupBy(x => new { x.UserID, x.ProductID })
                                         .Select(g => new { g.Key.UserID, g.Key.ProductID, Rating = rater.GetRating(g.ToList()) })
                                         .ToList();

            foreach (var userAction in userProductRatingGroup)
            {
                int userIndex    = table.UserIndexToID.IndexOf(userAction.UserID);
                int productIndex = table.ProductIndexToID.IndexOf(userAction.ProductID);

                table.Users[userIndex].ProductRatings[productIndex] = userAction.Rating;
            }

            return(table);
        }
示例#2
0
        public void Train(UserBehaviorDatabase db)
        {
            UserBehaviorTransformer ubt = new UserBehaviorTransformer(db);

            ratings = ubt.GetUserProductRatingsTable(rater);

            List <ProductCategoryCount> productCategories = ubt.GetProductCategoryCounts();

            ratings.AppendProductFeatures(productCategories);

            FillTransposedRatings();
        }
示例#3
0
        public void Train(UserBehaviorDatabase db)
        {
            UserBehaviorTransformer ubt = new UserBehaviorTransformer(db);

            ratings = ubt.GetUserProductRatingsTable(rater);
        }