Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/31/12 11:31:59 (13 years ago)
Author:
gkronber
Message:

#1750 added results (accuracy training/test & number of support vectors) to SVC.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs

    r7259 r7430  
    113113      IClassificationProblemData problemData = Problem.ProblemData;
    114114      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);
    116120
    117121      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)));
    118125    }
    119126
    120127    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) {
    122130      Dataset dataset = problemData.Dataset;
    123131      string targetVariable = problemData.TargetVariable;
     
    148156      SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem);
    149157      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());
    151161
    152       return new SupportVectorClassificationSolution(model, (IClassificationProblemData)problemData.Clone());
     162      nSv = svmModel.SupportVectorCount;
     163      trainingAccuracy = solution.TrainingAccuracy;
     164      testAccuracy = solution.TestAccuracy;
     165
     166      return solution;
    153167    }
    154168    #endregion
Note: See TracChangeset for help on using the changeset viewer.