Exemplo n.º 1
0
 def visualization(self):
     feature_1 = self.x_pca[:, 0]
     feature_2 = self.x_pca[:, 1]
     labels = self.y
     cdict = {0: 'red', 1: 'green'}
     labl = {0: 'without bug', 1: 'bug'}
     marker = {0: '*', 1: 'o'}
     alpha = {0: .3, 1: .5}
     fig, ax = plt.subplots(figsize=(7, 5))
     fig.patch.set_facecolor('white')
     for l in np.unique(labels):
         ix = np.where(labels == l)
         ax.scatter(feature_1[ix],
                    feature_2[ix],
                    c=cdict[l],
                    s=100,
                    label=labl[l],
                    marker=marker[l],
                    alpha=alpha[l])
     # for loop ends
     plt.xlabel("First Principal Component", fontsize=14)
     plt.ylabel("Second Principal Component", fontsize=14)
     plt.legend()
     plt.savefig(
         str(pathlib.Path().absolute()) + "/File/PCA_visualization.png")
Exemplo n.º 2
0
    def create_plot(logbook, name_file):
        maxFitnessValues, meanFitnessValues, minFitnessValues, medianFitnessValues, stdFitnessValues = \
            logbook.select("max", "avg", "min", "median", "std")
        plt.plot(maxFitnessValues, color='red', label="Worst Fitness")
        plt.plot(meanFitnessValues, color='green', label="Mean Fitness")
        plt.plot(minFitnessValues, color='orange', label="Best Fitness")
        plt.plot(medianFitnessValues, color='blue', label="Avg. Fitness")
        plt.plot(stdFitnessValues, color='pink', label="Std. Fitness")

        plt.xlabel('Generation')
        plt.ylabel('Max / Average / Min / Median/ Std Fitness')
        plt.title('Max, Average, Min, Median and Std Fitness over Generations')
        plt.legend(loc='lower right')
        plt.savefig(name_file)
        plt.close()
Exemplo n.º 3
0
                        content = [x.strip() for x in content]
                        original_cc = []
                        supergraph_cc = []
                    for line in content:
                        value = line.split(" ")
                        if len(value):
                            supergraph_cc.append(float(value.pop()))
                            original_cc.append(float(value.pop()))

                    plt.clf()
                    plt.plot(k_array, original_cc, 'r--', k_array,
                             supergraph_cc, 'g-')
                    plt.ylabel("Clustering Coefficent")
                    plt.xlabel("k_degree")
                    plt.legend(('Original Graph', 'Supergraph'),
                               loc='lower center',
                               shadow=True)
                    plt.title(str(sys.argv[4]))
                    plt.savefig("metric_cc_web.png")  #if choose dataset web
                    #plt.savefig("metric_cc_socfb.png")
                    plt.clf()
                    list_norm = []
                    for i in norm:
                        list_norm.append(float(i))
                    list_k_array = []
                    for i in k_array:
                        list_k_array.append(float(i))
                    plt.plot(list_k_array, list_norm, 'r--')
                    plt.ylabel("Norm of vector a")
                    plt.xlabel("k_degree")
                    plt.title(str(sys.argv[4]))
Exemplo n.º 4
0
epochs = 5  #训练5次
model1.summary()  #模型输出
model1.compile(
    loss='sparse_categorical_crossentropy',  #模型编译
    optimizer='adam',
    metrics=['accuracy'])
#从训练集中抽取0.2进行验证
history = model1.fit(x_train,
                     y_train,
                     batch_size=batch_size,
                     epochs=epochs,
                     validation_split=0.2)

#-----------------------------------------------保存模型,可视化--------------------------
#保存模型
model1.save('model_CNN_text.h5')
#模型可视化
plot_model(model1, to_file='model_CNN_text.png', show_shape=True)
#加载模型
model = load_model('model_CNN_text.h5')
y_new = model.predict(x_train[0].reshape(1, 50))
#训练结果可视化
plt.plot(history.history['acc'])
plt.plot(history.history['val_acc'])
plt.title('Model accuracy')
plt.xlabel('Epoch')
plt.ylabel('Accuracy')
plt.legend(['Train', 'Valid'], loc='upper left')
plt.savefig('Valid_acc.png')
plt.show()
#-----------------------------------------------------查看解码效果--------------------------------------------
decoded_imgs = model.predict(x_test)
n = 10
plt.figure(figsize=(20, 6))
for i in range(n):
    # 原图
    ax = plt.subplot(3, n, i+1)
    plt.imshow(x_test[i].reshape(28, 28))
    plt.gray()
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)


    # 解码效果图
    ax = plt.subplot(3, n, i+n+1)
    plt.imshow(decoded_imgs[i].reshape(28, 28))
    plt.gray()
    ax.get_xaxis().set_visible(False)
    ax.get_yaxis().set_visible(False)

plt.show()
#----------------------------------------------------训练过程可视化---------------------------------------------
print(history.history.keys())
plt.plot(history.history['loss'])
plt.plot(history.history['val_loss'])
plt.title('model loss')
plt.ylabel('loss')
plt.xlabel('epoch')
plt.legend(['train', 'validation'], loc='upper right')
plt.show()