Пример #1
0
        public ResultExperimentClassification TestClassification(object a)
        {
            InfaForExperimentClassification infa = (InfaForExperimentClassification)a;

            ResultExperimentClassification result = new ResultExperimentClassification();

            result.timeTrain          = new Stopwatch();
            result.timeTest           = new Stopwatch();
            result.timeСlassification = new Stopwatch();

            RandomForest RF = (RandomForest)SerializationHelper.read(infa.fileNameModel);  //Загрузка модели

            //RandomForest RF = new RandomForest();

            result.timeTest.Start();

            result.evaluation = evaluateModel(RF, infa.trainDataSet, infa.testDataSet); //Тестирование

            result.timeTest.Stop();
            result.timeСlassification.Start();

            RF.classifyInstance(infa.testDataSet.instance(0)); //Замер времени классификации 1 экземпляра

            result.timeСlassification.Stop();

            return(result);
        }
Пример #2
0
        public ResultExperimentClassification ExperimentClassification(object a)
        {
            InfaForExperimentClassification infa = (InfaForExperimentClassification)a;

            ResultExperimentClassification result = new ResultExperimentClassification();

            result.timeTrain          = new Stopwatch();
            result.timeTest           = new Stopwatch();
            result.timeСlassification = new Stopwatch();

            RandomForest RF = new RandomForest();

            RF.setNumIterations(100); //Количество деревьев

            result.timeTrain.Start();

            RF.buildClassifier(infa.trainDataSet); //Обучние

            result.timeTrain.Stop();
            result.timeTest.Start();

            result.evaluation = evaluateModel(RF, infa.trainDataSet, infa.testDataSet); //Тестирование

            result.timeTest.Stop();
            result.timeСlassification.Start();

            RF.classifyInstance(infa.testDataSet.instance(0)); //Замер времени классификации 1 экземпляра

            result.timeСlassification.Stop();

            return(result);
        }
Пример #3
0
        private async void button8_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "model файлы (*.model)|*.model|Все файлы (*.*)|*.*";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                InfaForExperimentClassification infa = new InfaForExperimentClassification(); //Инфа для второго потока

                trainDataSet.setClassIndex(trainDataSet.numAttributes() - 1);                 //Установка указателя на атрибут с классами
                testDataSet.setClassIndex(testDataSet.numAttributes() - 1);

                infa.trainDataSet  = trainDataSet;
                infa.testDataSet   = testDataSet;
                infa.fileNameModel = openFileDialog1.FileName;

                labelStatus.Text = "Проводится тестирование...";

                ResultExperimentClassification result = await Task.Factory.StartNew(() => TestClassification(infa));

                Evaluation evaluation = result.evaluation;

                for (int i = 0; i < 2; i++)
                {
                    string[] row = new string[11];
                    row[0] = $"{i}";
                    row[1] = evaluation.precision(i).ToString();                 //Точность
                    row[2] = evaluation.recall(i).ToString();                    //Полнота
                    row[3] = evaluation.fMeasure(i).ToString();                  //F-мера //Accuracy
                    row[4] = (evaluation.pctCorrect() / 100).ToString();         //Достоверноесть
                    row[5] = evaluation.truePositiveRate(i).ToString();          //TPR
                    row[6] = evaluation.falsePositiveRate(i).ToString();         //FPR
                    row[7] = evaluation.areaUnderROC(i).ToString();              //ROC

                    row[8]  = result.timeTrain.ElapsedTicks.ToString();          //Время обучения
                    row[9]  = result.timeTest.ElapsedTicks.ToString();           //Время тестирования
                    row[10] = result.timeСlassification.ElapsedTicks.ToString(); //Время классификации 1 экзепляра

                    dataGridView5.Rows.Add(row);
                }

                labelStatus.Text = "Тестирование прошло успешно.";
            }
        }
Пример #4
0
        private async void button6_Click(object sender, EventArgs e)
        {
            InfaForExperimentClassification infa = new InfaForExperimentClassification(); //Инфа для второго потока

            Instances experimentdataSet = dataSet;

            experimentdataSet.setClassIndex(experimentdataSet.numAttributes() - 1); //Установка указателя на атрибут с классами

            java.util.Random rnd = new java.util.Random();
            experimentdataSet.randomize(rnd);                                                   //Перемешивание исходного набора данных

            int trainSize = (int)Math.Round((double)(experimentdataSet.numInstances() * 0.66)); //0.66 - Процент даннхы на обучение
            int testSize  = experimentdataSet.numInstances() - trainSize;

            infa.trainDataSet = new Instances(experimentdataSet, 0, trainSize);
            infa.testDataSet  = new Instances(experimentdataSet, trainSize, testSize);

            labelStatus.Text = "Проводится эксперимент...";

            ResultExperimentClassification result = await Task.Factory.StartNew(() => ExperimentClassification(infa));

            Evaluation evaluation = result.evaluation;

            string[] row = new string[10];
            row[0] = evaluation.weightedPrecision().ToString();         //Точность
            row[1] = evaluation.weightedRecall().ToString();            //Полнота
            row[2] = evaluation.weightedFMeasure().ToString();          //F-мера //Accuracy
            row[3] = (evaluation.pctCorrect() / 100).ToString();        //Достоверноесть
            row[4] = evaluation.weightedTruePositiveRate().ToString();  //TPR
            row[5] = evaluation.weightedFalsePositiveRate().ToString(); //FPR
            row[6] = evaluation.weightedAreaUnderROC().ToString();      //ROC

            row[7] = result.timeTrain.ElapsedTicks.ToString();          //Время обучения
            row[8] = result.timeTest.ElapsedTicks.ToString();           //Время тестирования
            row[9] = result.timeСlassification.ElapsedTicks.ToString(); //Время классификации 1 экзепляра

            dataGridView5.Rows.Add(row);

            labelStatus.Text = "Эксперимент завершён";
        }