本文整理汇总了Python中sklearn.decomposition.PCA.decision_function方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.decision_function方法的具体用法?Python PCA.decision_function怎么用?Python PCA.decision_function使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.decomposition.PCA
的用法示例。
在下文中一共展示了PCA.decision_function方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LDA_A
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import decision_function [as 别名]
def LDA_A(rootdir, posdir, posnum, negnum_p, ft):
pos = []
neg = []
pathpos = []
pathneg = []
folders = []
imgspos = []
imgsneg = []
with open('list.txt', 'r') as f:
for line in f:
line = line.strip()
folders.append(line)
if 0 == cmp(ft, 'gabor'):
print 'feature type: GABOR'
gbf = igbf.GABOR_FEAT()
elif 0 == cmp(ft, 'hog'):
print 'feature type: HOG'
gbf = ihogf.HOG_FEAT()
elif 0 == cmp(ft, 'lbp'):
print 'feature type: LBP'
gbf = ilbpf.LBP_FEAT()
elif 0 == cmp(ft, 'dwt'):
print 'feature type: DWT'
gbf = idwtf.DWT_FEAT()
elif 0 == cmp(ft, 'yuv'):
print 'feature type: YUV'
gbf = iyuvf.YUV_FEAT()
else:
print 'unknown feature type'
return
for folder in folders:
fname = os.path.join(rootdir, folder)
if 0 == cmp(folder, posdir):
fvs,imgs = gbf.gen_folder(fname, posnum)
if fvs is None:
print 'pos None ',fname
continue
pos.extend(fvs)
imgspos.extend(imgs)
pathpos.extend([folder for k in range(len(fvs))])
else:
fvs,imgs = gbf.gen_folder(fname, negnum_p)
if fvs is None:
print 'neg None ', fname
continue
neg.extend(fvs)
imgsneg.extend(imgs)
pathneg.extend([folder for k in range(len(fvs))])
label0 = [0 for k in range(len(pos))]
label1 = [1 for k in range(len(neg))]
samples = np.array(pos + neg)
labels = np.array(label0 + label1)
paths = pathpos + pathneg
imgs = imgspos + imgsneg
#com_num = np.minimum(300, samples.shape[0] - 10)
clf = PCA(0.98)
samples = clf.fit_transform(samples)
print 'after pca : ', samples.shape
clf = LDA()
clf.fit(samples,labels)
cnf = clf.decision_function(samples)
X = []
for k in range(len(paths)):
X.append((paths[k], cnf[k], imgs[k]))
X = sorted(X, key = lambda a : a[1])
line = ""
lineA = "" #sometimes, the positive set is split into two parts
lineB = ""
for path, cnf, img in X:
line += str(cnf) + ' ' + path + ' ' + img + '\n'
if 0 != cmp(path, posdir):
continue
if cnf > 0:
lineA += img + '\n'
else:
lineB += img + '\n'
with open('A.txt', 'w') as f:
f.writelines(lineA)
with open('B.txt', 'w') as f:
f.writelines(lineB)
with open('result.txt', 'w') as f:
f.writelines(line)
return
示例2:
# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import decision_function [as 别名]
plt.legend(["Not considered"])
plt.show()
# <codecell>
count_n=tmp.shape[0]
OUTLIER_FRACTION = 0.26
# <codecell>
clf=svm.OneClassSVM(kernel='rbf')
clf.fit(tmp)
# <codecell>
dist_to_border = clf.decision_function(tmp).ravel()
threshold = stats.scoreatpercentile(dist_to_border,
100 * OUTLIER_FRACTION)
is_inlier = dist_to_border > threshold
# <codecell>
df[is_inlier == 0].Decision.value_counts()
# <codecell>
pd.DataFrame(dist_to_border).plot()
plt.show()
# <codecell>