c# - If Best Fit Straight Line the best method for prediction -
i need make prediction next point, based on given set of point samples on 2-d coordinate system.
i using best-fit straight line method such prediction.
please let me know if there method better best-fit straight line?
my code below:
public class lineequation { public double m; //slope public double c; //constant in y=mx+c } public class point { public double x; public double y; } public class bestfitline { public point[] points = new point[7]; public void inputpoints(point[] points) { (int = 0; < points.length; i++) { points[i] = new point(); } points[0].x = 12; points[0].y = 13; points[1].x = 22; points[1].y = 23; points[2].x = 32; points[2].y = 33; points[3].x = 42; points[0].y = 23; points[4].x = 52; points[4].y = 33; points[5].x = 62; points[5].y = 63; points[6].x = 72; points[6].y = 63; } public lineequation calculatebestfitline(point[] points) { double constant = 0; double slope=0; (int = 0; < points.length - 1; i++) { (int j = + 1; j < points.length; j++) { double m = (points[j].y - points[i].y) / (points[j].x - points[i].x); double c = points[j].y - (m * points[j].x); constant += c; slope += m; } } int linecount =((points.length-1)*points.length)/2; slope = slope / linecount; constant = constant / linecount; lineequation eq = new lineequation(); eq.c = constant; eq.m = slope; return eq; }}
if x coordinate composed of dates, can rely on generalized additive models following components : - trend - yearly profile - weekly profile - daily profile
gam models available in r, advice use jri in order interface java code r.
cheers
Comments
Post a Comment