本文整理汇总了Python中sklearn.neighbors.KernelDensity.score方法的典型用法代码示例。如果您正苦于以下问题:Python KernelDensity.score方法的具体用法?Python KernelDensity.score怎么用?Python KernelDensity.score使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.neighbors.KernelDensity
的用法示例。
在下文中一共展示了KernelDensity.score方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pdf
# 需要导入模块: from sklearn.neighbors import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.KernelDensity import score [as 别名]
def pdf(self, token, years, bandwidth=5):
"""
Estimate a density function from a token's rank series.
Args:
token (str)
years (range)
Returns: OrderedDict {year: density}
"""
series = self.series(token)
data = []
for year, wpm in series.items():
data += [year] * round(wpm)
data = np.array(data)[:, np.newaxis]
pdf = KernelDensity(bandwidth=bandwidth).fit(data)
samples = OrderedDict()
for year in years:
samples[year] = np.exp(pdf.score(year))
return samples
示例2: check_results
# 需要导入模块: from sklearn.neighbors import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.KernelDensity import score [as 别名]
def check_results(kernel, bandwidth, atol, rtol, X, Y, dens_true):
kde = KernelDensity(kernel=kernel, bandwidth=bandwidth,
atol=atol, rtol=rtol)
log_dens = kde.fit(X).score_samples(Y)
assert_allclose(np.exp(log_dens), dens_true,
atol=atol, rtol=max(1E-7, rtol))
assert_allclose(np.exp(kde.score(Y)),
np.prod(dens_true),
atol=atol, rtol=max(1E-7, rtol))
示例3: kde3d
# 需要导入模块: from sklearn.neighbors import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.KernelDensity import score [as 别名]
def kde3d(x, y, z, data_point):
values = np.vstack([x, y, z]).T
# Use grid search cross-validation to optimize the bandwidth
# params = {'bandwidth': np.logspace(-1, 1, 20)}
kde = KernelDensity(bandwidth=0.3)
kde.fit(values)
kde_coords = kde.sample(10000)
log_pdf = kde.score_samples(kde_coords)
percentile = np.sum(log_pdf < kde.score(data_point))/10000.
return (percentile)
示例4: str
# 需要导入模块: from sklearn.neighbors import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.KernelDensity import score [as 别名]
driverID=2
tripInd=2
driverDir = '/home/user1/Desktop/SharedFolder/Kaggle/DriversCleaned/'+str(driverID)
df = pd.read_csv(driverDir+'_' + str(tripInd)+'.csv')
trip = Trip(driverID,tripInd,df)
trip.getSpeed()
trip.getAcc()
#trip.getRadius()
#trip.getCacc()
trip.getFeatures()
X=trip.features[['v','acc']]
probas = np.zeros(X.shape[0])
for i in range(X.shape[0]):
probas[i]=clf.score(X.loc[i])
# <codecell>
probas.mean()
# <codecell>
sns.jointplot(X.v,X.acc,kind = "scatter",size=6,ratio=5,marginal_kws={'bins':30})
#sns.kdeplot(X[['cacc','acc']])
# <codecell>
xN = np.asanyarray(X[['cacc','acc']])
# <codecell>