コード例 #1
0
        public async Task LearnCategoriesAsync()
        {
            var accounts = await this.db.Accounts.ToArrayAsync();

            foreach (var account in accounts)
            {
                var w            = Stopwatch.StartNew();
                var expenseCount = this.db.Expenses.Count(ex => ex.AccountId == account.Id);
                if (expenseCount < MinimumNumberOfExpensesForPrediction)
                {
                    continue;
                }

                var expenses = await this.db.Expenses.Where(ex => ex.AccountId == account.Id).ToArrayAsync();

                var predictor = new CategoryPredictor();
                predictor.Learn(expenses);
                this.accountToPredictor.AddOrUpdate(account.Name, predictor, (k, v) => predictor);
                w.Stop();

                this.log.LogInformation(Events.LearnCategoriesForAccount,
                                        "Learning categories for {AccountName} took {ElapsedMilliseconds}ms ({ExpenseCount} samples)",
                                        account.Name, w.ElapsedMilliseconds, expenseCount);
            }
        }
コード例 #2
0
        public void LearnPredictTest()
        {
            var trainSet = new[]
            {
                new Expense(-24.4M, "Haushalt", "Wocheneinkauf"),
                new Expense(-23.1M, "Haushalt", "Wocheneinkauf"),
                new Expense(-22.4M, "Haushalt", "Wocheneinkauf"),
                new Expense(-21.2M, "Haushalt", "Wocheneinkauf"),
                new Expense(-500M, "Haushalt", "Elektrogeräte"),
                new Expense(-2.5M, "Verpflegung", "Leberkäs"),
            };

            var predictor = new CategoryPredictor();

            predictor.Learn(trainSet);

            predictor.Predict(-22.0f, DateTime.Now, DateTime.Now).ShouldBe("Haushalt", "Wocheneinkauf");
            predictor.Predict(-600.0f, DateTime.Now, DateTime.Now).ShouldBe("Haushalt", "Elektrogeräte");
            predictor.Predict(-2.0f, DateTime.Now, DateTime.Now).ShouldBe("Verpflegung", "Leberkäs");
        }