You are on page 1of 16

May 2023

THE BASICS OF
MACHINE LEARNING
Table of Contents

04 CHAPTER - 1 Introduction

05 CHAPTER - 2 Types of Machine Learning (ML)

07 CHAPTER - 3 Neural Networks

12 CHAPTER - 4 Deep Learning

12 CHAPTER - 5 Tensorflow

14 CHAPTER - 6 Preparing the Data

15 CHAPTER - 7 ML Projects for Beginners

2 https://community.element14.com/learn/publications/ebooks/
The Basics of Machine Learning

element14 is a Community of over 800,000 makers, professional engineers, electronics enthusiasts, and
everyone in between. Since our beginnings in 2009, we have provided a place to discuss electronics,
get help with your designs and projects, show off your skills by building a new prototype, and much
more. We also offer online learning courses such as our Essentials series, video tutorials from element14
Presents, and electronics competitions with our Design Challenges.

As artificial intelligence technology improves, it will have a measurable impact on virtually every
industry. One of the main techniques in AI is machine learning, where systems learn and improve from
experience, similar to humans, without being explicitly programmed. In this eBook, we’ll discuss how
machine learning works, learn about the software driving it, and go over various applications that use it.

element14 Community Team

https://community.element14.com/learn/publications/ebooks/ 3
CHAPTER - 1 Introduction

Machine learning (ML) is a powerful tool that enables When Do We Need Machine Learning?
computers to learn from data without explicit
programming. It is an important part of modern ML is necessary when two aspects of a given problem
artificial intelligence (AI) technologies, such as require using programs that learn and improve based
speech and image recognition, natural language on their “experience.” These two aspects are the
processing (NLP), and predictive analytics. With problem’s complexity and adaptivity.
the increasing availability of computing resources
Complexity
enabling the analysis of vast amounts of data,
machine learning can revolutionize the way we • Tasks Performed by Animals/Humans:
approach complex problems and has the potential Several tasks are too complex to program
to shape society’s future. This eBook covers the traditionally. Humans perform many regular
fundamentals of machine learning, including neural tasks, such as driving, speech recognition,
networks, TensorFlow, deep learning, machine and image comprehension, which require
learning workflows, and data preparation. analysis of many different types of information.
These tasks require complex computations,
History
which can change depending on the data
The history of ML dates back to the early 1900s, received, making traditional programming
when mathematicians and scientists first explored ineffective. However, ML programs that learn
mathematical models to analyze data. The field began from experience can achieve satisfactory
taking shape in the 1950s and 1960s as researchers results once exposed to a sufficient amount of
developed groundbreaking techniques for analyzing training examples.
patterns and data. Machine learning experienced
• Tasks beyond Human Capabilities: ML
impressive growth through the 1970s and 1980s,
techniques are valuable for analyzing data sets
with the development of new algorithms and models
that are too large and complex for humans
for interpreting and analyzing data. Artificial neural
to work with. In the modern world, virtually
networks were also introduced during this time,
every industry produces large data sets that
drawing inspiration from the structure and function
can be analyzed in search of information
of the human brain.
that can streamline processes. As more data
As computing power advanced during the 1990s and becomes digitally available, it is increasingly
new algorithms capable of handling large data sets apparent that valuable information is hidden
emerged, ML began to be applied in various fields, within these archives. By detecting meaningful
such as finance, healthcare, and manufacturing. patterns and trends in these data sets, ML
These advancements paved the way for the current algorithms can unlock new insights. This
applications of ML, which encompass a wide promising field combines learning programs
range of applications including self-driving cars, with the vast memory capacity and the ever-
personalized advertising, predictive maintenance, increasing processing speed of computers,
and fraud detection. Although ML has demonstrated opening up new uses for data analysis.
remarkable effectiveness in solving complex
Adaptivity
problems, it requires large amounts of data and
computational power to train and refine models, Programmed tools can be inflexible and unable
making it more challenging to implement than to adapt to changes. ML tools offer a solution to
traditional programming approaches. this problem and are designed to adapt to input
4 https://community.element14.com/learn/publications/ebooks/
data. These adaptive programs have successfully decoded handwritten text, detected spam emails, and
recognized speech patterns. With their ability to adjust to changes, ML tools can provide more flexible and
effective solutions to various problems.

CHAPTER - 2 Types of Machine Learning (ML)

ML includes hundreds of statistical-based algorithms, making it challenging to choose the appropriate


algorithm or combination of algorithms for those working in the field. Before diving into specific
algorithms, it is important to understand the three main categories of ML: supervised, unsupervised, and
reinforcement. There are also subfields of ML, including semi-supervised, active, and transfer learning.

Supervised Learning: Supervised learning is the first branch of ML, and focuses on finding patterns in
labeled datasets by establishing a connection between variables and known outcomes. The algorithm
is trained using sample data with various features (represented as “X”) and their corresponding output
values (represented as “Y”). By recognizing patterns in the data, the algorithm creates a model that can
predict outcomes for new data. For instance, a supervised algorithm can predict the market rate for a
used car by analyzing the relationship between car attributes (year, brand, mileage, etc.) and the selling
price of comparable vehicles based on historical data.

Figure 1: Car value prediction model (Image source: Machine Learning for Absolute Beginners)

Supervised learning involves creating a model by analyzing labeled data to identify patterns and rules.
This model can then make predictions with new data. Once the model passes training and testing, it can
be applied in the real world. Examples of supervised learning algorithms include regression analysis,
decision trees, k-nearest neighbors, neural networks, and support vector machines.

Unsupervised Learning: Conversely, unsupervised learning involves discovering hidden patterns and
relationships in data without pre-existing labels. Algorithms are used to group data points with similar
features and label them. The K-means clustering algorithm is an example of unsupervised learning;
it clusters data points based on their similarity in features. Unsupervised learning is useful in data
exploration, dimensionality reduction, and anomaly detection. Other popular unsupervised learning

https://community.element14.com/learn/publications/ebooks/ 5
algorithms include principal component analysis, hierarchical clustering, and association rule mining.
Figure 2 illustrates the concept behind K-means clustering.

Figure 2: Example of K-means clustering (Image source: quasarcommunity.org)

When examining the purchasing behavior of small and medium-sized enterprises (SMEs), and large
enterprise customers, two distinct clusters often emerge due to their differing buying habits. SMEs
require basic cloud hosting resources and a Content Delivery Network (CDN), while larger enterprises may
require more complex cloud solutions. To identify patterns and trends in the data, unsupervised learning
techniques such as K-means clustering are commonly used to group similar data points together based
on their features.

Unsupervised learning is particularly powerful in fraud detection, as the most dangerous attacks are often
not yet classified.

Reinforcement Learning: Reinforcement learning is an advanced algorithmic category in machine


learning that continuously improves its model by leveraging feedback from previous iterations. This is
analogous to a video game, where the player learns the value of different actions under varying conditions
and becomes more familiar with the environment, leading to better performance based on experience.

Reinforcement learning involves training the model through continuous learning, where the model is
graded based on measurable performance criteria, and positive scores are given for desirable outcomes.
One specific algorithmic example is Q-learning, where the environment is represented by a set of states
denoted as “S”, actions as “A”, and starting value as “Q”, which has an initial value of 0.

As the machine explores the game, Q decreases when negative events occur after a given state/action
and increases when positive events occur. The machine learns which actions generate or maintain the
highest Q level for each given state, initially through random movements under different conditions. The
machine records its results and how they impact its Q, storing those values to optimize its future actions.

6 https://community.element14.com/learn/publications/ebooks/
CHAPTER - 3 Neural Networks

Neural networks are computer models that imitate the structure and function of the human brain. They
recognize patterns and relationships in data, making them useful for ML and artificial intelligence.

Figure 3: Human brain neuron (Image source: researchgate.net)

Artificial neural networks consist of interconnected nodes or neurons, like the neurons in the human brain. These
nodes are arranged in layers, with the first layer receiving raw data and each subsequent layer processing the
data and forwarding it to the next layer. The edges, or connections, between nodes have numeric weights that
are adjusted based on experience. The activation function determines whether a neuron is activated based on
the sum of connected edges meeting a set threshold.

Figure 4: The nodes, edges/weights, and sum/activation function of a basic neural network

https://community.element14.com/learn/publications/ebooks/ 7
There are many different types of neural networks, each with its architecture and purpose. Some of the most
commonly used neural network models for ML include:

Feedforward Neural Network: Feedforward neural networks, or multi-layer neural networks, are artificial neural
networks that only allow information to flow in one direction, from input nodes through hidden layers, finally
exiting through output nodes. This is because no loops or links in the network can send information back from
the output node to the input node.

A single-layer perceptron is a simplified version of a feedforward neural network; it consists of input nodes
multiplied by weights as they enter the layer. The weighted inputs are summed, and if the sum exceeds a
threshold (usually set at zero), the output value is 1. If the sum falls below the threshold, the output value is -1.
This type of network is often used for classification tasks and can incorporate ML techniques through the delta
rule, which is a formula for adjusting weights based on the difference in desired and actual output.

Figure 5: Simple feedforward neural network

The training process for a feedforward neural network is backpropagated through the network, layer
involves the following steps: by layer, to compute the gradients of the loss
function with respect to each weight and bias.
1. Initialization: The weights and biases of the These gradients are then used to update the
neural network are randomly initialized before weights and biases of the network.
training begins.
5. Weight Updates: The weights and biases of
2. Forward Propagation: In this step, the input the network are updated using an optimization
data is fed forward through the neural network, algorithm such as stochastic gradient descent
layer-by-layer, until the output is produced. Each (SGD). The update rule involves multiplying
neuron applies an activation function to the the gradient of the loss function with respect
weighted sum of its inputs, producing an output to each weight and bias by a learning rate and
that is passed on to the next layer. subtracting the result from the current value of
the weight or bias.
3. Calculation of Loss: The difference between the
predicted and the actual output is calculated, and 6. Repeat: Steps 2-5 are repeated for a fixed
the loss function is computed. The choice of loss number of epochs or until the training loss
function depends on the specific problem being reaches a desired level of accuracy. After training,
solved and can vary from Mean Squared Error the network can be used with new data.
(MSE) to Cross-Entropy Loss.
The goal of the process is to minimize the loss function
4. Backpropagation: This is the key step of on the training data, while avoiding overfitting, which
training a neural network. In this step, the error
8 https://community.element14.com/learn/publications/ebooks/
occurs when the network becomes too specialized to the training data and does not generalize well to new data.
Various techniques, such as regularization and early stopping, can be used to prevent overfitting and improve the
generalization ability of the network.

Convolutional Neural Networks: A convolutional neural network (CNN) is a type of neural network that operates
on a grid-like structure and extracts important features from the data through multiple layers. The key benefit of
using CNNs is that they require minimal image preprocessing, making them highly efficient.

Figure 6: Convolutional neural network (Image source: researchgate.net)

CNNs are a type of neural network that mimics the structure of the brain and consists of layers of artificial
neurons called nodes. These nodes perform mathematical operations on input data and generate activation
maps highlighting important features. In the example of an image, the activation maps would highlight features
such as colors and edges. As the network processes the data through successive layers, it becomes more adept
at identifying complex patterns and features.

To improve efficiency, max pooling is used to select only the most relevant information from each activation map.
In max pooling, a fixed-size rectangular window (called the pooling window or filter) slides over the feature map
and extracts the maximum value within that window. The output of the pooling operation is a downsampled
feature map that contains the maximum values of non-overlapping windows of the original feature map. Finally,
the classification layer predicts the output value based on the input data and the activation maps.

Training a CNN is similar to training other machine learning algorithms. The model is trained using separate
data, and the weights are tuned based on the accuracy of predicted values. It is essential to avoid overfitting the
model to the training data.

Recurrent Neural Network: Recurrent neural networks (RNNs) are built on the concept of using the output of a
layer to predict the next output. To transform a Feedforward Neural Network into a Recurrent Neural Network, the
nodes from various layers are merged into a single recurrent layer.

https://community.element14.com/learn/publications/ebooks/ 9
Figure 7: Simple Recurrent Neural Network (RNN) (Image source: imerit.net)

The network has parameters A, B, and C to improve the model’s output. The input layer is represented as “x”,
the hidden layer as “h”, and the output layer as “y”. At any time “t”, the input is made up of the current input at
x(t) and the previous input at x(t-1). The output is then fed back into the network to improve the model’s output.

Figure 8: Fully Connected Recurrent Neural Network

Generative Adversarial Network : Generative adversarial networks (GANs) are an innovative type of
deep network that consist of two competing neural networks - the generator and its adversary (called the
discriminator). The generator produces samples from a given distribution (such as realistic images of birds).
In contrast, the discriminator distinguishes between the generated and actual samples (such as a photo of a
specific bird).

10 https://community.element14.com/learn/publications/ebooks/
What sets GANs apart is their “adversarial” training approach, which generates high-quality image samples that
surpass those produced by other methods. GANs have been shown to create incredibly realistic images. They
are expected to be essential in the next generation of computer graphics tools. Applications such as Midjourney
are already approaching photorealism, highlighting the tremendous potential of this technology.

Figure 9: Generative Adversarial Network (GAN) (Image source: Test Yourself to Learn About Artificial Intelligence)

Advantages of using Neural Networks • Neural networks can perform multiple


computations simultaneously, which makes them
Neural networks have become a popular tool in efficient at processing large amounts of data.
machine learning (ML) and artificial intelligence They can also handle noisy and incomplete data
(AI). They are able to learn from data in a way that by discovering and making use of the patterns
traditional algorithms cannot. There are several and relationships within the data, making them
reasons why neural networks are advantageous over more robust than traditional algorithms.
other methods.
• Some neural network architectures can learn
• Neural networks effectively model nonlinear patterns in data without explicit labels. This is
relationships, which is important for many real- particularly useful when the data is unstructured
world problems. This efficiency enables them to or labeling is expensive or time-consuming.
solve complex problems more efficiently than
other methods. To learn about neural networks and build a neural
network from scratch, check out the eBook Get
• Neural networks can adapt and improve their Ready for AI: Tools to Help You Get Started.
performance over time through training. As the
network is exposed to large amounts of data,
it adjusts its parameters to better fit the data,
leading to improved performance.

https://community.element14.com/learn/publications/ebooks/ 11
CHAPTER - 4 Deep Learning

Neural networks are at the core of deep learning and algorithms are used to develop models in domains like
are made up of interconnected nodes called neurons. computer vision, healthcare, finance, and gaming.
Neurons can be trained to recognize patterns in data
and make predictions or classifications. Deep learning One application of deep learning is detecting objects,
is a type of machine learning that uses neural networks recognizing images, and identifying faces via computer
to tackle complex problems, such as speech, image vision. In NLP, deep learning is used for sentiment
recognition and natural language processing (NLP). analysis, speech recognition, and language translation.
Deep learning algorithms can learn from large amounts In health care, deep learning is used to diagnose
of data, in order to identify patterns and features without diseases, monitor patients, and discover new drugs.
explicit programming. In finance, deep learning algorithms are used for fraud
detection, risk assessment, and investment prediction.
As demand for intelligent systems that can learn
from complex data grows, deep learning is becoming To learn more about computer vision and AI, check out
more important. Neural networks and deep learning Essentials of Artifical Intelligence: Face Applications.

CHAPTER - 5 Tensorflow

TensorFlow is a powerful open-source machine learning The framework was initially designed for deep learning
(ML) framework created by the Google Brain team and is based on a data flow graph architecture. In
in 2015. It provides a range of tools and libraries for this architecture, nodes represent mathematical
building ML models, including support for different operations, while edges represent the data or tensors
types of neural networks and helpful tools for data that flow between them. This design enables distributed
preprocessing and model evaluation. One of the critical computing, efficiently training large-scale deep learning
benefits of TensorFlow is that it offers both high and models across multiple CPUs or GPUs.
low-level APIs, which allow developers to build models
at different levels of complexity.

Figure 10: Tensorflow API (Image source: tensorflow.org)

12 https://community.element14.com/learn/publications/ebooks/
Developers can build and run various types of neural Tensors are used to represent input data, model
networks using TensorFlow, including convolutional parameters, and output predictions. They can have
neural networks (CNNs) and recurrent neural networks different ranks, which correspond to the number of
(RNNs), commonly used in deep learning applications. dimensions, and different shapes, which correspond to
Its flexibility and efficiency make it a popular choice for the size of each dimension.
various ML tasks, such as computer vision and NLP.
For example, a 1D tensor can represent a sequence of
TensorFlow uses a tensor data structure to represent values, such as a time series or a sentence, and can be
all data. A tensor is a multi-dimensional array or data represented as a vector. A 2D tensor can represent an
structure that is used to represent data with multiple image or a matrix, and can be represented as a matrix.
dimensions in machine learning and other mathematical A 3D tensor can represent a stack of images or a volume
operations. Essentially, a tensor is a generalization of a of data, and can be represented as a cube.
matrix to higher dimensions.

Table 1: Tensor

ML Workflow with Tensorflow Keras

Figure 11 shows how ML works with Tensorflow Keras, a high-level API for building and training deep learning
models using the TensorFlow framework. Keras was originally developed as a standalone deep learning library,
but it was integrated into TensorFlow and has become its default API for building neural networks.

Figure 11: ML Workflow with Tensorflow Keras

https://community.element14.com/learn/publications/ebooks/ 13
CHAPTER - 6 Preparing the Data

We need to prepare the data that we will use for training. Keras offers a variety of built-in datasets that we
can use, such as Boston Housing (for regression), CIFAR100 (for classification of 100 image labels), MNIST
(for classification of 10 digits), Fashion-MNIST (for classification of 10 fashion categories), and Reuters News
(for multiclass text classification), among others. These datasets can be easily imported and used for training
purposes. An example in Python is shown below.

from tensorflow.keras.datasets import boston_housing

(x_train, y_train), (x_test, y_test) = boston_housing.load_data()

Before training a deep neural network model with Keras, it is essential to prepare the input datasets by cleaning,
balancing, transforming, scaling, and splitting them.

Create a Tensorflow Keras Model

Layers are the fundamental building blocks of Keras models and the Sequential model is a linear stack of layers.
A Sequential model can be created with a list of layer instances to the constructor or added with the .add()
method. The input shape/dimension of the first layer needs to be set.

from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense, Activation

model = Sequential([ Dense(64, activation=’relu’, input_dim=20), Dense(10, activation=’softmax’))]

Configure the Tensorflow Keras Model

Before the model is trained, we need to compile the Keras model. The compile method of a Keras model
configures the learning process before the model is trained. The following three arguments need to be set :

• Optimizer: Adam, AdaGrad, SGD, RMSprop, etc.

• Loss function: mean_squared_error, mean_absolute_error, mean_squared_logarithmic_error, categorical_


crossentropy, kullback_leibler_divergence, etc.

• A list of measurement metrics: accuracy, binary_accuracy, categorical_accuracy, etc.

Train and Evaluate the Tensorflow Keras Model

Keras is trained on NumPy arrays of input data and labels. The fit(), evaluate(), and summary() functions are
commonly used to train, evaluate, and summarize deep learning models.

• fit(): The fit() function is used to train a Keras model on a given dataset. This function takes in the training
data, validation data (optional), number of epochs, batch size, and other hyperparameters, and trains the
model on the data for the specified number of epochs. The fit() function also returns a history object that
contains the loss and accuracy values during training.

14 https://community.element14.com/learn/publications/ebooks/
• evaluate(): The evaluate() function is used to evaluate the performance of a trained Keras model on a given
dataset. This function takes in the test data and computes the loss and accuracy of the model on the test
data. The evaluate() function returns the loss and accuracy values of the model on the test data.

• summary(): The summary() function is used to print a summary of the Keras model, including the number
of layers, output shape of each layer, number of parameters in each layer, and total number of parameters
in the model. This function can be used to quickly inspect the architecture of a Keras model and to ensure
that the model has been defined correctly.

CHAPTER - 7 ML Projects for Beginners

Machine learning (ML) is a rapidly expanding field. As a 3. Backup Car Cam with Onboard Vision AI: A
beginner, it can be challenging to know where to start. Backup Car Cam with Onboard Vision AI is an
Fortunately, many beginner-friendly ML projects involve advanced system that offers drivers an enhanced
inexpensive hardware, from manufacturers such as level of safety and convenience when driving.
Avnet, BeagleBone, Arduino, Raspberry Pi, AMD, and This system includes a high-definition camera
more. In this chapter, we will discuss three projects that mounted on the rear of the vehicle, providing a
are perfect for beginners. clear and detailed view of the surroundings while
reversing. Additionally, the onboard Vision AI
1. Gesture Recognition with Arduino: This project technology offers real-time object detection and
involves building a gesture recognition system recognition, enabling the system to detect and
using Arduino and various other components. In alert drivers of any obstacles or hazards that may
the project, an ML model is trained to recognize be present. The project uses BeagleBone AI, a
different hand gestures, using a gesture sensor powerful embedded system that provides high-
connected to the Arduino. This project is an performance computing capabilities, making it
excellent way to learn about ML and how it can suitable for running sophisticated AI algorithms.
be used with hardware.
Additional Reading on Machine Learning
2. Smart Home Automation with Raspberry Pi:
Smart home automation is another field where • Detecting Multiple Objects with Artificial
ML can be applied significantly. This project uses Intelligence
a Raspberry Pi to control various smart home
devices using voice commands. An ML model is • Wake Word Detection and AI for Audio
trained to recognize different voice commands.
• Can You Make Agriculture Smarter with AI?
The commands are interpreted and actions are
sent to the connected smart home devices. • Artificial Intelligence: Inference for Machine
Learning

Check out more AI related articles on our AI web page.

https://community.element14.com/learn/publications/ebooks/ 15
300 S. Riverside Plaza, Suite 2200 Facebook.com/e14Community
Chicago, IL 60606 Twitter.com/e14Community
https://community.element14.com/

© 2023 by Newark Corporation, Chicago, IL 60606. All rights reserved. No portion of this publication, whether in whole or in part, can be reproduced without the express written consent of
Newark Corporation. Newark® is a registered trademark of Farnell Corp. All other registered and/or unregistered trademarks displayed in this publication constitute the intellectual property of
their respective holders. Printed in the U.S.A. WF-3306038

You might also like