Changeset 7430 for trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs
- Timestamp:
- 01/31/12 11:31:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs
r7259 r7430 113 113 IClassificationProblemData problemData = Problem.ProblemData; 114 114 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; 115 var solution = CreateSupportVectorClassificationSolution(problemData, selectedInputVariables, SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value); 115 double trainingAccuracy, testAccuracy; 116 int nSv; 117 var solution = CreateSupportVectorClassificationSolution(problemData, selectedInputVariables, 118 SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, 119 out trainingAccuracy, out testAccuracy, out nSv); 116 120 117 121 Results.Add(new Result("Support vector classification solution", "The support vector classification solution.", solution)); 122 Results.Add(new Result("Training accuracy", "The accuracy of the SVR solution on the training partition.", new DoubleValue(trainingAccuracy))); 123 Results.Add(new Result("Test R²", "The accuracy of the SVR solution on the test partition.", new DoubleValue(testAccuracy))); 124 Results.Add(new Result("Number of support vectors", "The number of support vectors of the SVR solution.", new IntValue(nSv))); 118 125 } 119 126 120 127 public static SupportVectorClassificationSolution CreateSupportVectorClassificationSolution(IClassificationProblemData problemData, IEnumerable<string> allowedInputVariables, 121 string svmType, string kernelType, double cost, double nu, double gamma) { 128 string svmType, string kernelType, double cost, double nu, double gamma, 129 out double trainingAccuracy, out double testAccuracy, out int nSv) { 122 130 Dataset dataset = problemData.Dataset; 123 131 string targetVariable = problemData.TargetVariable; … … 148 156 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem); 149 157 SVM.Problem scaledProblem = SVM.Scaling.Scale(rangeTransform, problem); 150 var model = new SupportVectorMachineModel(SVM.Training.Train(scaledProblem, parameter), rangeTransform, targetVariable, allowedInputVariables, problemData.ClassValues); 158 var svmModel = SVM.Training.Train(scaledProblem, parameter); 159 var model = new SupportVectorMachineModel(svmModel, rangeTransform, targetVariable, allowedInputVariables, problemData.ClassValues); 160 var solution = new SupportVectorClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 151 161 152 return new SupportVectorClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 162 nSv = svmModel.SupportVectorCount; 163 trainingAccuracy = solution.TrainingAccuracy; 164 testAccuracy = solution.TestAccuracy; 165 166 return solution; 153 167 } 154 168 #endregion
Note: See TracChangeset
for help on using the changeset viewer.