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


Python PCA.predict_proba方法代码示例

本文整理汇总了Python中sklearn.decomposition.PCA.predict_proba方法的典型用法代码示例。如果您正苦于以下问题:Python PCA.predict_proba方法的具体用法?Python PCA.predict_proba怎么用?Python PCA.predict_proba使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.decomposition.PCA的用法示例。


在下文中一共展示了PCA.predict_proba方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: RF_A

# 需要导入模块: from sklearn.decomposition import PCA [as 别名]
# 或者: from sklearn.decomposition.PCA import predict_proba [as 别名]
def RF_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(com_num)
    samples = clf.fit_transform(samples)
    print 'after pca : ', samples.shape
    clf = RandomForestClassifier()
    clf.fit(samples,labels)
    cnf = clf.predict_proba(samples)[:,0]
    X = []

    for k in range(len(paths)):
        X.append((paths[k], cnf[k], imgs[k]))
    X = sorted(X, key = lambda a : a[1], reverse=True)
    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 
开发者ID:z01nl1o02,项目名称:tests,代码行数:89,代码来源:a_rf.py


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