Changeset 11763
- Timestamp:
- 01/15/15 11:37:49 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 5 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis (added) merged: 11606-11607,11622,11643,11683-11686,11761
- Property svn:mergeinfo changed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r11623 r11763 124 124 </Compile> 125 125 <Compile Include="Implementation\Classification\ClassificationEnsembleSolution.cs" /> 126 <Compile Include="Implementation\Classification\ClassificationPerformanceMeasures.cs" /> 126 127 <Compile Include="Implementation\Classification\ClassificationProblemData.cs" /> 127 128 <Compile Include="Implementation\Classification\ClassificationProblem.cs" /> … … 178 179 <Compile Include="Interfaces\TimeSeriesPrognosis\ITimeSeriesPrognosisSolution.cs" /> 179 180 <Compile Include="OnlineCalculators\AutoCorrelationCalculator.cs" /> 181 <Compile Include="OnlineCalculators\ClassificationPerformanceMeasuresCalculator.cs" /> 180 182 <Compile Include="OnlineCalculators\DependencyCalculator\HoeffdingsDependenceCalculator.cs" /> 181 183 <Compile Include="OnlineCalculators\DependencyCalculator\PearsonsRDependenceCalculator.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r11171 r11763 36 36 protected const string ClassNamesParameterName = "ClassNames"; 37 37 protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties"; 38 protected const string PositiveClassNameParameterName = "PositiveClass"; 38 39 protected const int MaximumNumberOfClasses = 100; 39 40 protected const int InspectedRowsToDetermineTargets = 2000; … … 213 214 get { return (IFixedValueParameter<StringMatrix>)Parameters[ClassNamesParameterName]; } 214 215 } 216 public IConstrainedValueParameter<StringValue> PositiveClassNameParameter { 217 get { return (IConstrainedValueParameter<StringValue>)Parameters[PositiveClassNameParameterName]; } 218 } 215 219 public IFixedValueParameter<DoubleMatrix> ClassificationPenaltiesParameter { 216 220 get { return (IFixedValueParameter<DoubleMatrix>)Parameters[ClassificationPenaltiesParameterName]; } … … 262 266 get { return ClassNamesCache; } 263 267 } 268 269 public string PositiveClassName { 270 get { return PositiveClassNameParameter.Value.Value; } 271 set { 272 var matchingValue = PositiveClassNameParameter.ValidValues.SingleOrDefault(x => x.Value == value); 273 if (matchingValue == null) throw new ArgumentException(string.Format("{0} cannot be set as positive class.", value)); 274 PositiveClassNameParameter.Value = matchingValue; 275 } 276 } 264 277 #endregion 265 278 … … 270 283 private void AfterDeserialization() { 271 284 RegisterParameterEvents(); 285 // BackwardsCompatibility3.4 286 #region Backwards compatible code, remove with 3.5 287 if (!Parameters.ContainsKey(PositiveClassNameParameterName)) { 288 var validValues = new ItemSet<StringValue>(ClassNames.Select(s => new StringValue(s).AsReadOnly())); 289 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassNameParameterName, 290 "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)", validValues, validValues.First())); 291 } 292 #endregion 293 272 294 } 273 295 … … 307 329 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(validTargetVariableValues), target)); 308 330 Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "")); 331 Parameters.Add(new ConstrainedValueParameter<StringValue>(PositiveClassNameParameterName, "The positive class which is used for quality measure calculation (e.g., specifity, sensitivity,...)")); 309 332 Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "")); 310 333 … … 340 363 ClassNamesParameter.Value.RowNames = ClassValues.Select(s => "ClassValue: " + s); 341 364 365 PositiveClassNameParameter.ValidValues.Clear(); 366 foreach (var className in ClassNames) { 367 PositiveClassNameParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 368 } 369 342 370 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Rows = Classes; 343 371 ((IStringConvertibleMatrix)ClassificationPenaltiesParameter.Value).Columns = Classes; … … 411 439 } 412 440 private void Parameter_ValueChanged(object sender, EventArgs e) { 441 var oldPositiveClass = PositiveClassName; 442 var oldClassNames = classNamesCache; 443 var index = oldClassNames.IndexOf(oldPositiveClass); 444 413 445 classNamesCache = null; 414 446 ClassificationPenaltiesParameter.Value.RowNames = ClassNames.Select(name => "Actual " + name); 415 447 ClassificationPenaltiesParameter.Value.ColumnNames = ClassNames.Select(name => "Estimated " + name); 448 449 PositiveClassNameParameter.ValidValues.Clear(); 450 foreach (var className in ClassNames) { 451 PositiveClassNameParameter.ValidValues.Add(new StringValue(className).AsReadOnly()); 452 } 453 PositiveClassNameParameter.Value = PositiveClassNameParameter.ValidValues.ElementAt(index); 454 416 455 OnChanged(); 417 456 } … … 435 474 if (!newClassValues.SequenceEqual(ClassValues)) { 436 475 errorMessage = errorMessage + string.Format("The class values differ in the provided classification problem data."); 437 return false; 476 returnValue = false; 477 } 478 479 var newPositivieClassName = classificationProblemData.PositiveClassName; 480 if (newPositivieClassName != PositiveClassName) { 481 errorMessage = errorMessage + string.Format("The positive class differs in the provided classification problem data."); 482 returnValue = false; 438 483 } 439 484 … … 452 497 ClassNamesParameter.Value[i, 0] = classificationProblemData.ClassNames.ElementAt(i); 453 498 499 PositiveClassName = classificationProblemData.PositiveClassName; 500 454 501 for (int i = 0; i < Classes; i++) { 455 502 for (int j = 0; j < Classes; j++) { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r11171 r11763 34 34 private const string TrainingNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (training)"; 35 35 private const string TestNormalizedGiniCoefficientResultName = "Normalized Gini Coefficient (test)"; 36 private const string ClassificationPerformanceMeasuresResultName = "Classification Performance Measures"; 36 37 37 38 public new IClassificationModel Model { … … 62 63 protected set { ((DoubleValue)this[TestNormalizedGiniCoefficientResultName].Value).Value = value; } 63 64 } 65 public ClassificationPerformanceMeasuresResultCollection ClassificationPerformanceMeasures { 66 get { return ((ClassificationPerformanceMeasuresResultCollection)this[ClassificationPerformanceMeasuresResultName].Value); } 67 protected set { (this[ClassificationPerformanceMeasuresResultName].Value) = value; } 68 } 64 69 #endregion 65 70 … … 75 80 Add(new Result(TrainingNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the training partition.", new DoubleValue())); 76 81 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 82 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 83 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", 84 new ClassificationPerformanceMeasuresResultCollection())); 77 85 } 78 86 … … 83 91 if (!this.ContainsKey(TestNormalizedGiniCoefficientResultName)) 84 92 Add(new Result(TestNormalizedGiniCoefficientResultName, "Normalized Gini coefficient of the model on the test partition.", new DoubleValue())); 93 if (!this.ContainsKey(ClassificationPerformanceMeasuresResultName)) { 94 Add(new Result(ClassificationPerformanceMeasuresResultName, @"Classification performance measures.\n 95 In a multiclass classification all misclassifications of the negative class will be treated as true negatives except on positive class estimations.", 96 new ClassificationPerformanceMeasuresResultCollection())); 97 RecalculateResults(); 98 } 85 99 } 86 100 … … 88 102 double[] estimatedTrainingClassValues = EstimatedTrainingClassValues.ToArray(); // cache values 89 103 double[] originalTrainingClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TrainingIndices).ToArray(); 104 90 105 double[] estimatedTestClassValues = EstimatedTestClassValues.ToArray(); // cache values 91 106 double[] originalTestClassValues = ProblemData.Dataset.GetDoubleValues(ProblemData.TargetVariable, ProblemData.TestIndices).ToArray(); 107 108 var positiveClassName = ProblemData.PositiveClassName; 109 double positiveClassValue = ProblemData.GetClassValue(positiveClassName); 110 ClassificationPerformanceMeasuresCalculator trainingPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue); 111 ClassificationPerformanceMeasuresCalculator testPerformanceCalculator = new ClassificationPerformanceMeasuresCalculator(positiveClassName, positiveClassValue); 92 112 93 113 OnlineCalculatorError errorState; … … 107 127 TrainingNormalizedGiniCoefficient = trainingNormalizedGini; 108 128 TestNormalizedGiniCoefficient = testNormalizedGini; 129 130 trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues); 131 if (trainingPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 132 ClassificationPerformanceMeasures.SetTrainingResults(trainingPerformanceCalculator); 133 134 testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues); 135 if (testPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 136 ClassificationPerformanceMeasures.SetTestResults(testPerformanceCalculator); 109 137 } 110 138 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationProblemData.cs
r11171 r11763 26 26 27 27 IEnumerable<string> ClassNames { get; } 28 string PositiveClassName { get; set; } 28 29 IEnumerable<double> ClassValues { get; } 29 30 int Classes { get; }
Note: See TracChangeset
for help on using the changeset viewer.