public static void RegressionChart(IList <KeyValuePair <Employee, float> > predictions, string fileName) { const int minValue = 1500; const int maxValue = 6500; PlotToFile(fileName, pl => { pl.env(minValue, maxValue, minValue, maxValue, AxesScale.Equal, AxisBox.BoxTicksLabelsAxes); pl.lab("Actual", "Predicted", "Distribution of Salary Prediction"); pl.col0(Blue); foreach (var(employee, prediction) in predictions) { var x = employee.Salary; var y = prediction; pl.poin(new double[] { x }, new double[] { y }, Dot); } var points = predictions.Select(p => ((float)p.Key.Salary, p.Value)).ToList(); StatisticsService.CalculateRegressionLine(points, minValue, maxValue, out var y1, out var y2); pl.col0(Red); pl.line(new double[] { minValue, maxValue }, new double[] { y1, y2 }); });
public void It_should_return_the_correct_result_of_a_more_complex_problem() { var points = new List <(float x, float y)> { (-2, -3), (-1, -1), (1, 2), (4, 3) }; StatisticsService.CalculateRegressionLine(points, -10, 32, out var y1, out var y2); // y = 41x/42 - 5/21 y1.ShouldBe(-10, .0001); y2.ShouldBe(31, .0001); }
public void It_should_return_the_correct_result() { var points = new List <(float x, float y)> { (1, 2), (2, 1), (4, 3) }; StatisticsService.CalculateRegressionLine(points, 0, 7, out var y1, out var y2); y1.ShouldBe(1, .0001); y2.ShouldBe(4, .0001); }
public static void RegressionChart(IList <Employee> employees, string fileName) { const int minValueX = 20; const int maxValueX = 60; const int minValueY = 1500; const int maxValueY = 6500; PlotToFile(fileName, pl => { pl.env(minValueX, maxValueX, minValueY, maxValueY, AxesScale.Independent, AxisBox.BoxTicksLabelsAxes); pl.lab("Age", "Salary", "Regression of Salary"); void Plot(ExperienceLevel experienceLevel, int color) { var list = employees.Where(e => e.ExperienceLevel == experienceLevel).Take(100); var points = list.Select(employee => ((float)employee.Age, (float)employee.Salary)).ToList(); pl.col0(color); points.ForEach(p => pl.poin(new double[] { p.Item1 }, new double[] { p.Item2 }, Dot)); pl.col0(color); StatisticsService.CalculateRegressionLine(points, minValueX, maxValueX, out var y1, out var y2); pl.line(new double[] { minValueX, maxValueX }, new double[] { y1, y2 }); }