Accord.Tests.Statistics.LogarithmRegressionTest.LogarithmRegressionRegressTest C# (CSharp) Method

LogarithmRegressionRegressTest() private method

private LogarithmRegressionRegressTest ( ) : void
return void
        public void LogarithmRegressionRegressTest()
        {
            // This is the same data from the example available at
            // http://mathbits.com/MathBits/TISection/Statistics2/logarithmic.htm

            // Declare your inputs and output data
            double[] inputs = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            double[] outputs = { 6, 9.5, 13, 15, 16.5, 17.5, 18.5, 19, 19.5, 19.7, 19.8 };

            // Transform inputs to logarithms
            double[] logx = Matrix.Log(inputs);

            // Compute a simple linear regression
            var lr = new SimpleLinearRegression();

            // Compute with the log-transformed data
            double error = lr.Regress(logx, outputs);

            // Get an expression representing the learned regression model
            // We just have to remember that 'x' will actually mean 'log(x)'
            string result = lr.ToString("N4", CultureInfo.InvariantCulture);

            // Result will be "y(x) = 6.1082x + 6.0993"

            Assert.AreEqual(2.8760006026675797, error);
            Assert.AreEqual(6.1081800414945704, lr.Slope);
            Assert.AreEqual(6.0993411396126653, lr.Intercept);
            Assert.AreEqual("y(x) = 6.1082x + 6.0993", result);
        }