Kernel Density Estimation Example

Overview

The following example using kernel density estimation to estimate a sine curve from a number of noisy observations.

Code

let dn = await import('/lib/machine-learning/kernel/v1.0.0/density.mjs'); let kl = await import('/lib/machine-learning/kernel/v1.0.0/kernel.mjs'); let data = $from(1,10,100).map(p=>{ return { x:p, y:Math.sin(p)+0.1*Math.random() } }); kernel = kl.epanechnikov(0.5); let estimator = dn.estimator(data.map(p=>[p.x,p.y]), kernel); let test = estimator(5);
Try it!

The following shows the estimator of the noisy sine curve example above.