Example #1
0
        public static void BiasedMatrixFactorizationTest()
        {
            List <Rating> baseRatings = Tools.GetRatings(BaseRatingFile, " ");
            List <Rating> testRatings = Tools.GetRatings(TestRatingFile, " ");

            BiasedMatrixFactorization model = new BiasedMatrixFactorization(MaxUserId, MaxItemId);

            model.TrySGD(baseRatings, testRatings, 100, 0.005, 0.02, 0.98);
        }
Example #2
0
        public static void BiasedMatrixFactorizationTest(double testSize = 0.1)
        {
            List <Rating>             ratings   = Tools.GetRatings(RatingFile, ",");
            var                       max       = Tools.GetMaxUserIdAndItemId(ratings);
            var                       maxUserId = max.Item1 + 1;
            var                       maxItemId = max.Item2 + 1;
            BiasedMatrixFactorization model     = new BiasedMatrixFactorization(maxUserId, maxItemId);
            var                       t         = Tools.TrainTestSplit(ratings, testSize);

            model.TrySGD(t.Item1, t.Item2, 100, 0.005);
        }
Example #3
0
        public static void BiasedMatrixFactorizationTest(double testSize = 0.1)
        {
            List <Rating> ratings = Tools.GetRatings(DefaultRatingFile, "::");

            Tools.UpdateIndexesToZeroBased(ratings);

            var t = Tools.TrainTestSplit(ratings, testSize);

            BiasedMatrixFactorization model = new BiasedMatrixFactorization(MaxUserId, MaxItemId);

            model.TrySGD(t.Item1, t.Item2, 100, 0.005);
        }
Example #4
0
        public static void BiasedMatrixFactorizationTest()
        {
            List <Rating> baseRatings = Tools.GetRatings(BaseRatingFile);
            List <Rating> testRatings = Tools.GetRatings(TestRatingFile);

            Tools.UpdateIndexesToZeroBased(baseRatings);
            Tools.UpdateIndexesToZeroBased(testRatings);

            BiasedMatrixFactorization model = new BiasedMatrixFactorization(MaxUserId, MaxItemId);

            model.TrySGD(baseRatings, testRatings, 100, 0.01, 0.01, 0.95);
        }
Example #5
0
        public static void MatrixFactorization_IJCAI2018_Test2()
        {
            double        testSize = 0.2;
            List <Rating> ratings  = Tools.GetRatings(@"D:\data\ijcai2018task\ex\train.shop.csv", ",");

            var data = Tools.TrainTestSplit(ratings, testSize);
            var max  = Tools.GetMaxUserIdAndItemId(ratings);

            Tools.WriteRatings(data.Item1, @"D:\data\ijcai2018task\ex\train.shop.1.csv");
            Tools.WriteRatings(data.Item2, @"D:\data\ijcai2018task\ex\train.shop.2.csv");

            BiasedMatrixFactorization model = new BiasedMatrixFactorization(max.Item1 + 1, max.Item2 + 1, 100);

            model.TrySGD(data.Item1, data.Item2, 100, 0.01, 0.01, 0.94, 0, 1);
        }
Example #6
0
        public static void BiasedMatrixFactorization(Dictionary <string, string> pairs)
        {
            string separator = "\t";

            if (pairs.Keys.Contains("separator"))
            {
                separator = pairs["separator"];
            }

            List <Rating> baseRatings = Tools.GetRatings(pairs["train"], separator);
            List <Rating> testRatings = Tools.GetRatings(pairs["test"], separator);

            int maxUserId = System.Math.Max(baseRatings.Max(r => r.UserId), testRatings.Max(r => r.UserId));
            int maxItemId = System.Math.Max(baseRatings.Max(r => r.ItemId), testRatings.Max(r => r.ItemId));

            Tools.UpdateIndexesToZeroBased(baseRatings);
            Tools.UpdateIndexesToZeroBased(testRatings);

            int f = 10;

            if (pairs.Keys.Contains("f"))
            {
                f = Int32.Parse(pairs["f"]);
            }

            int epochs = 100;

            if (pairs.Keys.Contains("epochs"))
            {
                epochs = Int32.Parse(pairs["epochs"]);
            }

            double gamma = 0.01;

            if (pairs.Keys.Contains("gamma"))
            {
                gamma = Double.Parse(pairs["gamma"]);
            }

            double lambda = 0.01;

            if (pairs.Keys.Contains("lambda"))
            {
                lambda = Double.Parse(pairs["lambda"]);
            }

            double min_rating = 1.0;

            if (pairs.Keys.Contains("min_rating"))
            {
                min_rating = Double.Parse(pairs["min_rating"]);
            }

            double max_rating = 5.0;

            if (pairs.Keys.Contains("max_rating"))
            {
                max_rating = Double.Parse(pairs["max_rating"]);
            }

            BiasedMatrixFactorization model = new BiasedMatrixFactorization(maxUserId, maxItemId, f);

            model.TrySGD(baseRatings, testRatings, epochs, gamma, lambda, min_rating, max_rating);
        }