Professional Documents
Culture Documents
DL With Keras
DL With Keras
TensorFlow,
popularity, both
library.
classification problems.
networks?
red,
convolution process.
a time.
3
As we discussed earlier, activation
origin.
JupyterLab Notebook.
in our dataset.
Then we repeat the same thing for the other hidden layer,
Keras library.
in this video, we will learn how to use the Keras library to build models for
classification problems. Let's say that we would like to build a model that
would inform someone whether purchasing a certain car would be a good choice
based on the price of the car, the cost to maintain it, and whether it can
accommodate two or more people. So, here is a dataset that we are calling "car_data".
I already cleaned the data, as you can see, where I used one-hot encoding to
transform each category of price, maintenance, and how many people the car
can accommodate, into separate columns. So the price of the car can be either
car can also be high, medium, or low, and the car can either fit two people or
more. If you take the first car in the dataset, it is considered an expensive
car, has high maintenance cost, and can fit only two people. The decision is 0,
meaning that buying this car would be a bad choice. A decision of 1 means that
buying the car is acceptable, a decision of 2 means that buying the car would
be a good decision, and a decision of 3 means that buying the car would be
a very good decision. Let's use the same neural network as the one we used for
the regression problem that we discussed in the previous video. So a network that
still takes eight inputs or predictors, consists of two hidden layers, each of
five neurons, and an output layer. Next, let's divide our dataset into
can't use the target column as is; we actually need to transform the column
into an array with binary values similar to one-hot encoding like the output
function from the Keras utilities package. In other words, our model instead
of having just one neuron in the output layer, it would have four neurons,
since our target variable consists of four categories. In terms of code, the
structure of our code is pretty similar to the one we use to build the model for
our regression problem. We start by importing the Keras library and the
Sequential model and we use it to construct our model. We also import the
"Dense" layer since we will be using it to build our network. The additional import
proceed to constructing our layers. We use the add method to create two hidden
layers, each with five neurons and the neurons are activated using the ReLU
activation function. Notice how here we also specify the softmax function as the
activation function for the output layer, so that the sum of the predicted values
from all the neurons in the output layer sum nicely to 1. Then in defining our
measure instead of the mean squared error that we use for regression, and we
evaluation metric in Keras but you can actually define your own evaluation
metric and pass it in the metrics parameter. Then we fit the model.
Notice how this time we're specifying the number of epochs for training the
regression model, but we could have done that. Finally, we use the predict method
to make predictions. Now the output of the Keras predict method would be
something like what's shown here. For each data point, the output is the
the four classes. For each data point, the probabilities should sum to 1,
and the higher the probability the more confident is the algorithm that
a datapoint belongs to the respective class. So for the first data point or the
first car in the test set, the decision would be 0 meaning not acceptable,
since the first probability is the highest, with a value of 0.99 or close to
1, in this case. Similarly, for the second datapoint, the decision is also 0 or
not acceptable, since the probability for this class is the highest, again with a
value of 0.99 or almost 1. For the first three datapoints, the model is very
confident that purchasing these cars is not acceptable. As for the last three
the second class are higher than the rest of the classes. But notice how the
the model is not very confident but it would lean towards accepting purchasing
these cars. In the lab part, you will get the chance to build your own
regression and classification models using the Keras library, so make sure to
So far, we discussed two supervised deep learning models, which are the
convolutional neural network and the recurrent neural network. In this video, we
the compression and the decompression functions are learned automatically from
data. instead of being engineered by a human. Such autoencoders are built using
neural networks. Autoencoders are data specific, which means that they will only
be able to compress data similar to what they have been trained on. Therefore, an
representation of the input image. Then, using a decoder the original image is
autoencoders can learn data projections that are more interesting than a
principal component analysis PCA or other basic techniques, which can handle
Restricted Boltzmann Machines or (RBMs) for short. RBMs have been successfully
regenerate it, then they can learn the distribution of the minority class in an
imbalance dataset ,and then generate more data points of that class, transforming
Machines.
67
y Cajal,
left.
networks?
red,
green, and blue components of each pixel
convolution process.
a time.
In the previous video, we learned about convolutional neural networks, which are
will learn about another supervised deep learning model, which is the recurrent
neural network. So far, we have seen neural networks and deep learning models
that see datapoints as independent instances. However, let's say you want to
Well, you cannot assume that scenes in a movie are independent, and therefore,
traditional deep learning models are not suitable for this application. Recurrent
for short, are networks with loops that don't just take a new input at a time,
but also take in as input the output from the previous dat point that was fed
into the network. Accordingly, this is how the architecture of a recurrent neural
network would look like. Essentially, we can start with a normal neural network.
At time t = 0, the network takes in input x0 and outputs a0. Then, at time t = 1,
weighted with weight w0,1, and so on and so forth. As a result, recurrent neural
networks are very good at modelling patterns and sequences of data, such as
texts, genomes, handwriting, and stock markets. These algorithms take time and
sequence into account, which means that they have a temporal dimension. A very
popular type of recurrent neural network is the long short-term memory model or
the (LSTM) model for short. It has been successfully used for many applications
handwriting generation, which I described in the welcome video of this course. Also
LSTM models have been successfully used to build algorithms that can
autoencoders.