Example #1
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));
        }
Example #2
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));
        }