本文整理汇总了Python中sklearn.decomposition.PCA.fit_predict方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.fit_predict方法的具体用法?Python PCA.fit_predict怎么用?Python PCA.fit_predict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.fit_predict方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KMeans_A
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import fit_predict [as 别名]
def KMeans_A(rootdir,ft):
pos = []
imgspos = []
if 0 == cmp(ft, 'lbp'):
print "ft : LBP"
gbf=ilbpf.LBP_FEAT()
elif 0 == cmp(ft, 'gabor'):
print "ft : GABOR"
gbf = igbf.GABOR_FEAT()
elif 0 == cmp(ft, 'hog'):
print 'ft : HOG'
gbf = ihogf.HOG_FEAT()
elif 0 == cmp(ft, 'dwt'):
print 'ft : DWT'
gbf = idwtf.DWT_FEAT()
else:
print 'unknown ft'
return
fvs,imgs = gbf.gen_folder(rootdir, 5000)
if fvs is None:
print 'JPG None ',rootdir
return
pos.extend(fvs)
imgspos.extend(imgs)
samples = np.array(pos)
imgs = imgspos
com_num = np.minimum(300, samples.shape[0] - 10)
clf = PCA(com_num)
print 'before pca : ', samples.shape
samples = clf.fit_transform(samples)
print 'after pca : ', samples.shape
clf = KMeans(n_clusters=2,n_jobs=-2,verbose = 0)
prds = clf.fit_predict(samples)
line0 = ""
line1 = ""
# line2 = ""
# line3 = ""
for k in range(len(prds)):
if prds[k] == 0:
line0 += imgs[k] + '\n'
elif prds[k] == 1:
line1 += imgs[k] + '\n'
# elif prds[k] == 2:
# line2 += imgs[k] + '\n'
# else:
# line3 += imgs[k] + '\n'
with open('A.txt', 'w') as f:
f.writelines(line0)
with open('B.txt', 'w') as f:
f.writelines(line1)
# with open('C.txt', 'w') as f:
# f.writelines(line2)
# with open('D.txt', 'w') as f:
# f.writelines(line3)
return