Beispiel #1
0
        public RidgeRegressionEstimator Fit(Matrix <double> x, Vector <double> y)
        {
            var(x1, y1, xMean, yMean) = CenterData(x, y);
            (x, y) = (x1, y1);
            if (Method == RidgeRegressionMethod.Automatic)
            {
                // TODO: implement some logic here
                Method = RidgeRegressionMethod.LSQR;
            }
            Vector <double> w;

            if (Method == RidgeRegressionMethod.LSQR)
            {
                // TODO: make benchmark with sparse matrices.
                w = Lsqr(x, y, Alpha);

                if (Intercept)
                {
                    var intercept = GetIntercept(xMean, yMean, w);
                    var w1        = Vector <double> .Build.Dense(w.Count + 1);

                    w.CopySubVectorTo(w1, 0, 1, w.Count);
                    w1[0] = intercept;
                    w     = w1;
                }
            }
            else
            {
                throw new NotSupportedException();
            }
            return(new RidgeRegressionEstimator(this, w));
        }
Beispiel #2
0
 public RidgeRegression(bool intercept = true, double alpha = 1.0, RidgeRegressionMethod method = RidgeRegressionMethod.Automatic)
 {
     Intercept = intercept;
     Alpha     = alpha;
     Method    = method;
 }