Changeset 6680


Ignore:
Timestamp:
08/24/11 13:12:16 (8 years ago)
Author:
mkommend
Message:

#1592: Improved ClassificationEnsembleSolutionEstimatedClassValuesView with coloring of classification results.

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r5445 r6680  
    4444    }
    4545
     46    public DataGridView DataGridView {
     47      get { return dataGridView; }
     48    }
     49
    4650    public override bool ReadOnly {
    4751      get {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationEnsembleSolutionEstimatedClassValuesView.cs

    r6672 r6680  
    2121using System;
    2222using System.Collections.Generic;
     23using System.Drawing;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    3334    ClassificationSolutionEstimatedClassValuesView {
    3435    private const string RowColumnName = "Row";
    35     private const string TargetClassValuesColumnName = "TargetVariable";
    36     private const string EstimatedClassValuesColumnName = "EstimatedClassValues";
     36    private const string TargetClassValuesColumnName = "Target Variable";
     37    private const string EstimatedClassValuesColumnName = "Estimated Class Values";
     38    private const string CorrectClassificationColumnName = "Correct Classification";
    3739    private const string ConfidenceColumnName = "Confidence";
    3840
     
    5153      SamplesComboBox.Items.AddRange(new string[] { SamplesComboBoxAllSamples, SamplesComboBoxTrainingSamples, SamplesComboBoxTestSamples });
    5254      SamplesComboBox.SelectedIndex = 0;
     55      matrixView.DataGridView.RowPrePaint += new DataGridViewRowPrePaintEventHandler(DataGridView_RowPrePaint);
    5356    }
     57
     58
    5459
    5560    private void SamplesComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     
    9297      int classValuesCount = Content.ProblemData.ClassValues.Count;
    9398      int modelCount = Content.Model.Models.Count();
    94       string[,] values = new string[indizes.Length, 4 + classValuesCount + modelCount];
     99      string[,] values = new string[indizes.Length, 5 + classValuesCount + modelCount];
    95100      double[] target = Content.ProblemData.Dataset.GetVariableValues(Content.ProblemData.TargetVariable);
    96101      List<List<double?>> estimatedValuesVector = GetEstimatedValues(SamplesComboBox.SelectedItem.ToString(), indizes,
     
    102107        values[i, 1] = target[i].ToString();
    103108        values[i, 2] = estimatedClassValues[i].ToString();
     109        values[i, 3] = (target[i] == estimatedClassValues[i]).ToString();
    104110        var groups = estimatedValuesVector[i].GroupBy(x => x).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
    105111        var estimationCount = groups.Where(g => g.Key != null).Select(g => g.Count).Sum();
    106         values[i, 3] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
     112        values[i, 4] = (((double)groups.Where(g => g.Key == estimatedClassValues[i]).Single().Count) / estimationCount).ToString();
    107113        for (int classIndex = 0; classIndex < Content.ProblemData.ClassValues.Count; classIndex++) {
    108114          var group = groups.Where(g => g.Key == Content.ProblemData.ClassValues[classIndex]).SingleOrDefault();
    109           if (group == null) values[i, 4 + classIndex] = 0.ToString();
    110           else values[i, 4 + classIndex] = group.Count.ToString();
     115          if (group == null) values[i, 5 + classIndex] = 0.ToString();
     116          else values[i, 5 + classIndex] = group.Count.ToString();
    111117        }
    112118        for (int modelIndex = 0; modelIndex < estimatedValuesVector[i].Count; modelIndex++) {
    113           values[i, 4 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
     119          values[i, 5 + classValuesCount + modelIndex] = estimatedValuesVector[i][modelIndex] == null
    114120                                                           ? string.Empty
    115121                                                           : estimatedValuesVector[i][modelIndex].ToString();
     
    119125
    120126      StringMatrix matrix = new StringMatrix(values);
    121       List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, ConfidenceColumnName };
     127      List<string> columnNames = new List<string>() { "Id", TargetClassValuesColumnName, EstimatedClassValuesColumnName, CorrectClassificationColumnName, ConfidenceColumnName };
    122128      columnNames.AddRange(Content.ProblemData.ClassNames);
    123129      columnNames.AddRange(Content.Model.Models.Select(m => m.Name));
     
    125131      matrix.SortableView = true;
    126132      matrixView.Content = matrix;
     133      UpdateColoringOfRows();
    127134    }
    128135
     
    150157    }
    151158
     159    private void DataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) {
     160      if (InvokeRequired) {
     161        Invoke(new EventHandler<DataGridViewRowPrePaintEventArgs>(DataGridView_RowPrePaint), sender, e);
     162        return;
     163      }
     164      bool correctClassified = bool.Parse(matrixView.DataGridView[3, e.RowIndex].Value.ToString());
     165      matrixView.DataGridView.Rows[e.RowIndex].DefaultCellStyle.ForeColor = correctClassified ? Color.MediumSeaGreen : Color.Red;
     166    }
    152167
    153 
     168    private void UpdateColoringOfRows() {
     169      if (InvokeRequired) {
     170        Invoke((Action)UpdateColoringOfRows);
     171        return;
     172      }
     173      //matrixView.DataGridView.SuspendRepaint();
     174      //for (int i = 0; i < matrixView.DataGridView.Rows.Count; i++) {
     175      //  bool correctClassified = bool.Parse(matrixView.Content.GetValue(i, 3));
     176      //  matrixView.DataGridView.Rows[i].DefaultCellStyle.ForeColor = correctClassified ? Color.MediumSeaGreen : Color.Red;
     177      //}
     178      //matrixView.DataGridView.ResumeRepaint(true);
     179    }
    154180  }
    155181}
Note: See TracChangeset for help on using the changeset viewer.