public void RSquaredTest() { var actual = new Matrix(100, 1); var expected = new Matrix(100, 1); actual.InRandomize(0.25, 0.75); expected.InRandomize(0.25, 0.75); var metric = new RSquared(); var e = metric.Evaluate(actual, expected); var actualAvg = actual.Average(); var num = 0.0; var denom = 0.0; for (var i = 0; i < actual.Rows; i++) { for (var j = 0; j < actual.Columns; j++) { num += Math.Pow(expected[i, j] - actual[i, j], 2); } } for (var i = 0; i < actual.Rows; i++) { for (var j = 0; j < actual.Columns; j++) { denom += Math.Pow(expected[i, j] - actualAvg, 2); } } var val = num / (denom + double.Epsilon); Assert.IsTrue(Math.Abs(e - val) < 0.01, metric.Type().ToString() + " Evaluate."); }
/// <summary> /// <see cref="System.Object.GetHashCode"/> /// </summary> /// <returns>Hascode of the instance</returns> public override int GetHashCode() { int hash = 17; hash = hash * 23 + M.GetHashCode(); hash = hash * 23 + B.GetHashCode(); hash = hash * 23 + RSquared.GetHashCode(); return(hash); }
/// <summary> /// Initializes a new instance of the <see cref="LinearRegression"/>. /// </summary> /// <param name="linearReg">Linear regression.</param> /// <param name="rSquared">Regression R-squared.</param> /// <param name="regSlope">Coefficient with independent variable, slope of a straight line.</param> /// <param name="standardError">Standard error.</param> public LinearRegression(LinearReg linearReg, RSquared rSquared, LinearRegSlope regSlope, StandardError standardError) : base(linearReg, rSquared, regSlope, standardError) { LinearReg = linearReg; RSquared = rSquared; LinearRegSlope = regSlope; StandardError = standardError; Mode = ComplexIndicatorModes.Parallel; }