Kernel density estimation function

更新时间:
复制 MD 格式

Kernel density estimation (KDE) is a non-parametric method that uses smooth peak functions to estimate unknown probability density functions from observed data.

This function fits observed data points with a smooth peak function to simulate the true probability distribution curve.

  • Syntax

    select kernel_density_estimation(bigint stamp, double value, varchar kernelType)
  • Parameters

    Parameter

    Description

    stamp

    Unix timestamp in seconds.

    value

    Observed value at the timestamp.

    kernelType

    • box: A rectangular (uniform) kernel.

    • epanechnikov: An Epanechnikov curve.

    • gaussian: A Gaussian curve.

  • Outputs

    Field

    Description

    unixtime

    Unix timestamp of the raw data.

    real

    Observed value.

    pdf

    Probability density value at each data point.

  • Example

    • Sample query:

      * | 
      select 
          date_trunc('second', cast(t1[1] as bigint)) as time, t1[2] as real, t1[3] as pdf from (
              select kernel_density_estimation(time, num, 'gaussian') as res from ( 
                  select '("__time__" - ("__time__" % 10))' as time, COUNT(*) * 1.0 as num from log group by time order by time)
              ), unnest(res) as t(t1)  limit 1000
    • Result: