On this page
  1. statistics.kde_random
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

statistics.kde_random

Prev: statistics.kde | Up: statistics | Next: statistics.linear_regression
Rel: statistics.correlation, statistics.covariance, statistics.fmean, statistics.geometric_mean
Ref: docs.python.org — statistics.kde_random
Tags: #public #python3 #stdlib #statistics


Import

import statistics
from statistics import kde_random

Signature & Overview

statistics.kde_random(data, h, kernel='normal', *, seed=None)

Return a function that makes a random selection from the estimated probability density function created by kde(data, h, kernel).

Usage

import statistics

# Python 3.13+: creates a sampler from a KDE distribution
if hasattr(statistics, 'kde_random'):
    sampler = statistics.kde_random([1.0, 2.0, 3.0], h=0.5, seed=42)
    assert isinstance(sampler(), float)

Gotchas

REPL Inspect

from statistics import kde_random
help(kde_random)

Linked from

Related notes