Beispiel #1
0
        public static void SolveRegressionProblem()
        {
            SVR svr = new SVR();


            List <KeyValuePair <double[], double> > data = new List <KeyValuePair <double[], double> >();

            for (int i = 0; i < 100; ++i)
            {
                double[] x = new double[2];
                x[0] = i / 50.0;
                x[1] = (i + 1) / 100.0;
                double y = Math.Sin((x[0] + x[1]) * Math.PI);
                data.Add(new KeyValuePair <double[], double>(x, y));
            }

            var tuple      = TrainTestSplit(data);
            var train_data = tuple.Item1;
            var test_data  = tuple.Item2;

            var metric = svr.Fit(train_data, test_data);

            Console.WriteLine("Train MSE: {0}, Test MSE: {1}", metric.TrainMSE, metric.TestMSE);

            foreach (KeyValuePair <double[], double> entry in test_data.GetRange(0, 10))
            {
                double[] x      = entry.Key;
                double   y      = entry.Value;
                double   output = svr.Predict(x);
                Console.WriteLine("Predicted: {0} Actual: {1}", output, y);
            }
        }
Beispiel #2
0
        public object Clone()
        {
            SVR clone = new SVR();

            clone.Copy(this);

            return(clone);
        }
Beispiel #3
0
 public void Copy(SVR rhs)
 {
     _param           = rhs._param == null ? null : (SVMParam)rhs._param.Clone();
     _crossValidation = rhs._crossValidation;
     _model           = rhs._model == null ? null : (SVMModel)rhs._model.Clone();
     if (_model != null)
     {
         _model.Param = _param;
     }
     _isQuiet = rhs._isQuiet;
 }