示例#1
0
        private void test_button(object sender, EventArgs e)
        {
            string algorithm = comboBox1.Text;

            if (ac == null)
            {
                List <Itemset> eclatlitems = new List <Itemset>();
                try
                {
                    AllKeyWords = readFromFile(keyword_txt.Text);
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("Keywords error!");
                }

                try
                {
                    eclatlitems = load_model("AR.model");
                }
                catch (FileNotFoundException)
                {
                    MessageBox.Show("AR.model dont exist!");
                }

                ac = new AR(eclatlitems, AllKeyWords);
            }

            ac.Classification_Test(testmessages, algorithm);

            write_mat(ac.testdocRule, ac.testlabels, "test");

            ///*******************************************************************/
            //ac.Classification_Test(test_docword, algorithm);
            ///*******************************************************************/

            List <string> result = readFromFile("RESULTES_" + algorithm);
            double        accuracy;
            int           TPos = 0;
            int           TNeg = 0;
            int           FPos = 0;
            int           FNeg = 0;

            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] == "True")
                {
                    if (testlabel[i] == 1)
                    {
                        TPos++;
                    }
                    else
                    {
                        FPos++;
                    }
                }
                else
                {
                    if (testlabel[i] == 0)
                    {
                        TNeg++;
                    }
                    else
                    {
                        FNeg++;
                    }
                }
            }

            accuracy = (double)(TPos + TNeg) / result.Count;
            double percision = (double)TPos / (TPos + FPos);
            double recall    = (double)TPos / (TPos + FNeg);

            string[] row = { accuracy.ToString("0.0000"), TPos.ToString(), FPos.ToString(), TNeg.ToString(), FNeg.ToString(), percision.ToString("0.0000"), recall.ToString("0.0000") };
            dataGridView1.Rows.Add(row);
        }