All Products
Search
Document Center

Simple Log Service:Kernel density estimation function

Last Updated:Jun 12, 2024

Kernel density estimation is a non-parametric test method. It is used to estimate unkonwn density functions in probability theory.

The kernel density estimation function uses a smooth peak function to simulate the real probability distribution curve by fitting the observed data points.

  • Syntax

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

    Parameter

    Description

    stamp

    The UNIX timestamp. Unit: seconds.

    value

    The observed value.

    kernelType

    • box: rectangle window

    • epanechniov: Epanechnikov curve

    • gausener: Gaussian curve

  • Result

    Display item

    Description

    unixtime

    The timestamp of the source data.

    real

    The observed value.

    pdf

    The probability of each observed data point.

  • Example

    • Sample code:

      * | 
      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
    • Sample result: