maxframe.dataframe.DataFrame.plot.density#

DataFrame.plot.density(*args, **kwargs)#

使用高斯核生成核密度估计图。

在统计学中,核密度估计 (KDE)是一种非参数方法,用于估计随机变量的概率密度函数(PDF)。此函数使用高斯核,并包含自动带宽确定功能。

参数:
  • bw_method (str, scalar or callable, optional) -- 用于计算估计器带宽的方法。可以是 'scott'、'silverman'、标量常数或可调用对象。如果为 None(默认),则使用 'scott'。更多信息请参见 scipy.stats.gaussian_kde

  • ind (NumPy array or int, optional) -- 用于评估估计 PDF 的点。如果为 None(默认),则使用 1000 个等间距点。如果 ind 是一个 NumPy 数组,则在传入的点上评估 KDE。如果 ind 是一个整数,则使用 ind 个等间距点。

  • weights (NumPy array, optional) -- Weights of datapoints. This must be the same shape as datapoints. If None (default), the samples are assumed to be equally weighted.

  • **kwargs -- 其他关键字参数请参见 DataFrame.plot()

返回:

The matplotlib axes containing the KDE plot.

返回类型:

matplotlib.axes.Axes or numpy.ndarray of them

参见

scipy.stats.gaussian_kde

使用高斯核的核密度估计表示。这是内部用于估计 PDF 的函数。

示例

给定一个从未知分布中随机采样的点序列,使用带有自动带宽确定的 KDE 估计其 PDF,并将结果在 1000 个等间距点(默认)上进行评估和绘图:

(Source code)

可以指定一个标量带宽。使用较小的带宽值可能导致过拟合,而使用较大的带宽值可能导致欠拟合:

(Source code)

(Source code)

最后,ind 参数决定了估计 PDF 图的评估点:

(Source code)

对于 DataFrame,其工作方式相同:

(Source code)

可以指定一个标量带宽。使用较小的带宽值可能导致过拟合,而使用较大的带宽值可能导致欠拟合:

(Source code)

(Source code)

最后,ind 参数决定了估计 PDF 图的评估点:

(Source code)