public static void Run(IRegressionProblemData problemData, IEnumerable <string> allowedInputVariables,
                               string svmType, string kernelType, double cost, double nu, double gamma, double epsilon, int degree,
                               out ISupportVectorMachineModel model, out int nSv)
        {
            var               dataset        = problemData.Dataset;
            string            targetVariable = problemData.TargetVariable;
            IEnumerable <int> rows           = problemData.TrainingIndices;

            svm_parameter parameter = new svm_parameter {
                svm_type    = GetSvmType(svmType),
                kernel_type = GetKernelType(kernelType),
                C           = cost,
                nu          = nu,
                gamma       = gamma,
                p           = epsilon,
                cache_size  = 500,
                probability = 0,
                eps         = 0.001,
                degree      = degree,
                shrinking   = 1,
                coef0       = 0
            };

            svm_problem    problem        = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows);
            RangeTransform rangeTransform = RangeTransform.Compute(problem);
            svm_problem    scaledProblem  = rangeTransform.Scale(problem);
            var            svmModel       = svm.svm_train(scaledProblem, parameter);

            nSv = svmModel.SV.Length;

            model = new SupportVectorMachineModel(svmModel, rangeTransform, targetVariable, allowedInputVariables);
        }
 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner)
     : base(original, cloner)
 {
     // only using a shallow copy here! (gkronber)
     this.model                 = original.model;
     this.rangeTransform        = original.rangeTransform;
     this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
     if (original.classValues != null)
     {
         this.classValues = (double[])original.classValues.Clone();
     }
 }
示例#3
0
        public static void Run(IClassificationProblemData problemData, IEnumerable <string> allowedInputVariables,
                               int svmType, int kernelType, double cost, double nu, double gamma, int degree,
                               out ISupportVectorMachineModel model, out int nSv)
        {
            var               dataset        = problemData.Dataset;
            string            targetVariable = problemData.TargetVariable;
            IEnumerable <int> rows           = problemData.TrainingIndices;

            svm_parameter parameter = new svm_parameter {
                svm_type    = svmType,
                kernel_type = kernelType,
                C           = cost,
                nu          = nu,
                gamma       = gamma,
                cache_size  = 500,
                probability = 0,
                eps         = 0.001,
                degree      = degree,
                shrinking   = 1,
                coef0       = 0
            };

            var weightLabels = new List <int>();
            var weights      = new List <double>();

            foreach (double c in problemData.ClassValues)
            {
                double wSum = 0.0;
                foreach (double otherClass in problemData.ClassValues)
                {
                    if (!c.IsAlmost(otherClass))
                    {
                        wSum += problemData.GetClassificationPenalty(c, otherClass);
                    }
                }
                weightLabels.Add((int)c);
                weights.Add(wSum);
            }
            parameter.weight_label = weightLabels.ToArray();
            parameter.weight       = weights.ToArray();

            svm_problem    problem        = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows);
            RangeTransform rangeTransform = RangeTransform.Compute(problem);
            svm_problem    scaledProblem  = rangeTransform.Scale(problem);
            var            svmModel       = svm.svm_train(scaledProblem, parameter);

            nSv = svmModel.SV.Length;

            model = new SupportVectorMachineModel(svmModel, rangeTransform, targetVariable, allowedInputVariables, problemData.ClassValues);
        }
 public SupportVectorClassificationSolution(SupportVectorMachineModel model, IClassificationProblemData problemData)
     : base(model, problemData)
 {
 }
 public SupportVectorRegressionSolution(SupportVectorMachineModel model, IRegressionProblemData problemData)
     : base(model, problemData)
 {
 }
 public SupportVectorRegressionSolution(SupportVectorMachineModel model, IRegressionProblemData problemData)
   : base(model, problemData) {
 }
 public SupportVectorClassificationSolution(SupportVectorMachineModel model, IClassificationProblemData problemData)
   : base(model, problemData) {
 }
 private SupportVectorMachineModel(SupportVectorMachineModel original, Cloner cloner)
   : base(original, cloner) {
   // only using a shallow copy here! (gkronber)
   this.model = original.model;
   this.rangeTransform = original.rangeTransform;
   this.allowedInputVariables = (string[])original.allowedInputVariables.Clone();
   if (original.classValues != null)
     this.classValues = (double[])original.classValues.Clone();
 }