Examples
Estimate the PDF (probability density function) using KDE with automatic bandwidth
determination and plot from the results of a given Series of points randomly sampled
from an unknown distribution.
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, 5, 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)
In the following example, the ind parameter determines the evaluation points
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()
In the following example 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)
In the following example 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])