SampleApp.MainForm.btnRunCalibration_Click C# (CSharp) Method

btnRunCalibration_Click() private method

Calibrates the current Support Vector Machine to produce probabilistic outputs using ProbabilisticOutputLearning.
private btnRunCalibration_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void btnRunCalibration_Click(object sender, EventArgs e)
        {
            if (ksvm == null)
            {
                MessageBox.Show("Please train the machines first.");
                return;
            }

            // Extract inputs and outputs
            int rows = dgvTrainingSource.Rows.Count;
            double[][] input = new double[rows][];
            int[] output = new int[rows];
            for (int i = 0; i < rows; i++)
            {
                input[i] = (double[])dgvTrainingSource.Rows[i].Cells["colTrainingFeatures"].Value;
                output[i] = (int)dgvTrainingSource.Rows[i].Cells["colTrainingLabel"].Value;
            }



            // Create the calibration algorithm using the training data
            var ml = new MulticlassSupportVectorLearning<IKernel>()
            {
                Model = ksvm,

                // Configure the calibration algorithm
                Learner = (p) => new ProbabilisticOutputCalibration<IKernel>()
                {
                    Model = p.Model
                }
            };


            lbStatus.Text = "Calibrating the classifiers. This may take a (very) significant amount of time...";
            Application.DoEvents();

            Stopwatch sw = Stopwatch.StartNew();

            // Train the machines. It should take a while.
            ml.Learn(input, output);

            sw.Stop();

            double error = new ZeroOneLoss(output).Loss(ksvm.Decide(input));

            lbStatus.Text = String.Format(
                "Calibration complete ({0}ms, {1}er). Click Classify to test the classifiers.",
                sw.ElapsedMilliseconds, error);

            btnClassifyVoting.Enabled = true;
        }
MainForm