可能是您想在图表上绘制这些数字并找到一条直线,使这些直线和数字之间的总距离最小化?这称为线性回归
def linreg(X, Y): """ return a,b in solution to y = ax + b such that root mean square distance between trend line and original points is minimized """ N = len(X) Sx = Sy = Sxx = Syy = Sxy = 0.0 for x, y in zip(X, Y): Sx = Sx + x Sy = Sy + y Sxx = Sxx + x*x Syy = Syy + y*y Sxy = Sxy + x*y det = Sxx * N - Sx * Sx return (Sxy * N - Sy * Sx)/det, (Sxx * Sy - Sx * Sxy)/detx = [12, 34, 29, 38, 34, 51, 29, 34, 47, 34, 55, 94, 68, 81]a,b = linreg(range(len(x)),x) //your x,y are switched from standard notation
趋势线不太可能穿过您的原始点,但是它将尽可能接近直线可以到达的原始点。使用该趋势线(a,b)的梯度和截距值,您将可以推断出超出数组末尾的线:
extrapolatedtrendline=[a*index + b for index in range(20)] //replace 20 with desired trend length
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)