Multiclass Lab - plotting help?

Hello
In this lab I want to tweak some things to get a better idea of how it works.
For instance, I want to change the number of neurons in Layer 1 from 2 to 4 to 8 and more to see how ReLU is sorting stuff - but i can’t get a good plot that shows me all the units in this Layer when there is more than 4.
Specifically, I want to change this line:
Dense(2, activation = ‘relu’, name = “L1”), to have 8 units or more - in which case this line
plt_layer_relu(X_train, y_train.reshape(-1,), W1, b1, classes)
plots all the plots too close together on one line.
Could somebody help me how to change this function to show just a few (2, or 3, or 4) plots per line with multiple lines?
Thank you!
P.S. Eventually I want to do this with Layer 2, create more Layers etc.

Hello @Svetlana_Verthein,

Sure!

I need you to add one code cell as illustrated in below:

You can copy the new code from here:

# This is temporarily added for investigations, and to be removed afterwards
def plt_layer_relu(X, Y, W1, b1, classes):
    num_rows = 2  ## Adjustable
    num_columns = 4  ## Adjustable
    figure_height = 6  ## Adjustable
    figure_width = 10  ## Adjustable
    enable_legend = False  ## Adjustable
    
    nunits = (W1.shape[1])
    Y = Y.reshape(-1,)
    fig, axes = plt.subplots(num_rows, num_columns, figsize=(figure_width, figure_height))
    fig.canvas.toolbar_visible = False
    fig.canvas.header_visible = False
    fig.canvas.footer_visible = False

    for ax, i in zip(axes.flatten(), range(nunits)):
        layerf= lambda x : np.maximum(0,(np.dot(x,W1[:,i]) + b1[i]))
        plt_prob_z(ax, layerf)
        plt_mc_data(ax, X, Y, classes, map=dkcolors_map,legend=enable_legend, size=50, m='o')
        ax.set_title(f"Layer 1 Unit {i}")
        ax.set_ylabel(r"$x_1$",size=10)
        ax.set_xlabel(r"$x_0$",size=10)
    fig.tight_layout()
    plt.show()
    
plt_layer_relu(X_train, y_train.reshape(-1,), W1, b1, classes)

You can run this code cell to see more plots, but you will also need to adjust these adjustables to see the plots clearly.

    num_rows = 2  ## Adjustable
    num_columns = 4  ## Adjustable
    figure_height = 6  ## Adjustable
    figure_width = 10  ## Adjustable
    enable_legend = False  ## Adjustable

Please experiment these settings to understand their meanings :wink:

Cheers,
Raymond

PS: An example with the above set of adjustables.

1 Like

Thank you so much, Raymond! I’ll take the extra time today to play with these things, I really want to understand this forward and backwards.

Take your time! Let us know if you have anything to share.

Cheers,
Raymond

The big thing I want to share is that it is super important to be able to plot stuff - for me, anyway. Getting the picture visually helps so much to understand the math and the programming behind it.
So I’ll definitely be reusing your code again in the future - thanks again! :grinning: :grinning:

Indeed! I can’t read too many numbers :stuck_out_tongue_closed_eyes:

Raymond