예제 #1
0
        private static void showNeighboursAndSimilaritiesOfUserSeven(Dictionary <int, User> allUsers)
        {
            var userSeven = allUsers[7];

            ISimilarity similarityMeasure = new EuclideanSimilarity();
            var         userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("");
            Console.WriteLine("Neighbours and similarities using EUCLIDEAN: ");
            outputNeighbours(userSevenNeighboursAndSimilarities);


            similarityMeasure = new PearsonSimilarity();
            userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("");
            Console.WriteLine("Neighbours and similarities using PEARSON: ");
            outputNeighbours(userSevenNeighboursAndSimilarities);


            similarityMeasure = new CosineSimilarity();
            userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("");
            Console.WriteLine("Neighbours and similarities using COSINE: ");
            outputNeighbours(userSevenNeighboursAndSimilarities);
        }
예제 #2
0
        private static void singlePredictionDiagnostic(Dictionary <int, User> allUsers)
        {
            var userSeven = allUsers[7];

            ISimilarity similarityMeasure = new PearsonSimilarity();

            var userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("");
            IRatingPrediction weightedAvgPrediction = new WeightedAveragePrediction();

            Console.WriteLine("User no. 7 predicted rating of product no. 101  using pearson is "
                              + weightedAvgPrediction.predictRating(101, userSevenNeighboursAndSimilarities));
            Console.WriteLine("User no. 7 predicted rating of product no. 103 using pearson is "
                              + weightedAvgPrediction.predictRating(103, userSevenNeighboursAndSimilarities));
            Console.WriteLine("User no. 7 predicted rating of product no. 106 using pearson is "
                              + weightedAvgPrediction.predictRating(106, userSevenNeighboursAndSimilarities));

            //INCORRECT, CHECK THIS ONE
            var userFour = allUsers[4];
            var userFourNeighboursAndSimilarities = userFour.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("");
            Console.WriteLine("User no. 4 predicted rating of product no. 101 using pearson is "
                              + weightedAvgPrediction.predictRating(101, userFourNeighboursAndSimilarities));


            Console.WriteLine("");
            Console.WriteLine("USER NO. 7 RATED ITEM 106 AS A 2.8: REDOING PREDICTIONS OF ITEMS 101 and 103");
            userSeven.ratings[106]             = 2.8;
            userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("User no. 7 predicted rating of product no. 101, with rating of product no. 106 set to 2.8 using pearson is "
                              + weightedAvgPrediction.predictRating(101, userSevenNeighboursAndSimilarities));
            Console.WriteLine("User no. 7 predicted rating of product no. 103, with rating of product no. 106 set to 2.8 using pearson is "
                              + weightedAvgPrediction.predictRating(103, userSevenNeighboursAndSimilarities));


            Console.WriteLine("");
            Console.WriteLine("USER NO. 7 NOW RATED ITEM 106 AS A 5: REDOING PREDICTIONS OF ITEMS 101 and 103");
            userSeven.ratings[106]             = 5;
            userSevenNeighboursAndSimilarities = userSeven.getNearestNeighboursAndSimilarities(3, allUsers.Values.ToList(), similarityMeasure);

            Console.WriteLine("User no. 7 predicted rating of product no. 101, with rating of product no. 106 updated to 5 using pearson is "
                              + weightedAvgPrediction.predictRating(101, userSevenNeighboursAndSimilarities));
            Console.WriteLine("User no. 7 predicted rating of product no. 103, with rating of product no. 106 updated to 5 using pearson is "
                              + weightedAvgPrediction.predictRating(103, userSevenNeighboursAndSimilarities));
        }
예제 #3
0
        private static void similarityMeasuresDiagnostic(Dictionary <int, User> allUsers)
        {
            ISimilarity similarityMeasurer = new PearsonSimilarity();

            var testUser1 = allUsers[1];
            var testUser3 = allUsers[3];

            var overlappingProductsVectors = testUser1.getRatingsVectors(testUser3, similarityMeasurer.canHandleSparseData());

            var testUser1Vector = overlappingProductsVectors[testUser1.userId];
            var testUser3Vector = overlappingProductsVectors[testUser3.userId];

            Console.WriteLine("User 1 ratings vector: " + testUser1Vector.ToString());
            Console.WriteLine("User 3 ratings vector: " + testUser3Vector.ToString());

            Console.WriteLine("Pearson similarity between user 1 and user 3: "
                              + similarityMeasurer.computeSimilarity(testUser1Vector, testUser3Vector));
        }
예제 #4
0
        private static void nDimensionalRecommendationDiagnostic(Dictionary <int, User> sortedUserItems)
        {
            var user186 = sortedUserItems[186];

            ISimilarity       pearsonSimilarity     = new PearsonSimilarity();
            IRatingPrediction weightedAvgPrediction = new WeightedAveragePrediction();

            int neighboursAmount = 25;
            RecommendationCreator recommendationCreator = new RecommendationCreator(pearsonSimilarity, weightedAvgPrediction, neighboursAmount);

            int recommendationAmount = 8;
            int minimumAmountOfNeighbourProductOccurences = 0;
            var top8Recommendations = recommendationCreator.getListOfTopPredictedRatings(recommendationAmount, minimumAmountOfNeighbourProductOccurences, sortedUserItems, user186);

            Console.WriteLine("");
            Console.WriteLine("Top 8 recommendations for user 186 with " + neighboursAmount + " neighbours and minimumAmountOfNeighbourProductOccurences = 0: ");
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("");

            int counter = 0;

            top8Recommendations.ForEach(x => Console.WriteLine("Top " + (++counter) + " product: Movie no. " + x.Key + ", predicted rating " + x.Value));
            Console.WriteLine("");

            recommendationAmount = 8;
            minimumAmountOfNeighbourProductOccurences = 3;
            top8Recommendations = recommendationCreator.getListOfTopPredictedRatings(recommendationAmount, minimumAmountOfNeighbourProductOccurences, sortedUserItems, user186);

            Console.WriteLine("");
            Console.WriteLine("Top 8 recommendations for user 186 with " + neighboursAmount + " neighbours and minimumAmountOfNeighbourProductOccurences = 3: ");
            Console.WriteLine("-------------------------------------");
            Console.WriteLine("");

            counter = 0;
            top8Recommendations.ForEach(x => Console.WriteLine("Top " + (++counter) + " product: Movie no. " + x.Key + ", predicted rating " + x.Value));
        }