当前位置: 首页>>代码示例>>Python>>正文


Python KernelDensity.score方法代码示例

本文整理汇总了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
开发者ID:davidmcclure,项目名称:history-of-literature,代码行数:30,代码来源:wpm.py

示例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))
开发者ID:BasilBeirouti,项目名称:scikit-learn,代码行数:11,代码来源:test_kde.py

示例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)
开发者ID:scplbl,项目名称:singlEpoClass,代码行数:12,代码来源:survivalFunc.py

示例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>
开发者ID:bilykigor,项目名称:qimb,代码行数:33,代码来源:KaggleAnalysis.py


注:本文中的sklearn.neighbors.KernelDensity.score方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。