MATLAB을 사용해 Neural Networks 시작하기
* 한국어 자막을 포함한 영상입니다.
뉴럴 네트워크 (또는 신경망)은 클러스터링, 분류, 회귀 및 시계열 예측 등 다양한 분야에 사용됩니다. 본 영에서는 뉴럴 네트워크의 개념에 대해 살펴보고, MATLAB에서 신경망을 사용하는 방법을 보여드립니다.
예제로 스마트폰의 센서 데이터를 기반으로 인간 활동을 분류하기 위해 뉴럴 네트워크을 훈련시키는 방법을 간략하게 설명합니다. 또한 데이터 준비, 네트워크를 훈련, 검증 및 개선 등 네트워크를 만드는 방법을 소개합니다. 네트워크를 업데이트하고 배포해보세요.
발행: 2020년 6월 2일
Hello and welcome back to another MATLAB video. Today we’re going to be talking about neural networks and we will 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 3 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 in a layer has adjustable weights for its inputs and an adjustable bias.
A neural network operates (is trained) by adjusting all of these weights and biases and minimizing the error throughout the training phase to achieve more accurate results.
Let’s discuss this further this with a demo
This example uses sensor data containing measurements taken from smartphones worn by people while doing 5 different activities - walking, sitting, laying, walking upstairs and downstairs.
The goal of this analysis is to build a model to automatically identify the activity type given 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 will create a neural network for pattern recognition.
There are different functions for creating various 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.
Create network
In this case, we are solving a classification problem and will create a neural network for pattern recognition.
There are different functions for creating various 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 visualize the network. The default is 10 neurons in 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 will 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.
For this type of network, the predictor and response, or X and Y variables must be numeric. You can use a dummy variable to represent categorical data, like the activity, as a matrix of 1’s and 0’s.
Now we are ready to train the 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, learned from the data.
Remember there was one hidden layer with 10 nodes and one output layer. Our data set has 5 classes, so there are 5 output nodes.
The weights and biases have been updated with the values determined from training.
Now we can test the network and predict the activity using the test data.
The result is a score of 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 misclassifications, but you can explore ways to improve even more.
There are many strategies for improving the network.
We can try updating some parameters for training and evaluating the network. See the documentation for details about the 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. We could now take steps to prepare to use this model in a production environment or integrate with a system.
When deploying, you capture your steps into 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 genfunction 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 Simulink model or included in an application written in C/C++, Java, Python and more. See the documentation for more info.
Now that we have a deeper understanding of neural networks 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.