Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 6 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs
r5975 r6760 24 24 using System.Linq; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Core.Views;27 26 using HeuristicLab.MainForm; 28 27 using HeuristicLab.MainForm.WindowsForms; … … 31 30 [View("Confusion Matrix")] 32 31 [Content(typeof(IClassificationSolution))] 33 public partial class ClassificationSolutionConfusionMatrixView : ItemView, IClassificationSolutionEvaluationView {32 public partial class ClassificationSolutionConfusionMatrixView : DataAnalysisSolutionEvaluationView { 34 33 private const string TrainingSamples = "Training"; 35 34 private const string TestSamples = "Test"; … … 78 77 dataGridView.ColumnCount = 1; 79 78 } else { 80 dataGridView.ColumnCount = Content.ProblemData.Classes ;81 dataGridView.RowCount = Content.ProblemData.Classes ;79 dataGridView.ColumnCount = Content.ProblemData.Classes + 1; 80 dataGridView.RowCount = Content.ProblemData.Classes + 1; 82 81 83 82 int i = 0; … … 87 86 i++; 88 87 } 88 dataGridView.Columns[i].HeaderText = "Actual not classified"; 89 dataGridView.Rows[i].HeaderCell.Value = "Predicted not classified"; 90 89 91 dataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader); 90 92 dataGridView.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders); … … 100 102 if (Content == null) return; 101 103 102 double[,] confusionMatrix = new double[Content.ProblemData.Classes , Content.ProblemData.Classes];104 double[,] confusionMatrix = new double[Content.ProblemData.Classes + 1, Content.ProblemData.Classes + 1]; 103 105 IEnumerable<int> rows; 104 106 107 double[] predictedValues; 105 108 if (cmbSamples.SelectedItem.ToString() == TrainingSamples) { 106 109 rows = Content.ProblemData.TrainingIndizes; 110 predictedValues = Content.EstimatedTrainingClassValues.ToArray(); 107 111 } else if (cmbSamples.SelectedItem.ToString() == TestSamples) { 108 112 rows = Content.ProblemData.TestIndizes; 113 predictedValues = Content.EstimatedTestClassValues.ToArray(); 109 114 } else throw new InvalidOperationException(); 115 116 double[] targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray(); 110 117 111 118 Dictionary<double, int> classValueIndexMapping = new Dictionary<double, int>(); … … 116 123 } 117 124 118 double[] targetValues = Content.ProblemData.Dataset.GetEnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();119 double[] predictedValues = Content.GetEstimatedClassValues(rows).ToArray();120 121 125 for (int i = 0; i < targetValues.Length; i++) { 122 126 double targetValue = targetValues[i]; 123 127 double predictedValue = predictedValues[i]; 124 int targetIndex = classValueIndexMapping[targetValue]; 125 int predictedIndex = classValueIndexMapping[predictedValue]; 128 int targetIndex; 129 int predictedIndex; 130 if (!classValueIndexMapping.TryGetValue(targetValue, out targetIndex)) { 131 targetIndex = Content.ProblemData.Classes; 132 } 133 if (!classValueIndexMapping.TryGetValue(predictedValue, out predictedIndex)) { 134 predictedIndex = Content.ProblemData.Classes; 135 } 126 136 127 137 confusionMatrix[predictedIndex, targetIndex] += 1; -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs
r5975 r6760 22 22 using System.Linq; 23 23 using System.Windows.Forms; 24 using HeuristicLab.Core.Views;25 24 using HeuristicLab.Data; 26 25 using HeuristicLab.Data.Views; … … 31 30 [View("Estimated Class Values")] 32 31 [Content(typeof(IClassificationSolution))] 33 public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView { 34 private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable"; 35 private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedClassValues"; 32 public partial class ClassificationSolutionEstimatedClassValuesView : DataAnalysisSolutionEvaluationView { 33 private const string TARGETVARIABLE_SERIES_NAME = "Target Variable"; 34 private const string ESTIMATEDVALUES_SERIES_NAME = "Estimated Class Values (all)"; 35 private const string ESTIMATEDVALUES_TRAINING_SERIES_NAME = "Estimated Class Values (training)"; 36 private const string ESTIMATEDVALUES_TEST_SERIES_NAME = "Estimated Class Values (test)"; 36 37 37 38 public new IClassificationSolution Content { 38 39 get { return (IClassificationSolution)base.Content; } 39 set { 40 base.Content = value; 41 } 40 set { base.Content = value; } 42 41 } 43 42 44 pr ivateStringConvertibleMatrixView matrixView;43 protected StringConvertibleMatrixView matrixView; 45 44 46 45 public ClassificationSolutionEstimatedClassValuesView() … … 80 79 } 81 80 82 pr ivatevoid UpdateEstimatedValues() {81 protected virtual void UpdateEstimatedValues() { 83 82 if (InvokeRequired) Invoke((Action)UpdateEstimatedValues); 84 83 else { 85 DoubleMatrix matrix = null;84 StringMatrix matrix = null; 86 85 if (Content != null) { 87 double[,] values = new double[Content.ProblemData.Dataset.Rows, 2];86 string[,] values = new string[Content.ProblemData.Dataset.Rows, 5]; 88 87 89 double[] target = Content.ProblemData.Dataset.Get VariableValues(Content.ProblemData.TargetVariable);88 double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray(); 90 89 double[] estimated = Content.EstimatedClassValues.ToArray(); 91 90 for (int row = 0; row < target.Length; row++) { 92 values[row, 0] = target[row]; 93 values[row, 1] = estimated[row]; 91 values[row, 0] = row.ToString(); 92 values[row, 1] = target[row].ToString(); 93 values[row, 2] = estimated[row].ToString(); 94 94 } 95 95 96 matrix = new DoubleMatrix(values); 97 matrix.ColumnNames = new string[] { TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME }; 96 var estimatedTraining = Content.EstimatedTrainingClassValues.GetEnumerator(); 97 estimatedTraining.MoveNext(); 98 foreach (var trainingRow in Content.ProblemData.TrainingIndizes) { 99 values[trainingRow, 3] = estimatedTraining.Current.ToString(); 100 estimatedTraining.MoveNext(); 101 } 102 var estimatedTest = Content.EstimatedTestClassValues.GetEnumerator(); 103 estimatedTest.MoveNext(); 104 foreach (var testRow in Content.ProblemData.TestIndizes) { 105 values[testRow, 4] = estimatedTest.Current.ToString(); 106 estimatedTest.MoveNext(); 107 } 108 109 matrix = new StringMatrix(values); 110 matrix.ColumnNames = new string[] { "Id", TARGETVARIABLE_SERIES_NAME, ESTIMATEDVALUES_SERIES_NAME, ESTIMATEDVALUES_TRAINING_SERIES_NAME, ESTIMATEDVALUES_TEST_SERIES_NAME }; 111 matrix.SortableView = true; 98 112 } 99 113 matrixView.Content = matrix; -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs
r5975 r6760 28 28 using System.Windows.Forms.DataVisualization.Charting; 29 29 using HeuristicLab.Common; 30 using HeuristicLab.Core.Views;31 30 using HeuristicLab.MainForm; 32 31 using HeuristicLab.MainForm.WindowsForms; … … 34 33 [View("ROC Curves")] 35 34 [Content(typeof(IDiscriminantFunctionClassificationSolution))] 36 public partial class DiscriminantFunctionClassificationRocCurvesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {35 public partial class DiscriminantFunctionClassificationRocCurvesView : DataAnalysisSolutionEvaluationView { 37 36 private const string xAxisTitle = "False Positive Rate"; 38 37 private const string yAxisTitle = "True Positive Rate"; … … 108 107 109 108 double[] estimatedValues = Content.GetEstimatedValues(rows).ToArray(); 110 double[] targetClassValues = Content.ProblemData.Dataset.Get EnumeratedVariableValues(Content.ProblemData.TargetVariable, rows).ToArray();109 double[] targetClassValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable, rows).ToArray(); 111 110 double minThreshold = estimatedValues.Min(); 112 111 double maxThreshold = estimatedValues.Max(); -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionEstimatedClassValuesView.cs
r5975 r6760 22 22 using System.Linq; 23 23 using System.Windows.Forms; 24 using HeuristicLab.Core.Views;25 24 using HeuristicLab.Data; 26 using HeuristicLab.Data.Views;27 25 using HeuristicLab.MainForm; 28 26 using HeuristicLab.MainForm.WindowsForms; … … 31 29 [View("Estimated Class Values")] 32 30 [Content(typeof(IDiscriminantFunctionClassificationSolution))] 33 public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {31 public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ClassificationSolutionEstimatedClassValuesView { 34 32 private const string TargetClassValuesSeriesname = "TargetVariable"; 35 33 private const string EstimatedClassValuesSeriesName = "EstimatedClassValues"; … … 38 36 public new IDiscriminantFunctionClassificationSolution Content { 39 37 get { return (IDiscriminantFunctionClassificationSolution)base.Content; } 40 set { 41 base.Content = value; 42 } 38 set { base.Content = value; } 43 39 } 44 45 private StringConvertibleMatrixView matrixView;46 40 47 41 public DiscriminantFunctionClassificationSolutionEstimatedClassValuesView() 48 42 : base() { 49 43 InitializeComponent(); 50 matrixView = new StringConvertibleMatrixView();51 matrixView.ShowRowsAndColumnsTextBox = false;52 matrixView.ShowStatisticalInformation = false;53 matrixView.Dock = DockStyle.Fill;54 this.Controls.Add(matrixView);55 44 } 56 45 57 #region events 58 protected override void RegisterContentEvents() { 59 base.RegisterContentEvents(); 60 Content.ModelChanged += new EventHandler(Content_ModelChanged); 61 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 62 } 63 64 protected override void DeregisterContentEvents() { 65 base.DeregisterContentEvents(); 66 Content.ModelChanged -= new EventHandler(Content_ModelChanged); 67 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged); 68 } 69 70 private void Content_ProblemDataChanged(object sender, EventArgs e) { 71 OnContentChanged(); 72 } 73 74 private void Content_ModelChanged(object sender, EventArgs e) { 75 OnContentChanged(); 76 } 77 78 protected override void OnContentChanged() { 79 base.OnContentChanged(); 80 UpdateEstimatedValues(); 81 } 82 83 private void UpdateEstimatedValues() { 46 protected override void UpdateEstimatedValues() { 84 47 if (InvokeRequired) Invoke((Action)UpdateEstimatedValues); 85 48 else { 86 DoubleMatrix matrix = null;49 StringMatrix matrix = null; 87 50 if (Content != null) { 88 double[,] values = new double[Content.ProblemData.Dataset.Rows, 3];51 string[,] values = new string[Content.ProblemData.Dataset.Rows, 4]; 89 52 90 double[] target = Content.ProblemData.Dataset.Get VariableValues(Content.ProblemData.TargetVariable);53 double[] target = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray(); 91 54 double[] estimatedClassValues = Content.EstimatedClassValues.ToArray(); 92 55 double[] estimatedValues = Content.EstimatedValues.ToArray(); 93 56 for (int row = 0; row < target.Length; row++) { 94 values[row, 0] = target[row]; 95 values[row, 1] = estimatedClassValues[row]; 96 values[row, 2] = estimatedValues[row]; 57 values[row, 0] = row.ToString(); 58 values[row, 1] = target[row].ToString(); 59 values[row, 2] = estimatedClassValues[row].ToString(); 60 values[row, 3] = estimatedValues[row].ToString(); 97 61 } 98 62 99 matrix = new DoubleMatrix(values); 100 matrix.ColumnNames = new string[] { TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName }; 63 matrix = new StringMatrix(values); 64 matrix.ColumnNames = new string[] { "Id", TargetClassValuesSeriesname, EstimatedClassValuesSeriesName, EstimatedValuesSeriesName }; 65 matrix.SortableView = true; 101 66 } 102 67 matrixView.Content = matrix; 103 68 } 104 69 } 105 #endregion106 70 } 107 71 } -
branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs
r5975 r6760 27 27 using System.Windows.Forms.DataVisualization.Charting; 28 28 using HeuristicLab.Common; 29 using HeuristicLab.Core.Views;30 29 using HeuristicLab.MainForm; 31 30 using HeuristicLab.MainForm.WindowsForms; … … 33 32 namespace HeuristicLab.Problems.DataAnalysis.Views { 34 33 [View("Classification Threshold")] 35 [Content(typeof(IDiscriminantFunctionClassificationSolution), true)]36 public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {34 [Content(typeof(IDiscriminantFunctionClassificationSolution), false)] 35 public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : DataAnalysisSolutionEvaluationView { 37 36 private const double TrainingAxisValue = 0.0; 38 37 private const double TestAxisValue = 10.0; … … 136 135 private void FillSeriesWithDataPoints(Series series) { 137 136 List<double> estimatedValues = Content.EstimatedValues.ToList(); 137 var targetValues = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToList(); 138 138 139 foreach (int row in Content.ProblemData.TrainingIndizes) { 139 140 double estimatedValue = estimatedValues[row]; 140 double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable,row];141 double targetValue = targetValues[row]; 141 142 if (targetValue.IsAlmost((double)series.Tag)) { 142 143 double jitterValue = random.NextDouble() * 2.0 - 1.0; … … 151 152 foreach (int row in Content.ProblemData.TestIndizes) { 152 153 double estimatedValue = estimatedValues[row]; 153 double targetValue = Content.ProblemData.Dataset[Content.ProblemData.TargetVariable,row];154 if (targetValue == (double)series.Tag) {154 double targetValue = targetValues[row]; 155 if (targetValue.IsAlmost((double)series.Tag)) { 155 156 double jitterValue = random.NextDouble() * 2.0 - 1.0; 156 157 DataPoint point = new DataPoint();
Note: See TracChangeset
for help on using the changeset viewer.