private void btnClassify_Click(object sender, EventArgs e)
{
int trainingHits = 0;
int trainingMiss = 0;
int testingHits = 0;
int testingMiss = 0;
// For each image group (i.e. flowers, dolphins)
foreach (ListViewGroup group in listView1.Groups)
{
// For each image item in the group
foreach (ListViewItem item in group.Items)
{
var info = item.Tag as Tuple<double[], int>;
double[] input = info.Item1;
int expected = info.Item2;
// Classify into one of the classes
int actual = ksvm.Compute(input);
// Check if we did a correct classification
if (expected == actual)
{
// Yes, we did! Change color to green
item.BackColor = Color.LightGreen;
if (item.Group.Name.EndsWith(".train"))
trainingHits++;
else testingHits++;
}
else
{
// No, we didn't :( change to red
item.BackColor = Color.Firebrick;
if (item.Group.Name.EndsWith(".train"))
trainingMiss++;
else testingMiss++;
}
}
}
int trainingTotal = trainingHits + trainingMiss;
int testingTotal = testingHits + testingMiss;
lbStatus.Text = String.Format("Classification complete. " +
"Training: {0}/{1} ({2:00.00}%) hits. Testing: {3}/{4} ({5:00.00}%) hits.",
trainingHits, trainingTotal, 100 * trainingHits / (double)(trainingTotal),
testingHits, testingTotal, 100 * testingHits / (double)(testingTotal));
}