scipy.stats.gaussian_kde.
set_bandwidth#
- gaussian_kde.set_bandwidth(bw_method=None)[Quelle]#
Berechnet den Bandbreitenfaktor mit der angegebenen Methode.
Die neue Bandbreite, die nach einem Aufruf von
set_bandwidthberechnet wird, wird für nachfolgende Auswertungen der geschätzten Dichte verwendet.- Parameter:
- bw_methodstr, Skalar oder aufrufbar, optional
Die Methode zur Berechnung des Bandbreitenfaktors. Dies kann 'scott', 'silverman', eine skalare Konstante oder eine aufrufbare Funktion sein. Wenn es sich um einen Skalar handelt, wird dieser direkt als Faktor verwendet. Wenn es sich um eine aufrufbare Funktion handelt, sollte diese eine
gaussian_kde-Instanz als einziges Argument nehmen und einen Skalar zurückgeben. Wenn None (Standard), passiert nichts; die aktuelle Methodecovariance_factorwird beibehalten.
Hinweise
Hinzugefügt in Version 0.11.
Beispiele
>>> import numpy as np >>> import scipy.stats as stats >>> x1 = np.array([-7, -5, 1, 4, 5.]) >>> kde = stats.gaussian_kde(x1) >>> xs = np.linspace(-10, 10, num=50) >>> y1 = kde(xs) >>> kde.set_bandwidth(bw_method='silverman') >>> y2 = kde(xs) >>> kde.set_bandwidth(bw_method=kde.factor / 3.) >>> y3 = kde(xs)
>>> import matplotlib.pyplot as plt >>> fig, ax = plt.subplots() >>> ax.plot(x1, np.full(x1.shape, 1 / (4. * x1.size)), 'bo', ... label='Data points (rescaled)') >>> ax.plot(xs, y1, label='Scott (default)') >>> ax.plot(xs, y2, label='Silverman') >>> ax.plot(xs, y3, label='Const (1/3 * Silverman)') >>> ax.legend() >>> plt.show()