本文整理汇总了Python中sklearn.neighbors.kde.KernelDensity.score方法的典型用法代码示例。如果您正苦于以下问题:Python KernelDensity.score方法的具体用法?Python KernelDensity.score怎么用?Python KernelDensity.score使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.neighbors.kde.KernelDensity
的用法示例。
在下文中一共展示了KernelDensity.score方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: estimate_distribution
# 需要导入模块: from sklearn.neighbors.kde import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.kde.KernelDensity import score [as 别名]
def estimate_distribution(samples, h=0.1, n_points=100):
kde = KernelDensity(bandwidth=h)
samples = samples[:, np.newaxis]
kde.fit(samples)
xs = np.linspace(-1.0, 1.0, n_points)
ys = [np.exp(kde.score([x])) for x in xs]
return xs, ys
示例2: PCA
# 需要导入模块: from sklearn.neighbors.kde import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.kde.KernelDensity import score [as 别名]
print msa_vectors.shape
#PCA
pca = PCA(n_components=20)
pca.fit(msa_vectors[1000:])
a_samps_pca = pca.transform(msa_vectors[1000:])
b_samps_pca = pca.transform(msa_vectors[:1000])
print a_samps_pca.shape
#KDE
# for bw in [.01, .1, 1., 10.]:
for bw in [ 1.]:
kde = KernelDensity(kernel='gaussian', bandwidth=bw).fit(a_samps_pca)
# density_train = kde.score_samples(msa_vectors)
print bw, kde.score(b_samps_pca)
densities = kde.score_samples(b_samps_pca)
# densities = np.ones(1000)
#Scale densities to betw 0 and 1
min_density = np.min(densities)
densities = densities - min_density + 1.
weights = np.reciprocal(densities)
max_weights = np.max(weights)
weights = weights / max_weights
print np.max(weights)
print np.mean(weights)
示例3: expanduser
# 需要导入模块: from sklearn.neighbors.kde import KernelDensity [as 别名]
# 或者: from sklearn.neighbors.kde.KernelDensity import score [as 别名]
from os.path import expanduser
home = expanduser("~")
from sklearn.neighbors.kde import KernelDensity
#RASH
L = 166
msa_file = home + '/Documents/Protein_data/RASH/RASH_HUMAN2_833a6535-26d0-4c47-8463-7970dae27a32_evfold_result/alignment/RASH_HUMAN2_RASH_HUMAN2_jackhmmer_e-10_m30_complete_run.fa'
msa, n_aa = tools.convert_msa(L, msa_file)
print len(msa), len(msa[0]), n_aa
msa_vectors = []
for samp in range(2000):
msa_vectors.append(np.ndarray.flatten(tools.convert_samp_to_one_hot(msa[samp], n_aa)))
msa_vectors = np.array(msa_vectors)
print msa_vectors.shape
for bw in [.01, .1, 1., 10.]:
kde = KernelDensity(kernel='gaussian', bandwidth=bw).fit(msa_vectors[1000:])
# density_train = kde.score_samples(msa_vectors)
print bw, kde.score(msa_vectors[:1000])