Changeset 15103 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.cs
- Timestamp:
- 07/01/17 08:23:22 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/RandomForestModelView.cs
r14345 r15103 19 19 */ 20 20 #endregion 21 21 using System; 22 22 using System.Drawing; 23 using HeuristicLab.Common; 23 24 using HeuristicLab.MainForm; 24 25 using HeuristicLab.Problems.DataAnalysis; … … 69 70 else { 70 71 var idx = (int)listBox.SelectedItem; 71 idx -= 1; 72 var rfModel = Content.Model as RandomForestModel; 73 var regProblemData = Content.ProblemData as IRegressionProblemData; 74 var classProblemData = Content.ProblemData as IClassificationProblemData; 75 if (rfModel != null) { 76 if (idx < 0 || idx >= rfModel.NumberOfTrees) return; 77 if (regProblemData != null) { 78 var syModel = new SymbolicRegressionModel(regProblemData.TargetVariable, rfModel.ExtractTree(idx), 79 new SymbolicDataAnalysisExpressionTreeLinearInterpreter()); 80 viewHost.Content = syModel.CreateRegressionSolution(regProblemData); 81 } else if (classProblemData != null) { 82 var syModel = new SymbolicDiscriminantFunctionClassificationModel(classProblemData.TargetVariable, rfModel.ExtractTree(idx), 83 new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), new NormalDistributionCutPointsThresholdCalculator()); 84 syModel.RecalculateModelParameters(classProblemData, classProblemData.TrainingIndices); 85 viewHost.Content = syModel.CreateClassificationSolution(classProblemData); 86 } 87 } 72 viewHost.Content = CreateModel(idx); 88 73 } 74 } 75 76 private void listBox_DoubleClick(object sender, System.EventArgs e) { 77 var selectedItem = listBox.SelectedItem; 78 if (selectedItem == null) return; 79 var idx = (int)listBox.SelectedItem; 80 MainFormManager.MainForm.ShowContent(CreateModel(idx)); 81 } 82 83 private IContent CreateModel(int idx) { 84 idx -= 1; 85 var rfModel = Content.Model as RandomForestModel; 86 if (rfModel == null) return null; 87 var regProblemData = Content.ProblemData as IRegressionProblemData; 88 var classProblemData = Content.ProblemData as IClassificationProblemData; 89 if (idx < 0 || idx >= rfModel.NumberOfTrees) 90 return null; 91 if (regProblemData != null) { 92 var syModel = new SymbolicRegressionModel(regProblemData.TargetVariable, rfModel.ExtractTree(idx), 93 new SymbolicDataAnalysisExpressionTreeLinearInterpreter()); 94 return syModel.CreateRegressionSolution(regProblemData); 95 } else if (classProblemData != null) { 96 var syModel = new SymbolicDiscriminantFunctionClassificationModel(classProblemData.TargetVariable, rfModel.ExtractTree(idx), 97 new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), new NormalDistributionCutPointsThresholdCalculator()); 98 syModel.RecalculateModelParameters(classProblemData, classProblemData.TrainingIndices); 99 return syModel.CreateClassificationSolution(classProblemData); 100 } else throw new InvalidProgramException(); 89 101 } 90 102 }
Note: See TracChangeset
for help on using the changeset viewer.