// BackwardsCompatibility3.4 #region Backwards compatible code, remove with 3.5 public static SupportVectorClassificationSolution CreateSupportVectorClassificationSolution(IClassificationProblemData problemData, IEnumerable <string> allowedInputVariables, int svmType, int kernelType, double cost, double nu, double gamma, int degree, out double trainingAccuracy, out double testAccuracy, out int nSv) { ISupportVectorMachineModel model; Run(problemData, allowedInputVariables, svmType, kernelType, cost, nu, gamma, degree, out model, out nSv); var solution = new SupportVectorClassificationSolution((SupportVectorMachineModel)model, (IClassificationProblemData)problemData.Clone()); trainingAccuracy = solution.TrainingAccuracy; testAccuracy = solution.TestAccuracy; return(solution); }
protected override void Run() { IClassificationProblemData problemData = Problem.ProblemData; IEnumerable <string> selectedInputVariables = problemData.AllowedInputVariables; int nSv; ISupportVectorMachineModel model; Run(problemData, selectedInputVariables, GetSvmType(SvmType.Value), GetKernelType(KernelType.Value), Cost.Value, Nu.Value, Gamma.Value, Degree.Value, out model, out nSv); if (CreateSolution) { var solution = new SupportVectorClassificationSolution((SupportVectorMachineModel)model, (IClassificationProblemData)problemData.Clone()); Results.Add(new Result("Support vector classification solution", "The support vector classification solution.", solution)); } { // calculate classification metrics // calculate regression model metrics var ds = problemData.Dataset; var trainRows = problemData.TrainingIndices; var testRows = problemData.TestIndices; var yTrain = ds.GetDoubleValues(problemData.TargetVariable, trainRows); var yTest = ds.GetDoubleValues(problemData.TargetVariable, testRows); var yPredTrain = model.GetEstimatedClassValues(ds, trainRows); var yPredTest = model.GetEstimatedClassValues(ds, testRows); OnlineCalculatorError error; var trainAccuracy = OnlineAccuracyCalculator.Calculate(yPredTrain, yTrain, out error); if (error != OnlineCalculatorError.None) { trainAccuracy = double.MaxValue; } var testAccuracy = OnlineAccuracyCalculator.Calculate(yPredTest, yTest, out error); if (error != OnlineCalculatorError.None) { testAccuracy = double.MaxValue; } Results.Add(new Result("Accuracy (training)", "The mean of squared errors of the SVR solution on the training partition.", new DoubleValue(trainAccuracy))); Results.Add(new Result("Accuracy (test)", "The mean of squared errors of the SVR solution on the test partition.", new DoubleValue(testAccuracy))); Results.Add(new Result("Number of support vectors", "The number of support vectors of the SVR solution.", new IntValue(nSv))); } }
private SupportVectorClassificationSolution(SupportVectorClassificationSolution original, Cloner cloner) : base(original, cloner) { }
private SupportVectorClassificationSolution(SupportVectorClassificationSolution original, Cloner cloner) : base(original, cloner) { }