コード例 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text != "" && TextBox2.Text != "")
            {
                var xIn = TextBox1.Text.Split(',');
                var yIn = TextBox2.Text.Split(',');

                List <decimal> x;
                List <decimal> y;

                try
                {
                    x = Array.ConvertAll(xIn, decimal.Parse).ToList();
                    y = Array.ConvertAll(yIn, decimal.Parse).ToList();
                }
                catch
                {
                    Label1.Text = "Could not convert the sequence into an array.";

                    return;
                }

                var res = LinearModels.LinearRegression(x, y);
                lblLinearEq.Text = res.ToString();
                lblRVal.Text     = res.R.ToString(CultureInfo.InvariantCulture);
                lblRSqVal.Text   = res.R2.ToString(CultureInfo.InvariantCulture);
                lblRegCoeff.Text = res.B.ToString(CultureInfo.InvariantCulture);
                lblIntr.Text     = res.Intercept.ToString(CultureInfo.InvariantCulture);
            }
            else
            {
                Label1.Text = "No sequence was entered.";
            }
        }
コード例 #2
0
        public void PredictionTest()
        {
            var x = new List <decimal> {
                1, 2, 3, 4, 5, 6, 7
            };
            var y = new List <decimal> {
                2, 4, 6, 8, 10, 12, 14
            };
            var res = LinearModels.LinearRegression(x, y);
            var b   = res.Predict(10);

            Assert.AreEqual(b, 20);
        }