本文整理汇总了Python中sklearn.decomposition.PCA.coeff方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.coeff方法的具体用法?Python PCA.coeff怎么用?Python PCA.coeff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.coeff方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: textListToColors
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import coeff [as 别名]
def textListToColors(names):
'''
Generates a list of colors based on a list of names (strings). Similar strings correspond to similar colors.
'''
# STEP A: compute strings distance between all combnations of strings
Dnames = np.zeros( (len(names), len(names)) )
for i in range(len(names)):
for j in range(len(names)):
Dnames[i,j] = 1 - 2.0 * levenshtein(names[i], names[j]) / float(len(names[i]+names[j]))
# STEP B: pca dimanesionality reduction to a single-dimension (from the distance space)
pca = PCA(method='cov')
pca.learn(Dnames)
coeff = pca.coeff()
# STEP C: mapping of 1-dimensional values to colors in a jet-colormap
textToColor = pca.transform(Dnames, k=1)
textToColor = 255 * (textToColor - textToColor.min()) / (textToColor.max() - textToColor.min())
textmaps = generateColorMap();
colors = [textmaps[int(c)] for c in textToColor]
return colors