def test(): # Testing import numpy.random as rand import pylab ############## Make synthetic data ################# # Simulate protein binding site by having few positive # class examples folds = [] labs = [-1] * 500 labs.extend([1] * 20) N = 40 # number of sequences # set means of decision values mu_n = -1 mu_p = 1 # draw decision values from normal distribution # for each class for i in xrange(N): preds = rand.normal(mu_n, 1, 500).tolist() preds.extend(rand.normal(mu_p, 1, 20).tolist()) folds.append((labs[:], preds)) # Calculate average ROC curve fpr, tpr, tpr_ci, area, area_ci = roc_VA(folds) # Print AUC with confidence interval print "area: %f, 95%% CI: (%f, %f)" % (area, area - area_ci, area + area_ci) ####### Plot ROC curve with 95% confidence band ####### fig = pylab.figure() ax = fig.add_subplot(111) # fill upper band xs, ys = pylab.poly_between(fpr, tpr, numpy.array(tpr) + numpy.array(tpr_ci)) ax.fill(xs, ys, 'r') # fill lower band xs, ys = pylab.poly_between(fpr, tpr, numpy.array(tpr) - numpy.array(tpr_ci)) ax.fill(xs, ys, 'r') # label axes and main pylab.xlabel("FPR") pylab.ylabel("TPR") pylab.title("Example ROC curve with 95% confidence band") ax.plot(numpy.arange(0, 1.1, .1), numpy.arange(0, 1.1, .1), 'k--') pylab.xlim(-.01, 1.01) pylab.ylim(-.01, 1.01) pylab.show()
def test(): # Testing import numpy.random as rand import pylab ############## Make synthetic data ################# # Simulate protein binding site by having few positive # class examples folds = [ ] labs = [ -1 ] * 500 labs.extend( [ 1 ] * 20 ) N = 40 # number of sequences # set means of decision values mu_n = -1 mu_p = 1 # draw decision values from normal distribution # for each class for i in xrange( N ): preds = rand.normal( mu_n, 1, 500 ).tolist() preds.extend( rand.normal( mu_p, 1, 20 ).tolist() ) folds.append( ( labs[ : ], preds ) ) # Calculate average ROC curve fpr, tpr, tpr_ci, area, area_ci = roc_VA( folds ) # Print AUC with confidence interval print "area: %f, 95%% CI: (%f, %f)" % ( area, area-area_ci, area+area_ci ) ####### Plot ROC curve with 95% confidence band ####### fig = pylab.figure( ) ax = fig.add_subplot( 111 ) # fill upper band xs, ys = pylab.poly_between( fpr, tpr, numpy.array( tpr ) + numpy.array( tpr_ci ) ) ax.fill( xs, ys, 'r' ) # fill lower band xs, ys = pylab.poly_between( fpr, tpr, numpy.array( tpr ) - numpy.array( tpr_ci ) ) ax.fill( xs, ys, 'r' ) # label axes and main pylab.xlabel( "FPR" ) pylab.ylabel( "TPR" ) pylab.title( "Example ROC curve with 95% confidence band" ) ax.plot( numpy.arange( 0, 1.1, .1 ), numpy.arange( 0, 1.1, .1 ), 'k--') pylab.xlim( -.01, 1.01 ) pylab.ylim( -.01, 1.01 ) pylab.show( )
def test(): GP = GaussianProcess(GaussianKernel_iso([0.2, 1.0])) X = array([[0.2], [0.3], [0.5], [1.5]]) Y = [1, 0, 1, 0.75] GP.addData(X, Y) figure(1) A = arange(0, 2, 0.01) mu = array([GP.mu(x) for x in A]) sig2 = array([GP.posterior(x)[1] for x in A]) Ei = EI(GP) ei = [-Ei.negf(x) for x in A] Pi = PI(GP) pi = [-Pi.negf(x) for x in A] Ucb = UCB(GP, 1, T=2) ucb = [-Ucb.negf(x) for x in A] ax = subplot(1, 1, 1) ax.plot(A, mu, "k-", lw=2) xv, yv = poly_between(A, mu - sig2, mu + sig2) ax.fill(xv, yv, color="#CCCCCC") ax.plot(A, ei, "g-", lw=2, label="EI") ax.plot(A, ucb, "g--", lw=2, label="UCB") ax.plot(A, pi, "g:", lw=2, label="PI") ax.plot(X, Y, "ro") ax.legend() draw() show()
def test(): GP = GaussianProcess(GaussianKernel_iso([.2, 1.0])) X = array([[.2], [.3], [.5], [1.5]]) Y = [1, 0, 1, .75] GP.addData(X, Y) figure(1) A = arange(0, 2, 0.01) mu = array([GP.mu(x) for x in A]) sig2 = array([GP.posterior(x)[1] for x in A]) Ei = EI(GP) ei = [-Ei.negf(x) for x in A] Pi = PI(GP) pi = [-Pi.negf(x) for x in A] Ucb = UCB(GP, 1, T=2) ucb = [-Ucb.negf(x) for x in A] ax = subplot(1, 1, 1) ax.plot(A, mu, 'k-', lw=2) xv, yv = poly_between(A, mu - sig2, mu + sig2) ax.fill(xv, yv, color="#CCCCCC") ax.plot(A, ei, 'g-', lw=2, label='EI') ax.plot(A, ucb, 'g--', lw=2, label='UCB') ax.plot(A, pi, 'g:', lw=2, label='PI') ax.plot(X, Y, 'ro') ax.legend() draw() show()
def stackareaplot(self): fig = pyplot.figure() lineas = [] stack = [] k = 0 for i in self.yval: stack.append(i) m = 0 for j in i: if k > 0: stack[k][m] = stack[k][m] + stack[k - 1][m] m = m + 1 k = k + 1 j = 0 xss = [] yss = [] used_colors = [] for i in stack: linea = pyplot.plot(self.xval, i, self.colors[j]) used_colors.append(self.colors[j]) lineas.append(linea[0]) xs, ys = pylab.poly_between(self.xval, 0, i) xss.append(xs) yss.append(ys) j = j + 1 if j > 19: j = 0 j = 0 k = -1 used_colors_inv = used_colors[::-1] for i in yss: pylab.fill(xss[0], yss[k], used_colors_inv[j]) j = j + 1 k = k - 1 pyplot.legend(lineas, self.tags, 'best') pyplot.title(self.title) pyplot.xlabel('Time (s)') pyplot.ylabel('Airtime consumption (%)') pyplot.grid(True) pyplot.show()
def stackareaplot(self): fig = pyplot.figure() lineas=[] stack = [] k=0 for i in self.yval: stack.append(i) m=0 for j in i: if k > 0: stack[k][m]=stack[k][m]+stack[k-1][m] m = m+1 k=k+1 j=0 xss=[] yss=[] used_colors=[] for i in stack: linea = pyplot.plot(self.xval,i,self.colors[j]) used_colors.append(self.colors[j]) lineas.append(linea[0]) xs,ys = pylab.poly_between(self.xval,0,i) xss.append(xs) yss.append(ys) j=j+1 if j>19: j = 0 j=0 k=-1 used_colors_inv = used_colors[::-1] for i in yss: pylab.fill(xss[0], yss[k], used_colors_inv[j]) j=j+1 k=k-1 pyplot.legend(lineas,self.tags,'best') pyplot.title(self.title) pyplot.xlabel('Time (s)') pyplot.ylabel('Airtime consumption (%)') pyplot.grid(True) pyplot.show()