def dissectedCV(clf,dataSet,cv=3,mapping={0:'closed or narrow',1:'open or wide open'}):
    truePositiveRate=[]
    trueNegativeRate = []
    accuracy=[]
    rocList = []
    rocPlotLabels = []
    for i in range(cv):
        training, test = dataSet.splitInTestAndTraining(frac=(1-1./cv))
        clf.fit(training.data,training.targetNum)
        test.classifiedAs=clf.predict(test.data)
        test.probabilities = clf.predict_proba(test.data)
        rocList.append(ROCCurve(test))
        
        test.hasBeenClassified = True
        tpr,tnr,acc=evaluateClassification(test,mapping)
        truePositiveRate.append(tpr)
        trueNegativeRate.append(tnr)
        accuracy.append(acc)
        rocPlotLabels.append('Fold # {}'.format(i+1))
    print 'Summary: '
    msg='TPR: {} \nTNR: {} \nAccuracy: {}'.format(np.mean(truePositiveRate),np.mean(trueNegativeRate),np.mean(accuracy))
    print msg
    PyRoc.plot_multiple_roc(rocList,include_baseline=True,labels=rocPlotLabels,plot_average=False)
    #plt.show()
    return PyRoc.multiple_roc_average(rocList,binstep=.05)    
Пример #2
0
    clf = pickle.load(f)
    testSet.classifiedAs=clf.predict(testSet.data)
    testSet.probabilities=clf.predict_proba(testSet.data)      
    return testSet
   
   
def splitByPose(testSet):
    poses = classifierUtils.splitByPoseFull(testSet)
    textures = {}
    for k in poses:
        textures[k]=classifierUtils.PyRoc.ROCData(poses[k])
    
    return textures
    
if __name__=='__main__':
    #patchSet=patches()
    textureICAOnlySet = textureICAonly()    
    textureSet=texture()
    #errorPatchSet = errorPatch()
    #patchROC = classifierUtils.ROCCurve(patchSet)
    texRoc = classifierUtils.ROCCurve(textureSet)
    texICARoc = classifierUtils.ROCCurve(textureICAOnlySet)    
    #errorPatchRoc = classifierUtils.ROCCurve(errorPatchSet)
    #PyRoc.plot_multiple_roc([patchROC, texRoc, errorPatchRoc],title='All Poses',labels=['Patch','Texture','ErrorPatch'])
    PyRoc.plot_multiple_roc([texICARoc,texRoc],title='',labels=['Gabor Patches Only','all Features'])    
#    t=splitByPose(textureSet)
#    p=splitByPose(patchSet)
#    e=splitByPose(errorPatchSet)
#    for k in p:
#        PyRoc.plot_multiple_roc([p[k],t[k],e[k]],title=k,labels=['Patch','Texture','ErrorPatch'])
    plt.show()
import numpy as np
import PyRoc


fn = ["patches/mp_combined", "texture/mp_combined", "errorpatches/errorpatch_test_mode_0", "modality_texture_patch"]
labels = ["Image Patch", "Extracted Texture", "Error Patch", "Combination"]
c = ["r-", "g-", "b-", "y-", "k-"]
av = []
stepsize = 0.05
x = np.arange(stepsize / 2, 1, stepsize)
roclist = []
for i, v in enumerate(fn):
    r = pickle.load(open(v))
    r.linestyle = c[i]
    roclist.append(r)
PyRoc.plot_multiple_roc(roclist, title="Comparing image modality", labels=labels, plot_average=False)
plt.xticks(np.arange(0.1, 1.1, 0.1), np.arange(0.1, 1.1, 0.1))
plt.yticks(np.arange(0.1, 1.1, 0.1), np.arange(0.1, 1.1, 0.1))
plt.legend(loc=4)
# plt.savefig('/home/attale00/Dropbox/tex_thesis/images/modality_combo.pdf')
#######################################################################################################
fn = ["modality_combo", "modality_errorpatch_patch", "modality_texture_patch", "modality_errorpatch_texture"]
labels = ["Errorpatch + Patch + Texture", "Errorpatches + Patches", "Texture + Patches", "Errorpatches + Texture"]
c = ["y-", "g-", "b-", "r-", "k-"]
av = []
stepsize = 0.05
x = np.arange(stepsize / 2, 1, stepsize)
roclist = []
for i, v in enumerate(fn):
    r = pickle.load(open(v))
    r.linestyle = c[i]
import pickle
import matplotlib.pyplot as plt
import numpy as np
import PyRoc


fn=['errorpatch_test_mode_0','errorpatch_test_mode_1','errorpatch_test_mode_2','errorpatch_test_hog','errorpatch_test_ica']
labels=['Mean and STD','Mean Only','STD only','HOG','ICA']
c=['r-','g-','b-','y-','k-','c-']
av=[]
stepsize=.05
x=np.arange(stepsize/2,1,stepsize)
roclist = []
for i,v in enumerate(fn):
    r=pickle.load(open(v))
    r.linestyle=c[i]
    roclist.append(r)
PyRoc.plot_multiple_roc(roclist,title='Comparison',labels=labels,plot_average=False)
plt.xticks(np.arange(0.1,1.1,0.1),np.arange(0.1,1.1,0.1))
plt.yticks(np.arange(0.1,1.1,0.1),np.arange(0.1,1.1,0.1))
plt.legend(loc=4)
plt.savefig('/home/attale00/Dropbox/tex_thesis/images/errorpatch_ana/errorpatch_train.pdf')
plt.show()
import pickle
import matplotlib.pyplot as plt
import numpy as np
import PyRoc


bins = range(-75,75,30)
p='multiPie_unmirror'
pm='multiPie_mirror'
labels=['Original Dataset separate','Original Dataset Aggregate','Mirrored Dataset separate','Mirrored Dataset aggregate']
for b in bins:
    #plt.figure()
    c=[pickle.load(open(p+'{}'.format(b))),pickle.load(open(p+'_aggregate{}'.format(b))),pickle.load(open(pm+'{}'.format(b))),pickle.load(open(pm+'_aggregate{}'.format(b)))]
    PyRoc.plot_multiple_roc(c,labels=labels,plot_average=False)
    dat=c[0].data
    plt.xlim((-0.01,1.0))
    plt.title('Pose: {}$^\circ$ - {}$^\circ$, Total: {}, n Open: {}'.format(b,b+30,len(dat),[i[0] for i in dat].count(1)))
    #plt.savefig('/home/attale00/Dropbox/tex_thesis/images/pose/mp_test_{}.pdf'.format(b))
    
    
#####################################
bins = range(-60,60,40)
for b in bins:
    #plt.figure()
    c=[pickle.load(open(p+'{}'.format(b))),pickle.load(open(p+'_aggregate{}'.format(b))),pickle.load(open(pm+'{}'.format(b))),pickle.load(open(pm+'_aggregate{}'.format(b)))]
    PyRoc.plot_multiple_roc(c,labels=labels,plot_average=False)
    dat=c[0].data
    plt.xlim((-0.01,1.0))
    plt.title('Pose: {}$^\circ$ - {}$^\circ$, Total: {}, n Open: {}'.format(b,b+40,len(dat),[i[0] for i in dat].count(1)))
    #plt.savefig('/home/attale00/Dropbox/tex_thesis/images/pose/mp_test_{}.pdf'.format(b))