Examples
From a given a Series of points randomly sampled from an unknown distribution,
estimate its PDF (probability density function) using KDE (Kernel Density Estimate) with
automatic bandwidth determination and plot the results, evaluating them at 1000 equally
spaced points (default):
import numpy as np
import pandas as pd
s = pd.Series([2, 3, 3.5, 4, 4.5, 4, 6])
ax = s.plot.kde()
A scalar bandwidth can be specified. Using a small bandwidth value can lead to over-fitting,
while using a large bandwidth value may result in under-fitting:
ax = s.plot.kde(bw_method=0.3)
ax = s.plot.kde(bw_method=3)
The ind parameter determines the evaluation points for the plot of
the estimated PDF(probability density function):
ax = s.plot.kde(ind=[2, 3, 4, 5, 6])
For DataFrame, it works in the same way:
df = pd.DataFrame({
'p': [2, 3, 3.5, 4, 4.5, 5, 6],
'q': [5, 5, 5.5, 6, 6.5, 7, 7],
})
ax = df.plot.kde()
A scalar bandwidth can be specified. Using a small bandwidth value can lead to over-fitting,
while using a large bandwidth value may result in under-fitting:
ax = df.plot.kde(bw_method=0.3)
ax = df.plot.kde(bw_method=3)
Finally, the ind parameter determines the evaluation points for the plot of the estimated PDF:
ax = df.plot.kde(ind=[2, 3, 4, 5, 6, 7])