Fully Connected Networks
Practice
1# Training linear regression in Keras2# import Keras3from tensorflow import keras45# create the model6model = keras.models.Sequential()7# indicate how the neural network is arranged8# units - the number of neurons in the layer9# input_dim - the number of inputs in the layer10model.add(keras.layers.Dense(units=1, input_dim=features.shape[1]))11# indicate how the neural network is trained12model.compile(loss='mean_squared_error', optimizer='sgd')1314# train the model15model.fit(features, target)
1# Training logistic regression in Keras2# import Keras3from tensorflow import keras45# create the model6model = keras.models.Sequential()7# indicate how the neural network is arranged8# units - the number of neurons in the layer9# input_dim - the number of inputs in the layer10# activation - activation function11model.add(keras.layers.Dense(units=1, input_dim=features_train.shape[1],12 activation='sigmoid'))13# indicate how the neural network is trained14model.compile(loss='binary_crossentropy', optimizer='sgd')1516# train the model17model.fit(features, target)
1# Training fully connected neural networks in Keras2# import Keras3from tensorflow import keras45# create the model6model = keras.models.Sequential()7# indicate how the neural network is arranged8# We have two layers: the first one has 10 neurons, the second one has one neuron9# units - the number of neurons in the layer10# input_dim - the number of inputs in the layer11# activation - activation function12model.add(keras.layers.Dense(units=10, input_dim=features_train.shape[1],13 activation='sigmoid'))14model.add(keras.layers.Dense(units=1, activation='sigmoid'))1516# indicate how the neural network is trained17model.compile(loss='binary_crossentropy', optimizer='sgd', metrics=['acc'])1819# train the model20model.fit(features, target)
1# Working with Images in Python2import numpy as np3from PIL import Image45# Importing the image6image = Image.open('image.png')7image_array = np.array(image)8print(image_array)910# Plotting the image11plt.imshow(image_array)1213# Plotting the black and white image14plt.imshow(image_array, cmap='gray')1516# Adding the color bar to the image17plt.colorbar()