Example #1
0
def pca_prediction(prefix, components, outfile, model):
    o = outPutMedia(outfile + '.pdf')
    x = components
    variance = []
    for c in components:
        variance.append(pca_pipeline(prefix, c, model))
    result = '\n'.join([str(k) + ',' + str(v) for k, v in zip(x, variance)])
    open(outfile + '.csv', 'w').write(result)
    plt.plot(x, variance, 'ro-', linewidth=2)
    plt.title('principle number vs variance explained')
    plt.xlabel('Number of principle components')
    plt.ylabel('Explained variance')
    o.write(None)
    o.close()
Example #2
0
def plotVarianceExplained(prefix, components, outfile):
    o = outPutMedia(outfile + '.pdf')
    x = np.arange(components) + 1
    variance = np.arange(components)
    for c in range(components):
        variance[c] = drive(prefix, x[c])
    result = '\n'.join([str(k) + ',' + str(v) for k, v in zip(x, variance)])
    open(outfile + '.csv', 'w').write(result)
    plt.plot(x, variance, 'ro-', linewidth=2)
    plt.title('principle number vs variance explained')
    plt.xlabel('Number of principle components')
    plt.ylabel('Explained variance')
    o.write(None)
    o.close()
def plotVarianceExplained(prefix,components,outfile):
	o = outPutMedia(outfile + '.pdf')
	x = np.arange(components) + 1
	variance = np.arange(components)
	for c in range(components):
		variance[c] = drive(prefix,x[c])
	result = '\n'.join([str(k) + ',' + str(v) for k,v in zip(x,variance)])
	open(outfile + '.csv','w').write(result)
	plt.plot(x,variance,'ro-',linewidth = 2)
	plt.title('principle number vs variance explained')
	plt.xlabel('Number of principle components')
	plt.ylabel('Explained variance')	
	o.write(None)
	o.close()	
def pca_prediction(prefix,components,outfile,model):
	o = outPutMedia(outfile + '.pdf')
	x = components
	variance = []
	for c in components:
		variance.append(pca_pipeline(prefix,c,model))
	result = '\n'.join([str(k) + ',' + str(v) for k,v in zip(x,variance)])
	open(outfile + '.csv','w').write(result)
	plt.plot(x,variance,'ro-',linewidth = 2)
	plt.title('principle number vs variance explained')
	plt.xlabel('Number of principle components')
	plt.ylabel('Explained variance')	
	o.write(None)
	o.close()	
def screePlot(filename,S):
	o = outPutMedia(filename)
	eigvals = S**2/np.cumsum(S)[-1]
	eigvals2 = S**2/np.sum(S)
	assert (eigvals == eigvals2).all()
	x = np.arange(len(S)) + 1
	print(len(x))
	plt.plot(x,eigvals,'ro-',linewidth = 2)
	plt.title('Scree Plot')
	plt.xlabel('Principle Component')
	plt.ylabel('Eigenvalue')
	leg = plt.legend(['Eigenvalues from Bagofword'],loc='best',borderpad=0.3,shadow=False,markerscale = 0.4)
	leg.get_frame().set_alpha(0.4)
	o.write(None)
	o.close()	
Example #6
0
def screePlot(filename, S):
    o = outPutMedia(filename)
    eigvals = S**2 / np.cumsum(S)[-1]
    eigvals2 = S**2 / np.sum(S)
    assert (eigvals == eigvals2).all()
    x = np.arange(len(S)) + 1
    print(len(x))
    plt.plot(x, eigvals, 'ro-', linewidth=2)
    plt.title('Scree Plot')
    plt.xlabel('Principle Component')
    plt.ylabel('Eigenvalue')
    leg = plt.legend(['Eigenvalues from Bagofword'],
                     loc='best',
                     borderpad=0.3,
                     shadow=False,
                     markerscale=0.4)
    leg.get_frame().set_alpha(0.4)
    o.write(None)
    o.close()