// BackwardsCompatibility3.4 #region Backwards compatible code, remove with 3.5 // for compatibility with old API public static SupportVectorRegressionSolution CreateSupportVectorRegressionSolution( IRegressionProblemData problemData, IEnumerable <string> allowedInputVariables, string svmType, string kernelType, double cost, double nu, double gamma, double epsilon, int degree, out double trainingR2, out double testR2, out int nSv) { ISupportVectorMachineModel model; Run(problemData, allowedInputVariables, svmType, kernelType, cost, nu, gamma, epsilon, degree, out model, out nSv); var solution = new SupportVectorRegressionSolution((SupportVectorMachineModel)model, (IRegressionProblemData)problemData.Clone()); trainingR2 = solution.TrainingRSquared; testR2 = solution.TestRSquared; return(solution); }
private SupportVectorRegressionSolution(SupportVectorRegressionSolution original, Cloner cloner) : base(original, cloner) { }
protected override void Run() { IRegressionProblemData problemData = Problem.ProblemData; IEnumerable <string> selectedInputVariables = problemData.AllowedInputVariables; int nSv; ISupportVectorMachineModel model; Run(problemData, selectedInputVariables, SvmType.Value, KernelType.Value, Cost.Value, Nu.Value, Gamma.Value, Epsilon.Value, Degree.Value, out model, out nSv); if (CreateSolution) { var solution = new SupportVectorRegressionSolution((SupportVectorMachineModel)model, (IRegressionProblemData)problemData.Clone()); Results.Add(new Result("Support vector regression solution", "The support vector regression solution.", solution)); } Results.Add(new Result("Number of support vectors", "The number of support vectors of the SVR solution.", new IntValue(nSv))); { // 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.GetEstimatedValues(ds, trainRows).ToArray(); var yPredTest = model.GetEstimatedValues(ds, testRows).ToArray(); OnlineCalculatorError error; var trainMse = OnlineMeanSquaredErrorCalculator.Calculate(yPredTrain, yTrain, out error); if (error != OnlineCalculatorError.None) { trainMse = double.MaxValue; } var testMse = OnlineMeanSquaredErrorCalculator.Calculate(yPredTest, yTest, out error); if (error != OnlineCalculatorError.None) { testMse = double.MaxValue; } Results.Add(new Result("Mean squared error (training)", "The mean of squared errors of the SVR solution on the training partition.", new DoubleValue(trainMse))); Results.Add(new Result("Mean squared error (test)", "The mean of squared errors of the SVR solution on the test partition.", new DoubleValue(testMse))); var trainMae = OnlineMeanAbsoluteErrorCalculator.Calculate(yPredTrain, yTrain, out error); if (error != OnlineCalculatorError.None) { trainMae = double.MaxValue; } var testMae = OnlineMeanAbsoluteErrorCalculator.Calculate(yPredTest, yTest, out error); if (error != OnlineCalculatorError.None) { testMae = double.MaxValue; } Results.Add(new Result("Mean absolute error (training)", "The mean of absolute errors of the SVR solution on the training partition.", new DoubleValue(trainMae))); Results.Add(new Result("Mean absolute error (test)", "The mean of absolute errors of the SVR solution on the test partition.", new DoubleValue(testMae))); var trainRelErr = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(yPredTrain, yTrain, out error); if (error != OnlineCalculatorError.None) { trainRelErr = double.MaxValue; } var testRelErr = OnlineMeanAbsolutePercentageErrorCalculator.Calculate(yPredTest, yTest, out error); if (error != OnlineCalculatorError.None) { testRelErr = double.MaxValue; } Results.Add(new Result("Average relative error (training)", "The mean of relative errors of the SVR solution on the training partition.", new DoubleValue(trainRelErr))); Results.Add(new Result("Average relative error (test)", "The mean of relative errors of the SVR solution on the test partition.", new DoubleValue(testRelErr))); } }
private SupportVectorRegressionSolution(SupportVectorRegressionSolution original, Cloner cloner) : base(original, cloner) { }