public void RegressTest3()
{
// We will try to model a plane as an equation in the form
// "ax + by + c = z". We have two input variables (x and y)
// and we will be trying to find two parameters a and b and
// an intercept term c.
// Create a multiple linear regression for two input and an intercept
var target = new MultipleLinearRegression(2, true);
// Now suppose you have some points
double[][] inputs =
{
new double[] { 1, 1 },
new double[] { 0, 1 },
new double[] { 1, 0 },
new double[] { 0, 0 },
};
// located in the same Z (z = 1)
double[] outputs = { 1, 1, 1, 1 };
// Now we will try to fit a regression model
double error = target.Regress(inputs, outputs);
Assert.AreEqual(2, target.NumberOfInputs);
Assert.AreEqual(1, target.NumberOfOutputs);
// As result, we will be given the following:
double a = target.Coefficients[0]; // a = 0
double b = target.Coefficients[1]; // b = 0
double c = target.Coefficients[2]; // c = 1
// This is the plane described by the equation
// ax + by + c = z => 0x + 0y + 1 = z => 1 = z.
Assert.AreEqual(0.0, a, 1e-6);
Assert.AreEqual(0.0, b, 1e-6);
Assert.AreEqual(1.0, c, 1e-6);
Assert.AreEqual(0.0, error, 1e-6);
double[] expected = target.Compute(inputs);
double[] actual = target.Transform(inputs);
Assert.IsTrue(expected.IsEqual(actual, 1e-10));
double r = target.CoefficientOfDetermination(inputs, outputs);
Assert.AreEqual(1.0, r);
}