def main(): df = pd.read_csv("/home/saxobeat/PythonML/MLCodes/Spambase/Dataset/spamdata.csv") features = df.iloc[:,0:57].values labels = df.iloc[:,57].values X_train, X_test, y_train, y_test = tts(features, labels, test_size=0.25, shuffle=True, random_state=8) models = [] models.append(('LR', LR(solver='lbfgs', max_iter=2000, tol=0.0001))) models.append(('LDA', LDA())) models.append(('DTC', DTC())) models.append(('KNC', KNC())) models.append(('MNB', MNB())) models.append(('RFC', RFC(n_estimators=100))) models.append(('SVC', SVC(gamma='scale', kernel='rbf', probability=True))) x0 = np.linspace(0,1,10) plt.plot([0,1],[0,1],'k',linestyle='--') for name,model in models: model.fit(X_train, y_train) y_pred = model.predict_proba(X_test) y_score = y_pred[:,1] fpr, tpr, thresholds = roc_curve(y_test, y_score) label = "{}({})".format(name,auc(fpr, tpr)) plt.plot(fpr,tpr,label=label) plt.legend() # plt.legend(name) plt.title("Reciever Operating Characteristics") plt.grid() plt.cool() plt.xlabel("Fasle Positive Rate") plt.ylabel("True Positive Rate") plt.savefig("roc.pdf")
def __call__(self,u,v,w,iteration): q = 4 plt.cool() if self.x == None: ny = v.shape[1] nz = v.shape[0] self.x,self.y = np.meshgrid(range(ny),range(nz)) x,y = self.x,self.y if self.iterations == None: self.iterations = self.sim.bulk_calc(getIteration()) all_itr = self.iterations if self.xvar == None: class temp(sim_operation): def get_params(self): return ["u"] def __call__(self,u): return np.max(self.sim.ddx(u)) self.xvar = self.sim.bulk_calc(temp()) xvar_series = self.xvar min = np.min(xvar_series) max = np.max(xvar_series) if min <= 0: min = 0.000001 if max <= min: max = 0.00001 avgu = np.average(u,2) avgv = np.average(v,2) avgw = -np.average(w,2) xd = self.sim.ddx(u) xd2d = np.max(xd,2) xd1d = np.max(xd2d,1) plt.subplot(221) plt.imshow(avgu) plt.quiver(x[::q,::q],y[::q,::q],avgv[::q,::q],avgw[::q,::q]) plt.title('Avg u') plt.axis("tight") plt.subplot(222) plt.imshow(xd2d) plt.title('Max x Variation (y-z)') plt.axis("tight") plt.subplot(223) plt.plot(xd1d) plt.title('Max x Variation (z)') plt.axis("tight") plt.subplot(224) plt.plot(all_itr,xvar_series, '--') plt.plot([iteration,iteration],[min,max]) plt.semilogy() plt.title('Max x Variation (t)') plt.axis("tight")
def plot(): # set default color #colors = ['brown', 'r', 'b', 'oldlace', 'yellowgreen', 'teal', 'tomato', 'palegreen', 'cornsilk', 'pink', 'crimson', 'darkgreen', 'hotpink', 'gray', 'green', 'gold', 'beige', 'bisque'] colors = [(0., 1, 1), (0.05, 1, 1), (0.11, 0, 0), (0.66, 1, 1), (0.89, 1, 1), (1, 0.5, 0.5), (0, 1, 1), (0.05, 1, 1), (0.11, 0, 0), (0.375, 1, 1), (0.64, 1, 1), (0.91, 0, 0), (1, 0, 0), (0., 1, 1), (0.05, 1, 1), (0.11, 1, 1), (0.34, 1, 1), (0.65, 0, 0), (1, 0, 0)] Raw_edge = [] Bcc_matrix = [] cut_arr = [] n = readRawFile( "/Users/luodian/Desktop/DSA/Graph Plus/Graph Plus/DATA/in.txt", Raw_edge) readBccFile( "/Users/luodian/Desktop/DSA/Graph Plus/Graph Plus/DATA/Bcc.txt", Bcc_matrix, cut_arr) all_node = range(1, n + 1) G = nx.Graph() G.add_edges_from(Raw_edge) G.add_nodes_from(all_node) pos = nx.spring_layout(G) # color the bcc nodes for i in xrange(0, len(Bcc_matrix)): nx.draw_networkx_nodes(G, pos, nodelist=Bcc_matrix[i], alpha=1, node_color=colors[i]) # color the cut nodes nx.draw_networkx_nodes(G, pos, nodelist=cut_arr, node_color='salmon') nx.draw_networkx_edges(G, pos, edge_color='black', alpha=1, width=0.8) nx.draw_networkx_labels(G, pos) # print type(node_blue) # nx.draw_networkx_edges(G, pos = nx.spring_layout(G), edgelist=[(1,2)], edge_color = 'blue') # nx.draw_networkx_nodes(G, pos, nodelist = Bcc_matrix[1], node_color = 'b') font = {'color': 'k', 'fontweight': 'bold', 'fontsize': 14} plt.title("The cut and bcc info", font) plt.annotate('The cut vertexs', (1, 1.15)) plt.plot([0.95], [1.1666], color='salmon', marker='o', markersize=15) plt.axis('off') plt.cool() plt.savefig('Bcc.png', dpi=233) plt.show()
def plot(x, y, z, c, experimentNumber): x = np.asarray(x) y = np.asarray(y) z = np.asarray(z) c = np.asarray(c) fig = plt.figure() ax = fig.gca(projection='3d') img = ax.scatter(x, y, z, c=c, cmap=plt.cool()) ax.set_xlabel('Inputs') ax.set_ylabel('Outputs') ax.set_zlabel('$P_{expected}$') cbrar = fig.colorbar(img) cbrar.set_label('$P_{real}$') # ax.legend() plt.title("Relation of inputs, outputs and non-determinism") outF = open("results/experiment2.txt", "w") sys.stdout = outF print("inputs,outputs,prevalence,nondeterminism") for i, _ in enumerate(x): print("{},{},{:04.2f},{:06.4f}".format(x[i], y[i], z[i], c[i])) plt.savefig('results/experiment4.png'.format(experimentNumber)) plt.show()
def plot_convergence( order_of_probed_points: List[List[int]], loss_function: Callable, truth_value: List[int], step_sizes: List[int], ) -> None: fig = plt.figure() ax = fig.add_subplot(projection='3d') # probed points x = np.array([point[0] for point in order_of_probed_points] + [truth_value[0]]) y = np.array([point[1] for point in order_of_probed_points] + [truth_value[1]]) z = np.array([point[2] for point in order_of_probed_points] + [truth_value[2]]) c = np.array([ loss_function(point, step_sizes, truth_value) for point in order_of_probed_points ] + [0]) # ax.plot3D(x, y, z, 'grey') image = ax.scatter3D(x, y, z, c=c, cmap=plt.cool()) ax.set_xlabel('print temperature') ax.set_ylabel('retraction distance') ax.set_zlabel('flow rate') fig.colorbar(image, pad=0.05, label="loss", location='left') plt.show()
def write_snrmap(outputfile, intsnr, ds): """ Update the CTF parameters file with new CTF file lines. Parameters: outputfile Filename of output image file intsnr Integrated SNR ds Frequency sampling """ # Import plotting libaries import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt # Setup plotting parameters matplotlib.rcParams['xtick.direction'] = 'out' matplotlib.rcParams['ytick.direction'] = 'out' # Create plotting variables x = np.arange(0., ds * len(intsnr), ds) y = np.arange(0., 0.5, 0.005) X, Y = np.meshgrid(x, y) Z = np.transpose(np.array(intsnr)) # Plot result plt.figure() CS = plt.contourf(X, Y, Z, np.arange(0., np.max(intsnr) + old_div(np.max(intsnr), 20.), old_div(np.max(intsnr), 20.)), antialiased=True) CB = plt.colorbar(CS, shrink=0.8, format='%i') plt.cool() plt.title('Image Coverage of Frequency Space') plt.xlabel('Frequency (1/A)') plt.ylabel('Signal-to-Noise Ratio') plt.savefig(outputfile)
def plot(label): # set default color # colors = ['brown', 'r', 'b', 'oldlace', 'yellowgreen', 'teal', 'tomato', 'palegreen', 'cornsilk', 'pink', 'crimson', 'darkgreen', 'hotpink', 'gray', 'green', 'gold', 'beige', 'bisque'] colors = [(0., 1, 1), (0.05, 1, 1), (0.11, 0, 0), (0.66, 1, 1), (0.89, 1, 1), (1, 0.5, 0.5), (0, 1, 1), (0.05, 1, 1), (0.11, 0, 0), (0.375, 1, 1), (0.64, 1, 1), (0.91, 0, 0), (1, 0, 0), (0., 1, 1), (0.05, 1, 1), (0.11, 1, 1), (0.34, 1, 1), (0.65, 0, 0), (1, 0, 0)] Raw_edge = [] n = readRawFile( "/Users/luodian/Desktop/network_alignment/graphs/{}.txt".format(label), Raw_edge) n = int(n) all_node = range(0, n) G = nx.DiGraph() G.add_edges_from(Raw_edge) G.add_nodes_from(all_node) pos = nx.spring_layout(G) nx.draw_networkx_edges(G, pos, edge_color='blue', arrows=True, arrowstyle='->', arrowsize=20, alpha=1, width=0.8) nx.draw_networkx_labels(G, pos) # print type(node_blue) # nx.draw_networkx_edges(G, pos = nx.spring_layout(G), edgelist=[(1,2)], edge_color = 'blue') nx.draw_networkx_nodes(G, pos, nodelist=all_node, node_color='orange') font = {'color': 'k', 'fontweight': 'bold', 'fontsize': 14} plt.title("Graph of {}".format(label), font) # plt.annotate('The cut vertexs', (1, 1.15)) # plt.plot([0.95], [1.1666], color='salmon', marker='o', markersize=15) plt.axis('off') plt.cool() plt.savefig('{}_digraph.png'.format(label), dpi=200) plt.show()
def write_snrmap( outputfile, intsnr, ds ) : """ Update the CTF parameters file with new CTF file lines. Parameters: outputfile Filename of output image file intsnr Integrated SNR ds Frequency sampling """ # Import plotting libaries import matplotlib import numpy as np import matplotlib.cm as cm import matplotlib.mlab as mlab import matplotlib.pyplot as plt # Setup plotting parameters matplotlib.rcParams['xtick.direction'] = 'out' matplotlib.rcParams['ytick.direction'] = 'out' # Create plotting variables x = np.arange( 0., ds * len( intsnr ), ds ) y = np.arange( 0., 0.5, 0.005 ) X,Y = np.meshgrid( x, y ) Z = np.transpose( np.array( intsnr ) ) # Plot result plt.figure( ) CS = plt.contourf( X, Y, Z, np.arange( 0., np.max( intsnr ) + np.max( intsnr ) / 20., np.max( intsnr ) / 20. ), antialiased = True ) CB = plt.colorbar( CS, shrink = 0.8, format = '%i' ) plt.cool( ) plt.title( 'Image Coverage of Frequency Space' ) plt.xlabel( 'Frequency (1/A)' ) plt.ylabel( 'Signal-to-Noise Ratio' ) plt.savefig( outputfile )
def show_relative_error_results(self, expected_results): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') result = self.anfis_estimate_labels(self.premises, self.op, self.tsk) error_result = np.abs(expected_results - result) / expected_results img = ax.scatter(self.training_data[0], self.training_data[1], self.training_data[2], c=error_result.flatten(), cmap=plt.cool()) fig.colorbar(img) fig.canvas.set_window_title('Relative error') plt.show()
def graph(s): """ This code is horrific. Unfortunately started local NSGA2 without checking so will have to do for now :param s: seed :return: nothing """ data = [] input = [] datat = True mixed = [[], [], [], []] for x in open("results/" + str(s) + "_results.txt"): x = x.replace("\n", "") if x == "#": datat = False continue x = x.replace("\n", "") x = x.split(",") if datat: data.append([-float(x[0]), -float(x[1])]) mixed[0].append(-float(x[0])) mixed[1].append(-float(x[1])) else: input.append([int(float(x[0])), float(x[1])]) mixed[2].append(int(float(x[0]))) mixed[3].append(float(x[1])) #Scatter(tight_layout=True).add(np.array(mixed),s=10).show() #Scatter().add(np.array(data)).show() #Scatter().add(np.array(input)).show() fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = np.array(mixed[0]) y = np.array(mixed[1]) z = np.array(mixed[2]) c = np.array(mixed[3]) img = ax.scatter(x, y, z, c=c, cmap=plt.cool()) fig.colorbar(img) plt.show()
def __call__(self,u,iteration): plt.cool() if self.iterations == None: self.iterations = self.sim.bulk_calc(getIteration()) all_itr = self.iterations if self.xvar == None: class temp(sim_operation): def get_params(self): return ["u"] def __call__(self,u): return np.max(self.sim.ddx(u)) self.xvar = self.sim.bulk_calc(temp()) xvar_series = self.xvar min = np.min(xvar_series) max = np.max(xvar_series) if min <= 0: min = 0.000001 if max <= min: max = 0.00001 uavg = np.average(u,2) xd = self.sim.ddx(u) xd2d = np.max(xd,2) plt.subplot(241) plt.imshow(xd2d) plt.title('Max x Variation (y-z)') plt.axis("tight") plt.subplot(242) plt.plot(uavg[58,:]) plt.title('z = 58') plt.axis("tight") plt.subplot(243) plt.plot(uavg[60,:]) plt.title('z = 60') plt.axis("tight") plt.subplot(244) plt.plot(uavg[62,:]) plt.title('z = 62') plt.axis("tight") plt.subplot(245) plt.plot(all_itr,xvar_series, '--') plt.plot([iteration,iteration],[min,max]) plt.semilogy() plt.title('Max x Variation (t)') plt.axis("tight") plt.subplot(246) plt.plot(uavg[64,:]) plt.title('z = 64') plt.axis("tight") plt.subplot(247) plt.plot(uavg[64,:]) plt.title('z = 64') plt.axis("tight") plt.subplot(248) plt.plot(uavg[66,:]) plt.title('z = 66') plt.axis("tight")
x_range = np.linspace(x_min - 1, x_max + 1, 200) y_range = np.linspace(y_min - 1, y_max + 1, 200) xx, yy = np.meshgrid(x_range, y_range) for k, model in enumerate((LDA(), QDA())): #fit, predict clf = model clf.fit(points, labels) z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) z = z.reshape(200, 200) z_p = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()]) #draw areas and boundries pl.figure() pl.pcolormesh(xx, yy, z) pl.cool() for j in range(len(u)): pl.contour(xx, yy, z_p[:, j].reshape(200, 200), [0.5], lw=3, colors='k') #draw points for i, point in enumerate(x): pl.plot(point[:, 0], point[:, 1], c[i] + m[i]) #draw contours for i in range(len(u)): prob = mvn2d(x_range, y_range, u[i], sigma[i]) cs = pl.contour(xx, yy, prob, colors=c[i])
import matplotlib.pyplot as plt import numpy as np dx, dy = 0.015, 0.05 x = np.arange(-4.0, 4.0, dx) y = np.arange(-4.0, 4.0, dy) X, Y = np.meshgrid(x, y) extent = np.min(x), np.max(x), np.min(y), np.max(y) Z1 = np.add.outer(range(8), range(8)) % 2 plt.imshow(Z1, cmap="binary_r", interpolation="nearest", extent=extent, alpha=1) def copyassignment(x, y): return (1 - x / 2 + x**5 + y**6) * np.exp(-(x**2 + y**2)) z2 = copyassignment(X, Y) plt.imshow(z2, alpha=0.7, interpolation='bilinear', extent=extent) plt.cool() plt.title('matplotlib.pyplot.cool() function example', fontweight="bold") plt.show()
x_range = np.linspace(x_min - 1, x_max + 1, 200) y_range = np.linspace(y_min - 1, y_max + 1, 200) xx, yy = np.meshgrid(x_range, y_range) for k, model in enumerate((LDA(), QDA())): #fit, predict clf = model clf.fit(points, labels) z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) z = z.reshape(200, 200) z_p = clf.predict_proba(np.c_[xx.ravel(), yy.ravel()]) #draw areas and boundries pl.figure() pl.pcolormesh(xx, yy, z) pl.cool() for j in range(len(u)): pl.contour(xx, yy, z_p[:, j].reshape(200, 200), [0.5], lw=3, colors='k') #draw points for i, point in enumerate(x): pl.plot(point[:, 0], point[:, 1], c[i] + m[i]) #draw contours for i in range(len(u)): prob = mvn2d(x_range, y_range, u[i], sigma[i]) cs = pl.contour(xx, yy, prob, colors=c[i]) pl.title('Seperate {0} classes using {1}'. format(len(u), model_names[k]))
from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt fig = plt.figure() ax2 = fig.add_subplot(111, projection='3d') x1 = df.ix[0:, 'x1'] x2 = df.ix[0:, 'x2'] x3 = df.ix[0:, 'x3'] y = df.ix[0:, 'y'] if sys.argv[1:] == ['winter']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.winter()) elif sys.argv[1:] == ['cool']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.cool()) elif sys.argv[1:] == ['viridis']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.viridis()) elif sys.argv[1:] == ['plasma']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.plasma()) elif sys.argv[1:] == ['inferno']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.inferno()) elif sys.argv[1:] == ['jet']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.jet()) elif sys.argv[1:] == ['gist_ncar']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.gist_ncar()) elif sys.argv[1:] == ['rainbow']: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.nipy_spectral()) else: p = ax2.scatter(x1, x2, x3, c=y, cmap=plt.nipy_spectral())