예제 #1
0
        private async void FindAllBtn_Click(object sender, EventArgs e)
        {
            try
            {
                assocRuleRtb.Clear();
                assocRuleDgv.Rows.Clear();
                double percent = double.Parse(suppTxtb.Text);
                if (percent < 1)
                {
                    MessageBox.Show("Value to low");
                    return;
                }
                double supp    = ((double)((double)dataset.Count() / (double)100)) * percent;
                int    support = (int)Math.Round(supp);
                double conf    = double.Parse(confTxtb.Text);
                apriori = new Apriori(support, conf, toolStripProgressBar1);

                toolStripStatusLabel1.Text    = "Đang xử lí";
                toolStripStatusLabel1.Visible = true;

                assocRules = await apriori.LearnAsync(dataset);

                if (assocRules.Count() <= 500)
                {
                    foreach (var rule in assocRules)
                    {
                        if (rule.Y.Count > 0)
                        {
                            assocRuleDgv.Rows.Add(rule.GetAssocRule(), (rule.Support / dataset.Count()).ToString("P1"),
                                                  rule.Confidence.ToString("N"));
                            assocRuleRtb.Text += rule.ToString() + "\n";
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Quá nhiều dữ liệu" + "\nKết quả sẽ được lưu vào file");
                    CsvHelper.CsvWriter csvWriter = new CsvHelper.CsvWriter(new StreamWriter(".\\Output.csv"));
                    foreach (var rule in assocRules)
                    {
                        csvWriter.WriteField(rule.GetAssocRule());
                        csvWriter.WriteField(rule.Support);
                        csvWriter.WriteField(rule.Confidence.ToString("N"));
                        csvWriter.NextRecord();
                    }
                }

                toolStripProgressBar1.Visible = false;
                toolStripStatusLabel1.Visible = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #2
0
        public When_mine_is_called_the_apriori_algorithm()
        {
            var mockFactsGenerators = new List <IFactsGenerator <string> >()
            {
                new MockFactsGenerator()
            };

            apriori = new Apriori <string>(new SelfJoinAndPruneGenerator <string>(), mockFactsGenerators);
            factA   = new MockSimpleFact("A");
            factB   = new MockSimpleFact("B");
            factC   = new MockSimpleFact("C");
        }