import numpy as np
import matplotlib.pyplot as plt
import matplotlib.font_manager
from matplotlib.ticker import FuncFormatter
import scipy.stats as st
import pylab
[docs]def syntheticAndReal(sData, bData, d1, d2, filename):
fig, ax = plt.subplots(1)
ax.scatter(sData[:,d1],sData[:,d2], alpha=0.5, c='r')
ax.scatter(bData[:,d1],bData[:,d2], alpha=0.5, c='g')
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def histogram(sData, bData, i, filename=None):
fig, ax = plt.subplots(1)
ax.hist(sData[:,i], 50, normed=True, alpha=0.5, color='r')
ax.hist(bData[:,i], 50, normed=True, alpha=0.5, color='g')
ax.grid(True)
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def yp_vs_y(yp, y, filename=None):
"""
This method plots y predicted vs. y actual on a 45-degree chart.
"""
miny = min(min(y), min(yp))
maxy = max(max(y), max(yp))
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.scatter(yp, y)
ax.plot([miny, maxy], [miny, maxy])
ax.set_xlim((miny, maxy))
ax.set_ylim((miny, maxy))
ax.grid(True)
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def qq(x, filename=None):
fig = plt.figure()
ax = fig.add_subplot(111)
osm, osr = st.probplot(x, fit=0, dist='norm') # compute
ax.plot(osm, osr, '.')
ax.grid(True)
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def coef_path(coefs):
"""
Plot the coefficient paths generated by elastic net / lasso.
"""
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_color_cycle(2 * ['b', 'r', 'g', 'c', 'k'])
plt.plot(coefs)
plt.xlabel('-Log(lambda)')
plt.ylabel('weights')
plt.title('Lasso and Elastic-Net Paths')
plt.axis('tight')
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
[docs]def pairs(data, labels=None, filename=None):
"""
Generates something similar to R pairs()
"""
nVariables = data.shape[1]
#if labels is None:
# labels = ['var%d'%i for i in range(nVariables)]
fig = plt.figure()
for i in range(nVariables):
for j in range(nVariables):
ax = fig.add_subplot(nVariables, nVariables, i * nVariables + j + 1)
if i == j:
ax.hist(data[:,i])
#ax.set_title(labels[i])
else:
ax.scatter(data[:,i], data[:,j])
ax.autoscale(True)
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def te_and_yl(error, errorSyn, filename, description):
[teSyn, ylSyn] = np.mean(errorSyn,0)
[teActual, ylActual] = np.mean(error,0)
nWafers = np.size(error,0)
prop = matplotlib.font_manager.FontProperties(size=10)
fig = pylab.figure()
ax = fig.add_subplot(211)
ax.plot(error[:,0],'k-')
ax.plot([0,nWafers],[teSyn, teSyn],'g--')
ax.plot([0,nWafers],[teActual, teActual],'k-')
leg = ax.legend((r"$T_E$", r"$\hat{T}_E$", r"$\bar{T}_E$"), 'best', shadow=True, prop = prop)
ax.grid(True)
ax.set_title('Test Escapes')
ax = fig.add_subplot(212)
ax.plot(error[:,1],'k-', [0,nWafers],[ylSyn, ylSyn],'g--', [0,nWafers],[ylActual, ylActual],'k-')
leg = ax.legend((r"$Y_L$", r"$\hat{Y}_L$", r"$\bar{Y}_L$"), 'best', shadow=True, prop = prop)
ax.grid(True)
ax.set_title('Yield Loss')
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
pylab.close()
[docs]def laplacianScores(filename, Scores, Ranking):
plt.plot(Scores[Ranking], 'k-')
plt.grid(True)
plt.xlabel('Features Retained')
plt.ylabel('Laplacian Score')
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')
plt.close()
[docs]def wafermap(x, y, val, filename=None):
xmax, ymax = max(x), max(y)
colMap = np.zeros((xmax, ymax))
for i in range(len(x)):
x, y, C = xy_coords.ix[i,0], xy_coords.ix[i,1], val[i]
colMap[x-1,y-1] = C
plt.imshow(colMap, cm.RdYlGn, interpolation='nearest')
if filename==None:
plt.show()
else:
plt.savefig(filename, dpi = 150, format='pdf')