hello and welcome back to another MATLAB
video today we're gonna be talking about
neural networks and we'll train one to
classify human activities based on
sensor data from smartphones neural
networks are useful in many applications
they can be used for clustering
classification regression and time
series predictions a neural network is
an adaptive system that learns by using
interconnected nodes neural networks
consist of one or more layers they
include at least three layers the input
layer a hidden layer and the output
layer in general the algorithm involves
a series of mathematical operations that
calculate a weighted sum of the inputs
at each node each neuron and a layer has
adjustable weights for its input and an
adjustable bias a neural network
operates by adjusting all of these
weights and biases and minimizing the
error throughout the training phase to
achieve more accurate results let's look
at this further with a demo this example
uses sensor data containing measurements
taken from smartphones worn by people
while doing five different activities
walking sitting laying walking up stairs
and walking down stairs the goal of this
analysis is to build a model to
automatically identify the activity type
even the sensor measurements using a
neural network we first import the data
set which contains the activity label
and statistical measurements from the
sensors in this case we are solving a
classification problem and we'll create
a neural network for pattern recognition
there are different functions for
creating different types of networks use
the documentation to determine the
function and to learn more about the
types of networks let's create a simple
feed-forward pattern recognition network
with the default values the network
variable contains information about the
parameters and equations and will be
updated as the model trains you can also
visualize the network the default is 10
neurons and one hidden layer you can
access the layer information including
the weights and biases these are
currently empty since we haven't yet
trained the model
next we'll include the ratio for
splitting the training validation and
test data the network uses this
information to evaluate the accuracy and
optimize the parameters during training
before we can train the network the data
must be prepared the pattern recognition
network expects the variables to be
along the rows and observations along
the columns we can simply transpose the
data in our example to achieve this
arrangement
this type of network the predictor and
response or x and y variables must be
numeric you can use a dummy variable to
represent the categorical data like the
activity as a matrix of ones and zeros
now we are ready to train a network
using the training data you can examine
progress while the network is training
and stop early if needed
now the network has finished training
and contains updated parameter values
learn from the data remember there was
one hidden layer with ten nodes and one
output layer our dataset has five
classes so there are five output nodes
the weeds and biases have been updated
with the values determine from the
training now we can test the network and
predict the activity using the test data
the result is a score belonging to each
class we can determine the predicted
class and convert the numeric values to
the original labels for comparison find
the accuracy and plot a confusion matrix
to evaluate the classifications laying
and sitting are almost all classified
correctly and while most are correct the
different types of walking are
occasionally classified as one another
this seems like a good network with
reasonable miss classifications but you
can explore ways to improve even more
there are many strategies for improving
the network we could try updating some
parameters for training and evaluating
the network see the documentation for
more about the different parameters for
different networks there's not much
improvement in the output here we could
continue to make adjustments or try
different types of networks for example
you could create a network with more
hidden layers or a deep neural network
there are many types of deep networks
supported in MATLAB and resources for
deep learning for more info check out
the links in the description below
there's always room for improvement but
this model seems to be performing well
enough with 92% accuracy can now take
steps to prepare to use this model in a
production environment or integrate
within a system when deploying you
capture your steps in a function and
will also need to save the network or
recreate it you can generate a matlab
function or Simulink diagram for
simulating your neural network use Gen
function to create the neural network
including all settings weight and bias
values functions and calculations in one
MATLAB function file now our neural
network could be used in a simulant
model or included an application written
in C C++ Java Python and more see the
documentation for details now that we
have a deeper understanding of neural
nowhere
in MATLAB we can more effectively train
and evaluate these models for more
practice you can search the
documentation for examples thanks for
watching and I'll see you in another
video