def Percentage_Change_Plot( params , base_name ):
    """ This function creates a vertical bar graph of the percentage change
        of values passed in with x_data and given labels in labels. params
        contain optional plotting options. """
    wc.Sep()
    logging.info( "Percentage_Change_Plot" )
    fig = plt.figure()
    axes1 = fig.add_subplot( 111 )
    bar_list = []
    legend_list = []
    names_list = []
    bar_number = 0
    for key in params[ "components" ]:
        if "width" in params[ "components" ][ key ]:
            width = float( params[ "components"][ key ][ "width" ] )
        else:
            width = 0.35
        if "color" in params[ "components" ][ key ]:
            color = params[ "components" ][ key ][ "color" ]
        else:
             color = 'b'
        bar_list.append( axes1.bar( bar_number , \
            params[ "components" ][ key ][ "p_change" ] , \
                width , c = color ) )
        legend_list.append( bar_list[ bar_number ][ 0 ] )
        if "label" in params:
            names_list.append( params[ "components" ][ key ][ "label" ] )
        else:
            names_list.append( str( key ) )
# This simply creates a legend for our plot
    ax.legend( legend_list , names_list )
    if "title" in params:
        axes1.set_title( params[ "title" ] )
    else:
        axes1.set_title( "Percentage Diff Plot " )
    if "y_label" in params:
        axes1.set_ylabel( params[ "y_label" ] )
    else:
        axes1.set_ylabel( "y axis" )
    if "x_label" in params:
        axes1.set_xlabel( params[ "x_label" ] )
    else:
        axes1.set_xlabel( "x axis" )
    if "legend_loc" in params:
        plt.legend( loc = params[ "legend_loc" ] )
    else:
        plt.legen( loc = "upper right" )
    if "title" in params:
        plt.savefig( base_name + "_" + params[ 'title' ] + ".eps" , \
            format = 'eps' , dpi = 1000 )
    else:
        plt.savefig( base_name + "_bar_" + str( np.random.randint( 100 , \
            size = 1 ) ) + ".eps" , format = 'eps' , dpi = 1000 )
    plt.cla()
    return
hist=model.fit(x_train, y_train, epochs=1000, callbacks=[checkpoint, earlystopping],validation_split=(0.3))
loss_and_metrics = model.evaluate(x_test, y_test, batch_size=14)
#------------------------------------------------------------------------------------------------------------------#
plt.figure(figsize=(10,6))
plt.subplot(2,1,1,)
plt.plot(hist.history['loss'], marker='.', c='red', label='loss') #plt.plot(x,y,hist.history['loss'])- x, y 별도추가 추가하지 않으면 epochs 순으로 기록 

plt.plot(hist.history['val_loss'], marker='.', c='blue', label='val_loss')
# plt.plot(hist.history['acc'])
# plt.plot(hist.history['val_acc'])
plt.grid()
plt.title('loss')
plt.ylabel('loss')
plt.xlabel('epoch')
# plt.legend(['loss', 'val_loss'])
plt.legen(loc='upper right')
plt.show()

plt.subplot(2,1,2,)
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'])
# plt.plot(hist.history['acc'])
# plt.plot(hist.history['val_acc'])
plt.grid()
plt.title('accuracy')
plt.ylabel('accuracy')
plt.xlabel('epoch')
plt.legend(['loss', 'val_acc'])
plt.show()
#------------------------------------------------------------------------------------------------------------------#
print('')
plt.legend()
plt.show()

# Visualising the Test set results
from matplotlib.colors import ListedColormap
X_set, y_set = X_test, y_test
X1, X2 = np.meshgrid(
    np.arange(start=X_set[:, 0].min() - 1,
              stop=X_set[:, 0].max() + 1,
              step=0.01),
    np.arange(start=X_set[:, 1].min() - 1,
              stop=X_set[:, 1].max() + 1,
              step=0.01))
plt.contourf(X1,
             X2,
             Classifier.predict(np.array([X1.ravel(),
                                          X2.ravel()]).T).reshape(X1.shape),
             alpha=0.75,
             cmap=ListedColormap(('red', 'green', 'blue')))
plt.xlim(X1.min(), X1.max())
plt.ylim(X2.min(), X2.max())
for i, j in enumerate(np.unique(y_set)):
    plt.scatter(X_set[y_set == j, 0],
                X_set[y_set == j, 1],
                c=ListedColormap(('red', 'green', 'blue'))(i),
                label=j)
plt.title('Logistic Regression (Test set)')
plt.xlabel('LD1')
plt.ylabel('LD2')
plt.legen()
plt.show()
Esempio n. 4
0
from matplotlib import pyplot as plt

plt.style.use("fivethirtyeight")

minutes = [1, 2, 3, 4, 5, 6, 7, 8, 9]

player1 = [1, 2, 3, 3, 4, 4, 4, 4, 5]
player2 = [1, 1, 1, 1, 2, 2, 2, 3, 4]
player3 = [1, 1, 1, 2, 2, 2, 3, 3, 3]

labels = ['player1', 'player2', 'player3']
colors = ['008fd5', 'fc4f30', '6d904f']

plt.stackplot(minutes, player1, player2, player3, labels=labels, colors=colors)
plt.legen(loc='upper left')
plt.title("My Awesome Stack Plot")
plt.tight_layout()
plt.show()

# Colors:
# Blue = #008fd5
# Red = #fc4f30
# Yellow = #e5ae37
# Green = #6d904f
Esempio n. 5
0
grades = [83, 95, 91, 87, 70, 0, 85, 82, 100, 67, 73, 77, 0]

histogram = Counter(min(grade // 10 * 10, 90) for grade in grades)
plt.bar(
    [x + 5 for x in histogram.keys()],  ## shift bars to right by 5
    histogram.values(),  ### give bars its respective correct height
    10,  ##barwidth of 10
    edgecolor=(0, 0, 0))  ## black edges for bar
plt.axis([-5, 105, 0, 5])
plt.xticks([10 * i for i in range[11]])
plt.xlabel("Decile")
plt.ylabel("# of Students")
plt.title("Distribution of Exam 1 Grades")
plt.show

###line charts

variance = [1, 2, 4, 8, 16, 32, 64, 128, 256]
bias_squared = [256, 128, 64, 32, 16, 8, 4, 2, 1]
total_error = [x + y for x, y in zip(variance, bias_squared)]
xs = [i for i, _ in enumerate(variance)]

plt.plot(xs, variance, 'g-', label='variance')  ##green solid
plt.plot(xs, bias_squared, 'r-.', label='bias^2')  ## red dashed
plt.plot(xs, total_error, 'b:', label='total errror')  ##blue dotted

plt.legen(loc=9)
plt.xlabel("model complexity")
plt.xticks([])
plt.title("Bias Variance Tradeoff")
plt.show()