예제 #1
0
        public static double slopeOne(int userId, int productId)
        {
            var        data     = DataParser.write2DArray("./userData.data", ",");
            List <int> products = DataParser.getProducts(data);

            products.Remove(productId);
            Dictionary <int, double> deviations = new Dictionary <int, double>();

            foreach (var item in products)
            {
                deviations.Add(item, ItemItem.deviations(productId, item));
            }

            //double averageDeviation = deviations.Average((item) => item.Value);
            //Console.WriteLine(averageDeviation);

            int    counter = 0;
            double result  = 0;

            foreach (var deviation in deviations)
            {
                if (data[userId].ContainsKey(deviation.Key) == true)
                {
                    counter++;
                    result += data[userId][deviation.Key] + deviation.Value;
                }
            }
            return(result / counter);
        }
예제 #2
0
        public static double deviations(int productId1, int productId2)
        {
            var data = DataParser.write2DArray("./userData.data", ",");

            var    filteredData = DataParser.filterTwoProducts(data, productId1, productId2);
            double result       = 0f;

            foreach (var user in filteredData)
            {
                result += ((user.Value[productId1]) - (user.Value[productId2]));
            }
            return(result / filteredData.Count());
        }
예제 #3
0
        public static void printData(int user1, int user2)
        {
            int[] users = { user1, user2 };

            StrategyContext strategy1 = new StrategyContext(new Euclidian());
            StrategyContext strategy2 = new StrategyContext(new Manhattan());
            StrategyContext strategy3 = new StrategyContext(new Pearsson());

            var data      = DataParser.filterData(DataParser.write2DArray("./userData.data", ","), users[0], users[1], true);
            var dataNoDel = DataParser.filterData(data, users[0], users[1], false);

            var tuple      = DataParser.splitDictionaries(data);
            var tupleNoDel = DataParser.splitDictionaries(dataNoDel);

            ////////////////////// FRONTEND \\\\\\\\\\\\\\\\\\\\\\

            Console.WriteLine("User " + users[0].ToString() + " -VS- User " + users[1].ToString());

            Console.WriteLine("Euclidian - " + strategy1.algorithm(tuple).ToString());
            Console.WriteLine("Manhattan - " + strategy2.algorithm(tuple).ToString());
            Console.WriteLine("Pearsson - " + strategy3.algorithm(tupleNoDel).ToString());

            Console.WriteLine();
        }
예제 #4
0
 static Dictionary <int, Dictionary <int, double> > getData()
 {
     return(DataParser.write2DArray("./userItem.data", ","));
     //return DataParser.write2DArray_MovieLens("./ratings.csv");
 }