public MalPositiveFeedbackRecResults GetRecommendations(MalPositiveFeedbackInput inputForUser, int numRecommendationsToTryToGet)
        {
            IUserInputClassifier <MalUserListEntries> classifier;
            decimal targetScoreUsed;

            if (inputForUser.TargetFraction != null)
            {
                classifier = new MalPercentageRatingClassifier(inputForUser.TargetFraction.Value, m_minEpisodesToClassifyIncomplete);
            }
            else
            {
                classifier = new MalMinimumScoreRatingClassifier(inputForUser.TargetScore.Value, m_minEpisodesToClassifyIncomplete);
            }

            IPositiveFeedbackForUser basicFeedback = inputForUser.AnimeList.AsPositiveFeedback(classifier,
                                                                                               additionalOkToRecommendPredicate: (animeId) => m_userCountByAnime.ContainsKey(animeId) && m_userCountByAnime[animeId] >= m_minUsersToCountAnime);

            if (inputForUser.TargetFraction != null)
            {
                targetScoreUsed = basicFeedback.Items.Min(itemId => inputForUser.AnimeList.Entries[itemId].Rating ?? 10);
            }
            else
            {
                targetScoreUsed = inputForUser.TargetScore.Value;
            }

            IEnumerable <RatingPredictionRecommendation> recs = m_recommender.GetRecommendations(basicFeedback, numRecommendationsToTryToGet);

            return(new MalPositiveFeedbackRecResults(recs, targetScoreUsed));
        }
예제 #2
0
        AnimeRecsResults IRecommendationSource <MalAnimeRecsInput, AnimeRecsResults, AnimeRecsRecommendation>
        .GetRecommendations(MalAnimeRecsInput inputForUser, int numRecommendationsToTryToGet)
        {
            ClassifiedUserInput <MalUserListEntries> classifiedInput;

            if (inputForUser.TargetFraction != null)
            {
                MalPercentageRatingClassifier inputClassifier = new MalPercentageRatingClassifier(inputForUser.TargetFraction.Value, m_minEpisodesToClassifyIncomplete);
                classifiedInput = inputClassifier.Classify(inputForUser.AnimeList);
            }
            else
            {
                MalMinimumScoreRatingClassifier inputClassifier = new MalMinimumScoreRatingClassifier(inputForUser.TargetScore.Value, m_minEpisodesToClassifyIncomplete);
                classifiedInput = inputClassifier.Classify(inputForUser.AnimeList);
            }

            AnimeRecsInput <MalUserListEntries> inputWithParameters = new AnimeRecsInput <MalUserListEntries>(
                originalInput: inputForUser.AnimeList,
                classifiedInput: classifiedInput,
                orderingGivenRecommenderAndItemIds: CompareRecs
                );

            return(m_recommender.GetRecommendations(inputWithParameters, numRecommendationsToTryToGet));
        }
예제 #3
0
        public MalAnimeRecsResults GetRecommendations(MalAnimeRecsInput inputForUser, int numRecommendationsToTryToGet)
        {
            ClassifiedUserInput <MalUserListEntries> classifiedInput;
            decimal targetScoreUsed;

            if (inputForUser.TargetFraction != null)
            {
                MalPercentageRatingClassifier inputClassifier = new MalPercentageRatingClassifier(inputForUser.TargetFraction.Value, m_minEpisodesToClassifyIncomplete);
                classifiedInput = inputClassifier.Classify(inputForUser.AnimeList);

                // target score used is the minimum score a liked anime has.
                targetScoreUsed = classifiedInput.Liked.Entries.Values.Min(entry => entry.Rating) ?? 10m;
            }
            else
            {
                MalMinimumScoreRatingClassifier inputClassifier = new MalMinimumScoreRatingClassifier(inputForUser.TargetScore.Value, m_minEpisodesToClassifyIncomplete);
                classifiedInput = inputClassifier.Classify(inputForUser.AnimeList);
                targetScoreUsed = inputForUser.TargetScore.Value;
            }

            AnimeRecsInput <MalUserListEntries> inputWithParameters = new AnimeRecsInput <MalUserListEntries>(
                originalInput: inputForUser.AnimeList,
                classifiedInput: classifiedInput,
                orderingGivenRecommenderAndItemIds: CompareRecs
                );

            AnimeRecsResults baseResults = m_recommender.GetRecommendations(inputWithParameters, numRecommendationsToTryToGet);

            List <MalAnimeRecsRecommenderUser> malRecommenders = new List <MalAnimeRecsRecommenderUser>();

            foreach (AnimeRecsRecommenderUser baseRecommender in baseResults.Recommenders)
            {
                malRecommenders.Add(new MalAnimeRecsRecommenderUser(
                                        userId: baseRecommender.UserId,
                                        username: m_trainingData.Users[baseRecommender.UserId].MalUsername,
                                        recsLiked: new HashSet <MalAnimeRecsRecommenderRecommendation>(baseRecommender.RecsLiked
                                                                                                       .Select(malAnimeId => new MalAnimeRecsRecommenderRecommendation(malAnimeId,
                                                                                                                                                                       m_trainingData.Users[baseRecommender.UserId].Entries[malAnimeId].Rating, m_itemAverages[malAnimeId])
                                                                                                               )
                                                                                                       ),
                                        recsNotLiked: new HashSet <MalAnimeRecsRecommenderRecommendation>(baseRecommender.RecsNotLiked
                                                                                                          .Select(malAnimeId => new MalAnimeRecsRecommenderRecommendation(malAnimeId,
                                                                                                                                                                          m_trainingData.Users[baseRecommender.UserId].Entries[malAnimeId].Rating, m_itemAverages[malAnimeId])
                                                                                                                  )
                                                                                                          ),
                                        recsInconclusive: new HashSet <MalAnimeRecsRecommenderRecommendation>(baseRecommender.RecsInconclusive
                                                                                                              .Select(malAnimeId => new MalAnimeRecsRecommenderRecommendation(malAnimeId,
                                                                                                                                                                              m_trainingData.Users[baseRecommender.UserId].Entries[malAnimeId].Rating, m_itemAverages[malAnimeId])
                                                                                                                      )
                                                                                                              ),
                                        recsNotInCommon: new HashSet <MalAnimeRecsRecommenderRecommendation>(baseRecommender.RecsNotInCommon
                                                                                                             .Select(malAnimeId => new MalAnimeRecsRecommenderRecommendation(malAnimeId,
                                                                                                                                                                             m_trainingData.Users[baseRecommender.UserId].Entries[malAnimeId].Rating, m_itemAverages[malAnimeId])
                                                                                                                     )
                                                                                                             ),
                                        compatibility: baseRecommender.Compatibility,
                                        compatibilityLowEndpoint: baseRecommender.CompatibilityLowEndpoint,
                                        compatibilityHighEndpoint: baseRecommender.CompatibilityHighEndpoint
                                        ));
            }

            return(new MalAnimeRecsResults(baseResults.Recommendations, malRecommenders, targetScoreUsed));
        }