Overcoming the Challenges of Adding Machine Learning to Your Products

Building the Model for Machine Learning

Last modified by Microchip on 2025/01/28 15:24

   Organizing the Data  Deploying the Model   

Querying the Data and Pipelines

Now, let's dive into the part where you analyze your data and models. First, you need to ensure you know what data you are going to work with. You will query the data, but only a subset that is relevant to your needs. For example, you might only select samples from 60 Hz countries or samples taken indoors to create a model better suited to your specific situation.

If your sensors have changed or you have particularly noisy sensors, this might be reflected in the metadata. You can tune your model based on this metadata, either for all sensors or just a specific range. 

You need to decide what data to use and feed into your model creation pipeline. Consider what sort of sensor data to use and how to process it. For instance, all your data might be time-domain data, taken at a specific sample frequency. However, it might be more interesting to analyze it in the frequency domain, which requires a transform. You need to convert your data to the frequency domain, generate features from it, and select the most interesting features. Using these features, you can improve your model and classify the data more effectively.

What Machine Learning Model to Use?

Imagine that a machine learning model is a neural network with some inputs, sensors to process data, a hidden layer, or multiple hidden layers where calculations with weights and sums are performed, and then a bunch of outputs. These outputs might be classifiers that function purely on majority rules. You decide which one has the highest number, and that's the result you get. Whether you've detected a digit or it might be some kind of min-max function or something else.

neural network

However, not all machine learning models are neural networks. Remember the definition from earlier: machine learning is a field of artificial intelligence that enables computers to learn from data and make decisions. It does not specifically mention neural networks. Nothing in the definition excludes other types of models.

When deciding what type of machine learning model to use, you have many options: regression algorithms, clustering algorithms, decision trees, Bayesian algorithms, and deep learning algorithms. Choosing the best one for your needs can be challenging, as it depends on the specific application you are working on. Certain models are better suited to certain applications.

ml models

So, how do you determine which model is the best? One option is to hire a PhD, which is effective but costly. A more affordable alternative is to use the AutoML model-building tool in the MPLAB® Machine Learning Development Suite. AutoML analyzes the problem you are trying to solve and tests multiple models to find the one that delivers the best results. For example, it might start with a regression algorithm and then try a Bayesian algorithm. It tests these models with different weights, learns the optimal weights, and identifies which model performs the best. To add complexity, as you will see later, AutoML may even combine regression and Bayesian algorithms, or other models, based on its performance evaluations.

Back to Top

Artificial Neural Network

Let's talk about neural networks. Typically, with an artificial neural network, you have fully connected layers of neurons. The idea is that a neuron takes some inputs, applies some weights to those inputs—essentially multipliers—adds and subtracts the values together, and then gives you an output.

neural example 9

Here's an example using a touch sensor. It has a particular resolution, and the artificial neural network has been trained with certain weights to look for specific features. At the end of the process, you get a set of labels, each associated with a number. Depending on what has been drawn, the network might determine that there is only a small chance of it being a one, definitely no chance of it being a four, it doesn't really look like a five, but there is a very high probability that it is a nine. You then perform a min-max function and conclude that it is a nine. This is how you get your labels from your artificial neural network.

Back to Top

Convolutional Neural Network

A different type you might encounter is a convolutional neural network. In a convolutional neural network, you apply masks or convolutions to areas or sub-areas of your image. For instance, in the first example, you take a 28x28 image and convolve it. You multiply it between these masks, which are 5x5. As you scan that 5x5 matrix across each of the 28x28 inputs, you get a reduction in size because you lose the edges. You end up with a number of 24x24 outputs. These outputs might then go through another algorithm, such as Max pooling. Then, they are convolved again, and all of this allows you to create a model. In this case, the model is performing digit recognition, just like the previous example, but it is typically smaller and more efficient because it simplifies the data and looks for particular features. It looks for circles, straight lines, and strokes in your number data, and it is much better at handling spatially related data. It doesn't matter where the digit nine is written in that 28x28 field; it could be in the top left, the middle, or the bottom right. The convolutional neural network is better at recognizing it than an input with 782 inputs.

convolutional neural network

Back to Top

Decision Tree

Decision trees are another possible model you can use. For instance, consider a movement detector. This might have an accelerometer, microphone, and light sensor and will make decisions based on these sensors.

So, what is the accelerometer doing? If it's not moving, you then evaluate the sound. Is it silent? If so, you conclude that it's not moving and is silent. Next, you check if it is very dark. If it is, you determine that the accelerometer is either in the person's pocket or it is very dark. Then, you consider the time of day. If it's the middle of the night, you infer that the person is likely sleeping. This example illustrates how a decision tree works.

Example movement sensor

However, there are a couple of issues with decision trees. They are very susceptible to being overfitted to the data you feed into them. Additionally, they are not very good at incremental learning. If you feed one or two more bits of data into a decision tree, it can end up with a radically different structure and shape. Therefore, decision trees are not very effective for iterative learning.

Back to Top

Selecting the Model

How do you choose the model? Certain architectures suit different problems. For instance, You Only Look Once (YOLO) is very effective for object detection. A convolutional neural network is a suitable solution for this task. However, you can also use convolutional neural networks for other applications, such as vibration analysis.

MPLAB Machine Learning Development Suite helps you choose the model by providing the following templates:

  • Keyword spotting
  • Vibration classification
  • Activity recognition
  • Gesture recognition
  • Audio classification

Vibration Template Example

If you select the vibration template, you will see a list of the frequency and amplitude characteristics to be analyzed. This provides a good starting point for vibration analysis.

For frequency, you will find:

  • Dominant, MFCC (Mel-frequency cepstral coefficients)
  • MFE
  • Peak frequencies
  • Power spectrum

For amplitude, you will see Global Peak to Peak.

vibration template

Back to Top