public void Train(MalTrainingData trainingData)
        {
            IBasicTrainingData <IBasicInputForUser> basicTrainingData =
                trainingData.AsBasicTrainingData(MinEpisodesToCountIncomplete, UseDropped);

            m_recommender.Train(basicTrainingData);
        }
예제 #2
0
        private void SetAverages(MalTrainingData trainingData)
        {
            m_itemAverages.Clear();

            Dictionary <int, float> scoreSumByItem  = new Dictionary <int, float>();
            Dictionary <int, int>   numScoresByItem = new Dictionary <int, int>();

            IBasicTrainingData <IBasicInputForUser> basicTrainingData =
                trainingData.AsBasicTrainingData(m_minEpisodesToClassifyIncomplete, includeDropped: true);

            foreach (int userId in basicTrainingData.Users.Keys)
            {
                foreach (KeyValuePair <int, float> itemIdRatingPair in basicTrainingData.Users[userId].Ratings)
                {
                    int   itemId = itemIdRatingPair.Key;
                    float rating = itemIdRatingPair.Value;

                    if (!scoreSumByItem.ContainsKey(itemId))
                    {
                        scoreSumByItem[itemId]  = 0;
                        numScoresByItem[itemId] = 0;
                    }

                    scoreSumByItem[itemId] += rating;
                    numScoresByItem[itemId]++;
                }
            }

            foreach (int itemId in scoreSumByItem.Keys)
            {
                float averageScore = scoreSumByItem[itemId] / numScoresByItem[itemId];
                m_itemAverages[itemId] = averageScore;
            }
        }
        public void Train(MalTrainingData trainingData)
        {
            IBasicTrainingData <IBasicInputForUser> basicTrainingData =
                trainingData.AsBasicTrainingData(MinEpisodesToCountIncomplete, UseDropped);

            IBasicTrainingData <IBasicInputForUser> filteredTrainingData = FilterHelpers.RemoveItemsWithFewUsers(basicTrainingData, MinUsersToCountAnime);

            m_recommender.Train(filteredTrainingData);
        }
        public void Train(MalTrainingData trainingData)
        {
            m_userCountByAnime = new Dictionary <int, int>();
            IBasicTrainingData <IBasicInputForUser> basicTrainingData =
                trainingData.AsBasicTrainingData(m_minEpisodesToCountIncomplete, m_useDropped);

            foreach (int userId in basicTrainingData.Users.Keys)
            {
                foreach (int itemId in basicTrainingData.Users[userId].Ratings.Keys)
                {
                    if (!m_userCountByAnime.ContainsKey(itemId))
                    {
                        m_userCountByAnime[itemId] = 0;
                    }
                    m_userCountByAnime[itemId]++;
                }
            }

            // Do not filter out anime with few users at this point. Let the MyMediaLite recommender possibly make use of that data.

            m_recommender.Train(basicTrainingData);
        }
예제 #5
0
        public void Train(IBasicTrainingData <IBasicInputForUser> trainingData)
        {
            m_realUserIdToMediaLiteUserId = new Dictionary <int, int>();
            m_mediaLiteUserIdToRealUserId = new Dictionary <int, int>();
            m_nextMediaLiteUserId         = 0;

            m_realItemIdToMediaLiteItemId = new Dictionary <int, int>();
            m_mediaLiteItemIdToRealItemId = new Dictionary <int, int>();
            m_nextMediaLiteItemId         = 0;

            MyMediaLite.Data.Ratings mediaLiteRatings = new MyMediaLite.Data.Ratings();
            foreach (KeyValuePair <int, IBasicInputForUser> userRatingsPair in trainingData.Users)
            {
                int userId = userRatingsPair.Key;
                IBasicInputForUser ratings = userRatingsPair.Value;

                m_realUserIdToMediaLiteUserId[userId] = m_nextMediaLiteUserId;
                m_mediaLiteUserIdToRealUserId[m_nextMediaLiteUserId] = userId;
                m_nextMediaLiteUserId++;

                foreach (KeyValuePair <int, float> rating in ratings.Ratings)
                {
                    int   itemId = rating.Key;
                    float score  = rating.Value;

                    if (!m_realItemIdToMediaLiteItemId.ContainsKey(itemId))
                    {
                        m_realItemIdToMediaLiteItemId[itemId] = m_nextMediaLiteItemId;
                        m_mediaLiteItemIdToRealItemId[m_nextMediaLiteItemId] = itemId;
                        m_nextMediaLiteItemId++;
                    }

                    mediaLiteRatings.Add(m_realUserIdToMediaLiteUserId[userId], m_realItemIdToMediaLiteItemId[itemId], score);
                }
            }

            m_recommender.Ratings = mediaLiteRatings;
            m_recommender.Train();
        }
        public void Train(MalTrainingData trainingData)
        {
            m_userCountByAnime = new Dictionary <int, int>();

            IBasicTrainingData <IPositiveFeedbackForUser> basicFeedback = trainingData.AsPositiveFeedback(m_positiveClassifier);

            foreach (int userId in basicFeedback.Users.Keys)
            {
                foreach (int itemId in basicFeedback.Users[userId].Items)
                {
                    if (!m_userCountByAnime.ContainsKey(itemId))
                    {
                        m_userCountByAnime[itemId] = 0;
                    }
                    m_userCountByAnime[itemId]++;
                }
            }

            // Do not filter out anime with few users at this point. Let the MyMediaLite recommender possibly make use of that data.

            m_recommender.Train(basicFeedback);
        }
예제 #7
0
        public void Train(IBasicTrainingData <IPositiveFeedbackForUser> trainingData)
        {
            m_realUserIdToMediaLiteUserId = new Dictionary <int, int>();
            m_mediaLiteUserIdToRealUserId = new Dictionary <int, int>();
            m_nextMediaLiteUserId         = 0;

            m_realItemIdToMediaLiteItemId = new Dictionary <int, int>();
            m_mediaLiteItemIdToRealItemId = new Dictionary <int, int>();
            m_nextMediaLiteItemId         = 0;

            PosOnlyFeedback <SparseBooleanMatrix> mediaLiteFeedback = new PosOnlyFeedback <SparseBooleanMatrix>();

            foreach (KeyValuePair <int, IPositiveFeedbackForUser> userFeedbackPair in trainingData.Users)
            {
                int userId = userFeedbackPair.Key;
                IPositiveFeedbackForUser feedback = userFeedbackPair.Value;

                m_realUserIdToMediaLiteUserId[userId] = m_nextMediaLiteUserId;
                m_mediaLiteUserIdToRealUserId[m_nextMediaLiteUserId] = userId;
                m_nextMediaLiteUserId++;

                foreach (int itemId in feedback.Items)
                {
                    if (!m_realItemIdToMediaLiteItemId.ContainsKey(itemId))
                    {
                        m_realItemIdToMediaLiteItemId[itemId] = m_nextMediaLiteItemId;
                        m_mediaLiteItemIdToRealItemId[m_nextMediaLiteItemId] = itemId;
                        m_nextMediaLiteItemId++;
                    }

                    mediaLiteFeedback.Add(m_realUserIdToMediaLiteUserId[userId], m_realItemIdToMediaLiteItemId[itemId]);
                }
            }

            m_recommender.Feedback = mediaLiteFeedback;
            m_recommender.Train();
        }
예제 #8
0
        public static IBasicTrainingData<IBasicInputForUser> RemoveItemsWithFewUsers(IBasicTrainingData<IBasicInputForUser> trainingData, int minimumUsers)
        {
            Dictionary<int, int> itemRatingCountByItemId = new Dictionary<int, int>();

            foreach (int userId in trainingData.Users.Keys)
            {
                foreach (int animeId in trainingData.Users[userId].Ratings.Keys)
                {
                    if (!itemRatingCountByItemId.ContainsKey(animeId))
                    {
                        itemRatingCountByItemId[animeId] = 0;
                    }
                    itemRatingCountByItemId[animeId]++;
                }
            }

            foreach (int userId in trainingData.Users.Keys)
            {
                List<int> animeIdsToRemove = new List<int>();

                foreach (int animeId in trainingData.Users[userId].Ratings.Keys)
                {
                    if (itemRatingCountByItemId[animeId] < minimumUsers)
                    {
                        animeIdsToRemove.Add(animeId);
                    }
                }

                foreach (int animeIdToRemove in animeIdsToRemove)
                {
                    trainingData.Users[userId].Ratings.Remove(animeIdToRemove);
                }
            }

            return trainingData;
        }
예제 #9
0
        public static IBasicTrainingData <IBasicInputForUser> RemoveItemsWithFewUsers(IBasicTrainingData <IBasicInputForUser> trainingData, int minimumUsers)
        {
            Dictionary <int, int> itemRatingCountByItemId = new Dictionary <int, int>();

            foreach (int userId in trainingData.Users.Keys)
            {
                foreach (int animeId in trainingData.Users[userId].Ratings.Keys)
                {
                    if (!itemRatingCountByItemId.ContainsKey(animeId))
                    {
                        itemRatingCountByItemId[animeId] = 0;
                    }
                    itemRatingCountByItemId[animeId]++;
                }
            }

            foreach (int userId in trainingData.Users.Keys)
            {
                List <int> animeIdsToRemove = new List <int>();

                foreach (int animeId in trainingData.Users[userId].Ratings.Keys)
                {
                    if (itemRatingCountByItemId[animeId] < minimumUsers)
                    {
                        animeIdsToRemove.Add(animeId);
                    }
                }

                foreach (int animeIdToRemove in animeIdsToRemove)
                {
                    trainingData.Users[userId].Ratings.Remove(animeIdToRemove);
                }
            }

            return(trainingData);
        }