示例#1
0
        public void test_AdjustedR2_performance_10000_observations_2_variables()
        {
            Stopwatch     sw   = new Stopwatch();
            Random        rand = new Random();
            List <double> y    = new List <double>();
            List <double> x1   = new List <double>();
            List <double> x2   = new List <double>();

            for (int i = 0; i < 10000; i++)
            {
                y.Add(rand.Next(0, 10));
                x1.Add(rand.Next(0, 10));
                x2.Add(rand.Next(0, 10));
            }

            List <List <double> > expl = new List <List <double> >()
            {
                x1, x2
            };

            sw.Start();
            ModelFit.AdjustedR2(y, expl);
            sw.Stop();
            Console.WriteLine("Took " + sw.ElapsedMilliseconds + " milliseconds");
            Assert.LessOrEqual(sw.ElapsedMilliseconds, 1000);
        }
示例#2
0
        public void test_AdjustedR2_return_correct_result()
        {
            /*Calculated with R, lm (list ~ list2 + list3) produces an adjusted R2 value of 0.2081.*/
            List <List <double> > explanatory = new List <List <double> >()
            {
                list2, list3
            };

            Assert.AreEqual(0.2081, Math.Round(ModelFit.AdjustedR2(list, explanatory), 4));
        }
示例#3
0
        public void test_AdjustedR2_throws_MathError_Different_Sized_Lists()
        {
            /*Different sized lists throw MathError*/
            List <double> y = new List <double>()
            {
                2, 3
            };

            List <List <double> > lists = new List <List <double> >()
            {
                list, list2, list3
            };

            Assert.Throws <MathError>(() => ModelFit.AdjustedR2(y, lists));
        }
示例#4
0
        public void test_AdjustedR2_throws_MathError()
        {
            /* Trying to get coefficients for invalid matrix should produce ArgumentException.*/
            List <double> y  = new List <double>();
            List <double> x1 = new List <double>();
            List <double> x2 = new List <double>();
            List <double> x3 = new List <double>();

            for (int i = 0; i < 100; i++)
            {
                y.Add(1);
                x1.Add(1);
                x2.Add(1);
                x3.Add(1);
            }

            List <List <double> > expl = new List <List <double> >()
            {
                x1, x2, x3
            };

            Assert.Throws <MathError>(() => ModelFit.AdjustedR2(y, expl));
        }
示例#5
0
 /// <summary>
 /// Calculates adjusted coefficient of determination value for a fitted model.
 /// </summary>
 /// <param name="y">List containing the response values.</param>
 /// <param name="x">List containing lists for all explanatory variables.</param>
 /// <returns>Coefficient of determination adjusted with number of explanatory variables
 /// and observations.</returns>
 /// <exception cref="MathError">Thrown when parameter lists are of different length.</exception>
 /// <exception cref="ArgumentException">Thrown when matrix created from parameters is not valid to fit least square points.</exception>
 public double EvaluateFitness(Model m)
 {
     return(ModelFit.AdjustedR2(m.getYVar().values, m.getXVariableLists()));
 }