Academic Int. Report
Academic Int. Report
ON
MATLAB WITH MACHINE LEARNING
Submitted by-
Priya Saikia(210810017026)
Pranamika Bora(220810017030)
Issa Gowala(220810017017)
1
CERTIFICATE OF APPROVAL
The undersigned certify that Priya Saikia, Pranamika Bora and Isha Gowala of 5th semester
from the Department of Power Electronics And Instrumentation Engineering have done the
internship under my guidance during the period from 18-06-2024 to 17-08-23.
2
DECLARATION
I hereby declare that the internship report entitled “Matlab With Machine Learning” submitted
for the B.TECH degree in Department of Power Electronics And Instrumentation is my original
work and has not been formed the basis for the award of any other degree, diploma, fellowship
or any other similar titles.
Signature of student
Place:
Date:
3
ACKNOWLEDGEMENT
It gives us immense pleasure to express our deepest sense of gratitude and sincere thanks to
our highly respected and esteemed guide Dr. Nilakshi Devi. Her useful suggestions are
sincerely acknowledged.
We would also like to express our sincere thanks to Mr. Angshuman Goswami(TPO) for giving
us this opportunity to undertake this internship and for his wholehearted support.
We are also grate to our respected HOD and teachers for their constant support and guidance.
At the end we would like to express our sincere thanks to all our friends and other who helped
us directly or indirectly during this internship work.
4
ABSTRACT
This report explores the seamless integration of machine learning algorithms within MATLAB,
highlighting its capabilities, applications, and performance. MATLAB’s machine learning
toolbox provides a comprehensive platform for data preprocessing, feature selection, model
development, and evaluation. The report delves into the implementation of supervised and
unsupervised learning techniques, including neural networks, decision trees, and clustering.
Real-world case studies demonstrate the efficacy of MATLAB’s machine learning tools in
image classification, predictive analytics, and signal processing. The results showcase the
efficiency and accuracy of MATLAB’s machine learning algorithms, underscoring its potential
in various domains such as engineering, computer vision, and data science. This report serves
as a valuable resource for researchers, engineers, and students seeking to leverage MATLAB’s
machine learning capabilities.
5
TABLE OF CONTENTS
CONTENTS PAGE NO
1. Institute Description
2. Methodology
3. Introduction to Machine Learning
4. Getting Started with Matlab
5. Understanding the basics of Machine Learning
6. Matlab Toolboxes for Machine Learning
7. Data Prepocessing in MATLAB
8. Supervised Learning Algorithms
9. Unsupervised Learning Algorithms
10. Evaluating Machine Learning Models in Matlab
11. Deep Learning With Matlab
12. Advanced Topics in Machine Learning with MATLAB
13. Real-World Applications of Machine Learning in MATLAB
14.MATLAB for Model Deployment and Automation
15. Challenges and Future Directions
16. Conclusion
17. References
6
INSTITUTE DESCRIPTION
7
METHODOLOGY
We were taught from the rock bottom to a notably well state. This course
has also taught us the importance of Machine Learning with MATLAB in
an individuals life in implementing his ideas.
8
INTRODUCTION
Definition of Learning
9
o Example – Consider the following data regarding patients entering
a clinic . The data consists of the gender and age of the patients and
each patient is labeled as “healthy” or “sick”.
o M o 48 o sick
o M o 67 o sick
o F o 53 o healthy
o M o 49 o sick
o F o 32 o healthy
o M o 34 o healthy
o M o 21 o healthy
2. Unsupervised learning:
Unsupervised learning is a type of machine learning algorithm used to draw
inferences from datasets consisting of input data without labeled responses. In
unsupervised learning algorithms, classification or categorization is not included
in the observations. Example: Consider the following data regarding patients
entering a clinic. The data consists of the gender and age of the patients.
Gender Age
M 48
M 67
F 53
10
M 49
F 34
M 21
As a kind of learning, it resembles the methods humans use to figure out that certain
objects or events are from the same class, such as by observing the degree of
similarity between objects. Some recommendation systems that you find on the
web in the form of marketing automation are based on this type of learning.
3. Reinforcement Learning:
A learner is not told what actions to take as in most forms of machine learning
but instead must discover which actions yield the most reward by trying them.
For example — Consider teaching a dog a new trick: we cannot tell him what to
do, what not to do, but we can reward/punish it if it does the right/wrong thing.
When watching the video, notice how the program is initially clumsy and
unskilled but steadily improves with training until it becomes a champion.
4. Semisupervised Learning:
Where an incomplete training signal is given: a training set with some (often
many) of the target outputs missing. There is a special case of this principle
known as Transduction where the entire set of problem instances is known at
learning time, except that part of the targets are missing. Semi-supervised
learning is an approach to machine learning that combines small labeled data with
a large amount of unlabeled data during training. Semi-supervised learning falls
between unsupervised learning and supervised learning.
11
ff
12
FIG: Machine Learning Lifecycle
1. Installation of MATLAB
To begin using MATLAB, it is essential to install the software on your
computer. MATLAB is available as a paid version, but there are free trials and
academic licenses available.
14
2. MATLAB Interface Overview
Upon launching MATLAB, users are greeted with the main interface,
which consists of several key components:
The Command Window is the primary interface for typing and executing
commands. It allows users to interact directly with MATLAB, execute
one-line commands, and display results.
2.2 Workspace
The Workspace area displays all the variables that have been defined
during the current session. This allows users to view and manage
variables and their values.
The Current Folder window shows the files and directories in the current
working directory. It enables users to navigate and manage their
MATLAB files.
2.4 Editor
The Editor is used to create, edit, and run scripts and functions. It allows
users to write more complex programs and organize their work into
reusable code blocks.
15
a = 5 + 3; % Addition
b = 10 - 2; % Subtraction
c = 4 * 6; % Multiplication
d = 8 / 2; % Division
3.2 Variables
MATLAB allows users to define variables to store values for later use:
C = A + B; % Matrix addition
D = A * B; % Matrix multiplication
E = A .* B; % Element-wise multiplication
plot(x, y1, '-r', x, y2, '-b'); % Plot sine in red, cosine in blue
16
legend('sin(x)', 'cos(x)');
title('Sine and Cosine Functions');
xlabel('x');
ylabel('y');
grid on;
This code generates a plot of the sine and cosine functions with labeled
axes, a title, and a legend.
5.1 Scripts
To create a script:
5.2 Functions
Functions are similar to scripts but allow for input and output arguments.
They enable users to write reusable blocks of code.
17
6. MATLAB Documentation and Help System
18
Machine Learning involves several foundational concepts, each
contributing to the ability of a system to learn and generalize from
data.
1.1. Data
1.2. Model
19
To assess the performance of an ML model, the data is often split
into two sets:
Training Data: Used to train the model and adjust its parameters.
Common Algorithms:
20
Linear Regression: Used for predicting continuous values (e.g.,
predicting house prices).
Common Algorithms:
22
Statistics and Machine Learning Toolbox
The Statistics and Machine Learning Toolbox is perhaps the most
comprehensive toolbox for general-purpose machine learning tasks in
MATLAB. It provides a wide range of algorithms for supervised and
unsupervised learning, as well as tools for model evaluation and
assessment.
Key Features:
Supervised Learning: Functions for classification, regression, and
support vector machines (SVM). Models such as decision trees, k-
nearest neighbors (k-NN), and logistic regression are supported.
Unsupervised Learning: Clustering algorithms like k-means,
hierarchical clustering, and Gaussian mixture models (GMM) are
included.
Dimensionality Reduction: Tools like principal component analysis
(PCA) and t-distributed stochastic neighbor embedding (t-SNE) help
reduce the number of input features while preserving important
patterns.
Model Evaluation: Provides cross-validation, confusion matrices, and
performance metrics (accuracy, precision, recall, F1 score) for model
evaluation.
Example Use Case:
23
The Deep Learning Toolbox is designed for developing deep neural
networks (DNNs), including convolutional neural networks (CNNs),
recurrent neural networks (RNNs), and other advanced neural
architectures. This toolbox is ideal for image recognition, speech
processing, and time-series analysis.
Key Features:
Network Architectures: Tools for defining, training, and validating
deep neural networks, including CNNs, RNNs, and autoencoders.
Pretrained Models: A library of pretrained models for tasks like image
classification, object detection, and natural language processing, which
can be fine-tuned to specific datasets.
GPU Acceleration: The toolbox supports GPU-based training for
faster model development, particularly useful when working with large
datasets.
Key Features:
25
Q-Learning and Deep Q-Networks (DQN): Supports classic RL
algorithms like Q-learning as well as advanced techniques such as deep
Q-networks (DQN) for more complex tasks.
Simulations: Allows for integration with simulation environments
(e.g., Simulink, Gazebo) to train RL agents in a controlled environment.
Policy Optimization: Includes algorithms for policy optimization,
such as proximal policy optimization (PPO) and trust region policy
optimization (TRPO).
Example Use Case:
Autonomous Driving: Using reinforcement learning to train an
autonomous vehicle agent to navigate through traffic and avoid
obstacles.
27
Key Functions:
Normalization: The normalize() function scales features to a specific
range (typically [0, 1]).
normalized_data = normalize(data);
Standardization: To standardize features (zero mean and unit variance),
you can use zscore().
standardized_data = zscore(data);
Example Use Case:
Customer Data: If you have features like age (range 0-100) and
income (range 10,000-100,000), normalization ensures that both
features contribute equally when input into a machine learning model.
28
Survey Data: If you have survey responses with categories like “Yes”
or “No,” you can convert these to numeric values (e.g., 1 and 0) for use
in machine learning models.
2.4. Feature Extraction and Selection
Feature extraction involves creating new features from existing data to
improve the predictive power of a model. Feature selection, on the
other hand, involves choosing the most relevant features from a larger
set, reducing dimensionality and preventing overfitting.
Key Functions:
Principal Component Analysis (PCA): MATLAB’s pca() function
performs dimensionality reduction by projecting data onto a set of
orthogonal components that capture the maximum variance in the data.
[coeff, score, latent] = pca(data);
Correlation-Based Feature Selection: You can identify highly
correlated features using corr() to ensure that redundant features are
removed.
correlation_matrix = corr(data);
Example Use Case:
Medical Data: When working with datasets containing thousands of
features (such as genetic data), PCA can help reduce the dimensionality
and retain the most important information.
29
Supervised learning involves training a model on labeled data to predict
outcomes for unseen data. MATLAB provides a comprehensive set of
tools to implement a variety of supervised learning algorithms, ranging
from simple models like linear regression to more complex ones such
as neural networks and support vector machines (SVM). This report
explores key supervised learning algorithms in MATLAB and their
applications.
Common Supervised Learning Algorithms in MATLAB
1. Linear Regression
Linear regression is used for predicting continuous values based on
input features. In MATLAB, the fitlm() function fits a linear regression
model.
2. Logistic Regression
Logistic regression is used for binary classification. MATLAB uses the
mnrfit() function for this task.
3. Decision Trees
30
Decision trees partition data into subsets based on feature values. In
MATLAB, use fitctree() for classification and fitrtree() for regression.
2. Hierarchical Clustering
32
3. Gaussian Mixture Models (GMM)
33
5. t-Distributed Stochastic Neighbor Embedding (t-SNE)
34
Evaluating the performance of machine learning models is a
crucial step in ensuring that the model generalizes well to new,
unseen data. In MATLAB, several techniques and metrics are
available for assessing model performance, including accuracy,
precision, recall, F1-score, and cross-validation. This report
highlights key methods and functions in MATLAB for
evaluating machine learning models, particularly focusing on
classification and regression tasks.
Metrics derived:
The ROC curve plots the true positive rate (recall) against the
false positive rate (1-specificity). The area under the ROC curve
(AUC) is a performance measure, where higher values (close to
1) indicate better models.
1.3. Cross-Validation
36
Deep learning is a subset of machine learning focused on algorithms
inspired by the structure and function of the brain, primarily artificial
neural networks. MATLAB provides a robust environment for building,
training, and deploying deep learning models with its Deep Learning
Toolbox. This toolbox offers prebuilt functions and tools for designing
deep neural networks, including feedforward networks, convolutional
networks, and recurrent networks. In this report, we explore key deep
learning workflows in MATLAB.
MATLAB allows users to build deep learning models using layers such as
fully connected, convolutional, and LSTM (long short-term memory)
layers.
Key Functions:
layers = [
fullyConnectedLayer(10)
reluLayer
fullyConnectedLayer(1)
regressionLayer
];
37
involves adjusting the weights of the network to minimize the loss
function.
Here, XTrain and YTrain are the input data and labels, and options
defines the training parameters such as learning rate and epochs.
3. Transfer Learning
Transfer learning enables the use of pre-trained models for new tasks,
saving time and computational resources. MATLAB offers pretrained
networks such as AlexNet, VGG16, and ResNet, which can be fine-tuned
on a new dataset.
Key Functions:
net = alexnet;
layers = net.Layers;
layers(end-3:end) = []; % Remove last layers
newLayers = [
fullyConnectedLayer(10)
softmaxLayer
classificationLayer
];
layers = [layers; newLayers];
model = trainNetwork(XTrain, YTrain, layers, options);
38
CNNs are widely used for image classification, object detection, and
segmentation. MATLAB simplifies building CNNs with specialized
layers like convolutional, pooling, and batch normalization layers.
layers = [
imageInputLayer([28 28 1])
convolution2dLayer(3, 16)
reluLayer
maxPooling2dLayer(2, 'Stride', 2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer
];
layers = [
sequenceInputLayer(1)
lstmLayer(50)
fullyConnectedLayer(1)
regressionLayer
];
39
ADVANCED TOPICS IN MACHINE LEARNING WITH
MATLAB
Key Techniques:
Tools:
2. Transfer Learning
40
Transfer learning is an advanced technique where a model pre-
trained on a large dataset is adapted for a new, often smaller,
dataset. This reduces training time and computational resources,
particularly when data is scarce.
Key Steps:
2. Modify the Model: Replace the final layers to fit your new
task.
41
1. Healthcare and Medical Diagnosis
Medical Image Analysis: MATLAB is widely used to analyze medical
images (such as MRI, CT scans, X-rays) for disease detection,
segmentation, and classification. ML algorithms help in tasks like
identifying tumors, detecting fractures, or classifying tissue types.
2. Autonomous Vehicles
42
Algorithmic Trading: ML algorithms in MATLAB can be trained on
historical market data to predict stock prices, forecast trends, and
design trading strategies that maximize returns.
43
Matlab is a powerful platform commonly used for model
development, testing, and deployment in various industries, including
engineering, finance, and healthcare. When it comes to model
deployment and applications, Matlab provides several tools and
features that help take models from research and simulation to real-
world use. Here’s a breakdown of how Matlab supports model
deployment and its applications:
44
3. Simulink and Simulink Coder
45
Challenges:
5. Community Support:
46
While MATLAB has a dedicated user base, its community-driven
resources (forums, tutorials, etc.) are not as vast as those in the Python
ecosystem, limiting learning and support opportunities.
Future Directions:
47
MATLAB will likely expand its cloud offerings, enabling large-scale
training and distributed computing. Integration with platforms like
AWS and Azure could further streamline deployment and
collaboration.
48
CONCLUSION
This report has explored the integration of Machine Learning techniques with
MATLAB, highlighting its powerful capabilities for data analysis, model
building, and deployment. MATLAB provides a comprehensive suite of tools
and functions that make it an ideal environment for implementing machine
learning algorithms, offering flexibility for both beginners and advanced
practitioners. The ease of use of MATLAB's interface, coupled with its
extensive documentation and built-in toolboxes, enables users to efficiently
develop and fine-tune models. Additionally, the report has demonstrated the key
applications of machine learning in various fields, such as pattern recognition,
regression, and classification, with real-world examples to illustrate the
practical value of these methods. Ultimately, MATLAB serves as a robust
platform for accelerating machine learning workflows, providing both
accessibility and advanced functionality, which makes it a valuable tool for
researchers, engineers, and data scientists alike.
REFERENCES
49
1.www.mathworks.com
2.www.researchgate.net
3.MATLAB for Beginners,Md. Irfan Ali,3rd edition
4.MATLAB Programming for Engineers,Stephen J. Chapman,6th edition
5.MACHINE LEARNING,S.Sridar,4th edition
50