本文整理汇总了Python中statsmodels.nonparametric.kde.KDEUnivariate.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python KDEUnivariate.evaluate方法的具体用法?Python KDEUnivariate.evaluate怎么用?Python KDEUnivariate.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类statsmodels.nonparametric.kde.KDEUnivariate
的用法示例。
在下文中一共展示了KDEUnivariate.evaluate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pdf
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def pdf(self, token, years, bw=5, *args, **kwargs):
"""
Estimate a density function from a token's ratio series.
Args:
token (str)
years (iter)
bw (int)
Returns: OrderedDict {year: density}
"""
series = self.clean_series(token, *args, **kwargs)
# Use the ratio values as weights.
weights = np.array(list(series.values()))
# Fit the density estimate.
density = KDEUnivariate(list(series.keys()))
density.fit(fft=False, weights=weights, bw=bw)
samples = OrderedDict()
for year in years:
samples[year] = density.evaluate(year)[0]
return samples
示例2: find_outiers_kde
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def find_outiers_kde(x):
x_scaled = scale(list(map(float,x)))
kde = KDEUnivariate(x_scaled)
kde.fit(bw="scott",fft=True)
pred = kde.evaluate(x_scaled)
n = sum(pred < 0.5)
outlierindices=np.asarray(pred).argsort()[:n]
outliervalue=np.asarray(x)[outlierindices]
return outlierindices,outliervalue
示例3: empiricalPDF
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def empiricalPDF(data):
"""
Evaluate a probability density function using kernel density
estimation for input data.
:param data: :class:`numpy.ndarray` of data values.
:returns: PDF values at the data points.
"""
LOG.debug("Calculating empirical PDF")
sortedmax = np.sort(data)
kde = KDEUnivariate(sortedmax)
kde.fit()
try:
res = kde.evaluate(sortedmax)
except MemoryError:
res = np.zeros(len(sortedmax))
return res
示例4: kde_statsmodels_u
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def kde_statsmodels_u(data, grid, **kwargs):
"""
Univariate Kernel Density Estimation with Statsmodels
Parameters
----------
data : numpy.array
Data points used to compute a density estimator. It
has `n x 1` dimensions, representing n points and p
variables.
grid : numpy.array
Data points at which the desity will be estimated. It
has `m x 1` dimensions, representing m points and p
variables.
Returns
-------
out : numpy.array
Density estimate. Has `m x 1` dimensions
"""
kde = KDEUnivariate(data)
kde.fit(**kwargs)
return kde.evaluate(grid)
示例5: kde_statsmodels_u
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def kde_statsmodels_u(x, x_grid, bandwidth=0.2, **kwargs):
"""Univariate Kernel Density Estimation with Statsmodels"""
kde = KDEUnivariate(x)
kde.fit(bw=bandwidth, **kwargs)
return kde.evaluate(x_grid)
示例6:
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
])
except AttributeError:
# wtf this fails sometimes, idk, works on root6
HAS_ROOT = False
##################################################################
# ... and plot everything.
fig, axes = plt.subplots(ncols=2, nrows=2, figsize=(6 * 2, 4 * 2))
axes[0, 0].hist(resid, bins='auto', normed=True)
axes[0, 0].plot(x, lg.pdf(x), label='Log Norm')
axes[0, 0].plot(x, hc.pdf(x), label='Half Cauchy')
if HAS_ROOT:
axes[0, 0].plot(x, land, label='Landau', color='blue')
axes[0, 0].plot(x, dens.evaluate(x), label='KDE')
axes[0, 0].set_xlabel('x')
axes[0, 0].set_xlim(0, 0.3)
axes[0, 0].set_ylabel('PDF(x)')
axes[0, 0].legend()
axes[0, 1].hist(resid, bins='auto', normed=True)
axes[0, 1].plot(x, lg.pdf(x), label='Log Norm')
axes[0, 1].plot(x, hc.pdf(x), label='Half Cauchy')
if HAS_ROOT:
axes[0, 1].plot(x, land, label='Landau', color='blue')
axes[0, 1].plot(x, dens.evaluate(x), label='KDE')
axes[0, 1].set_xlabel('x')
axes[0, 1].set_ylabel('PDF(x)')
axes[0, 1].set_yscale('log')
axes[0, 1].legend()
示例7: kde_statsmodels_u
# 需要导入模块: from statsmodels.nonparametric.kde import KDEUnivariate [as 别名]
# 或者: from statsmodels.nonparametric.kde.KDEUnivariate import evaluate [as 别名]
def kde_statsmodels_u(self, x_grid, bandwidth=0.2, **kwargs):
"""Univariate Kernel Density Estimation with Statsmodels"""
from statsmodels.nonparametric.kde import KDEUnivariate
kde = KDEUnivariate(self.data)
kde.fit(bw=bandwidth, **kwargs)
return kde.evaluate(x_grid)