series_fit_line()series_fit_line()

对序列应用线性回归,返回多个列。Applies linear regression on a series, returning multiple columns.

采用包含动态数值数组作为输入的表达式,并执行线性回归以找出拟合度最好的那条线。Takes an expression containing dynamic numerical array as input and does linear regression to find the line that best fits it. 应对时间序列数组使用此函数,拟合 make-series 运算符的输出。This function should be used on time series arrays, fitting the output of make-series operator. 此函数生成以下列:The function generates the following columns:

  • rsquare:r-square 是用于衡量拟合质量的标准。rsquare: r-square is a standard measure of the fit quality. 此值是 [0-1] 范围内的数字,其中 1 表示拟合度最好,0 表示数据无序,与任何直线均不拟合。The value's a number in the range [0-1], where 1 - is the best possible fit, and 0 means the data is unordered and doesn't fit any line.
  • slope:近似直线的斜率(即 y=ax+b 中的“a”)。slope: Slope of the approximated line ("a" from y=ax+b).
  • variance:输入数据的方差。variance: Variance of the input data.
  • rvariance:剩余方差,即输入数据值和近似数据值之间的方差。rvariance: Residual variance that is the variance between the input data values the approximated ones.
  • interception:近似直线的截距(即 y=ax+b 中的“b”)。interception: Interception of the approximated line ("b" from y=ax+b).
  • line_fit:数值数组,其中包含拟合度最好的直线的一系列值。line_fit: Numerical array holding a series of values of the best fitted line. 序列长度等于输入数组的长度。The series length is equal to the length of the input array. 该值用于绘制图表。The value's used for charting.

语法Syntax

series_fit_line(x)series_fit_line(x)

参数Arguments

  • x:数值的动态数组。x : Dynamic array of numeric values.

提示

使用此函数最便捷的方法是将其应用于 make-series 运算符的结果。The most convenient way of using this function is to apply it to the results of make-series operator.

示例Examples

print id=' ', x=range(bin(now(), 1h)-11h, bin(now(), 1h), 1h), y=dynamic([2,5,6,8,11,15,17,18,25,26,30,30])
| extend (RSquare,Slope,Variance,RVariance,Interception,LineFit)=series_fit_line(y)
| render timechart

序列拟合线

RSquareRSquare 斜率Slope VarianceVariance RVarianceRVariance InterceptionInterception LineFitLineFit
0.9820.982 2.7302.730 98.62898.628 1.6861.686 -1.666-1.666 1.064、3.7945、6.526、9.256、11.987、14.718、17.449、20.180、22.910、25.641、28.371、31.1021.064, 3.7945, 6.526, 9.256, 11.987, 14.718, 17.449, 20.180, 22.910, 25.641, 28.371, 31.102