series_fit_2lines_dynamic()series_fit_2lines_dynamic()

对序列应用两段线性回归,返回动态对象。Applies two segments linear regression on a series, returning a dynamic object.

采用包含动态数值数组的表达式作为输入,并应用两段线性回归,以便识别和量化序列中的趋势变化。Takes an expression containing dynamic numerical array as input and applies two segments linear regression in order to identify and quantify trend changes in a series. 该函数针对序列索引进行迭代。The function iterates on the series indexes. 在每次迭代中,它将序列拆分为两部分,并使用 series_fit_line()series_fit_line_dynamic() 来拟合一个单独的线条。In each iteration, it splits the series to two parts, and fits a separate line using series_fit_line() or series_fit_line_dynamic(). 此函数将线条与两个部分中的每部分进行拟合,并计算总的 R 平方值。The function fits the lines to each of the two parts, and calculates the total R-squared value. 最佳拆分是最大化 R 平方的拆分。The best split is the one that maximizes R-squared. 函数以动态值返回包含以下内容的参数:The function returns its parameters in dynamic value with the following content:

  • rsquare:R 平方是用于衡量拟合质量的标准。rsquare: R-squared is a standard measure of the fit quality. 它是 [0-1] 范围内的一个数字,其中 1 表示拟合质量可能最佳,0 表示数据是无序的,无法与任何线拟合。It's a number in the range of [0-1], where 1 is the best possible fit, and 0 means the data is unordered and do not fit any line.
  • split_idx:两段的拆分点的索引(从零开始)。split_idx: the index of breaking point to two segments (zero-based).
  • variance:输入数据的方差。variance: variance of the input data.
  • rvariance:残差方差,即输入数据值和近似数据值之间的方差(按两个线段)。rvariance: residual variance that is the variance between the input data values the approximated ones (by the two line segments).
  • 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. 它用于绘制图表。It is used for charting.
  • right.rsquare:拆分点右侧直线的相关系数平方,请参阅 series_fit_line()series_fit_line_dynamic()right.rsquare: r-square of the line on the right side of the split, see series_fit_line() or series_fit_line_dynamic().
  • right.slope:右近似线(形式为 y=ax+b)的斜率。right.slope: slope of the right approximated line (of the form y=ax+b).
  • right.interception:左近似线的截距(即 y=ax+b 中的 b)。right.interception: interception of the approximated left line (b from y=ax+b).
  • right.variance:拆分点右侧输入数据的方差。right.variance: variance of the input data on the right side of the split.
  • right.rvariance:拆分点右侧输入数据的残差方差。right.rvariance: residual variance of the input data on the right side of the split.
  • left.rsquare:拆分点左侧直线的相关系数平方,请参阅 [series_fit_line()].(series-fit-linefunction.md) 或 series_fit_line_dynamic()left.rsquare: r-square of the line on the left side of the split, see [series_fit_line()].(series-fit-linefunction.md) or series_fit_line_dynamic().
  • left.slope:左近似线(形式为 y=ax+b)的斜率。left.slope: slope of the left approximated line (of the form y=ax+b).
  • left.interception:左近似线(形式为 y=ax+b)的截距。left.interception: interception of the approximated left line (of the form y=ax+b).
  • left.variance:拆分点左侧输入数据的方差。left.variance: variance of the input data on the left side of the split.
  • left.rvariance:拆分点左侧输入数据的残差方差。left.rvariance: residual variance of the input data on the left side of the split.

此运算符类似于 series_fit_2linesThis operator is similar to series_fit_2lines. series-fit-2lines 不同,它返回一个动态包。Unlike series-fit-2lines, it returns a dynamic bag.

语法Syntax

series_fit_2lines_dynamic(x)series_fit_2lines_dynamic(x)

参数Arguments

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

提示

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

示例Example

print id=' ', x=range(bin(now(), 1h)-11h, bin(now(), 1h), 1h), y=dynamic([1,2.2, 2.5, 4.7, 5.0, 12, 10.3, 10.3, 9, 8.3, 6.2])
| extend LineFit=series_fit_line_dynamic(y).line_fit, LineFit2=series_fit_2lines_dynamic(y).line_fit
| project id, x, y, LineFit, LineFit2
| render timechart

序列拟合 2 条线