Book Image

MATLAB for Machine Learning

By : Giuseppe Ciaburro
Book Image

MATLAB for Machine Learning

By: Giuseppe Ciaburro

Overview of this book

MATLAB is the language of choice for many researchers and mathematics experts for machine learning. This book will help you build a foundation in machine learning using MATLAB for beginners. You’ll start by getting your system ready with t he MATLAB environment for machine learning and you’ll see how to easily interact with the Matlab workspace. We’ll then move on to data cleansing, mining and analyzing various data types in machine learning and you’ll see how to display data values on a plot. Next, you’ll get to know about the different types of regression techniques and how to apply them to your data using the MATLAB functions. You’ll understand the basic concepts of neural networks and perform data fitting, pattern recognition, and clustering analysis. Finally, you’ll explore feature selection and extraction techniques for dimensionality reduction for performance improvement. At the end of the book, you will learn to put it all together into real-world cases covering major machine learning algorithms and be comfortable in performing machine learning with MATLAB.
Table of Contents (17 chapters)
Title Page
About the Author
About the Reviewers
Customer Feedback
Improving the Performance of the Machine Learning Model - Dimensionality Reduction


For humans, learning from mistakes is a fundamental rule. Why should it not be the same for machines? Machine learning algorithms will do just that: learn from experience. Machine learning gives computers the ability to learn without being explicitly programmed. It starts with real examples, extracts the models (that is, the rules that govern their operation), and uses them to make predictions about new examples.

MATLAB provides essential tools for understanding the amazing world of machine learning. Solving machine learning problems becomes extremely easy with the use of the tools available in the MATLAB environment. This is because MATLAB is a strong environment for interactive exploration.

For each topic, after a concise theoretical basis, you will be involved in real-life solutions. By the end of the book, you will be able to apply machine learning techniques and leverage the full capabilities of the MATLAB platform through real-world examples.

What this book covers

Chapter 1, Getting Started with MATLAB Machine Learning, introduces the basic concepts of machine learning, and then we take a tour of the different types of algorithms. In addition, some introduction, background information, and basic knowledge of the MATLAB environment will be covered. Finally, we explore the essential tools that MATLAB provides for understanding the amazing world of machine learning.

Chapter 2, Importing and Organizing Data in MATLAB, teaches us how to import and organize our data in MATLAB. Then we analyze the different formats available for the data collected and see how to move data in and out of MATLAB. Finally, we learn how to organize the data in the correct format for the next phase of data analysis.

Chapter 3, From Data to Knowledge Discovery, is where we begin to analyze data to extract useful information. We start from an analysis of the basic types of variable and the degree of cleaning the data. We analyze the techniques available for the preparation of the most suitable data for analysis and modeling. Then we go to data visualization, which plays a key role in understanding the data.

Chapter 4, Finding Relationships between Variables - Regression Techniques, shows how to perform accurate regression analysis in the MATLAB environment. We explore the amazing MATLAB interface for regression analysis, including fitting, prediction, and plotting.

Chapter 5, Pattern Recognition through Classification Algorithms, covers classification and much more. You’ll learn how to classify an object using nearest neighbors. You'll understand how to use the principles of probability for classification. We'll also cover classification techniques using decision trees and rules.

Chapter 6, Identifying Groups of Data Using Clustering Methods, shows you how to divide the data into clusters, or groupings of similar items. You'll learn how to find groups of data with k-means and k-medoids. We'll also cover grouping techniques using hierarchical clustering.

Chapter 7, Simulation of Human Thinking - Artificial Neural Networks, teaches you how to use a neural network to fit data, classify patterns, and do clustering. You’ll learn preprocessing, postprocessing, and network visualization for improving training efficiency and assessing network performance.

Chapter 8, Improves the Performance of the Machine Learning Model - Dimensionality Reduction, shows you how to select a feature that best represents the set of data. You will learn feature extraction techniques for dimensionality reduction when the transformation of variables is possible.

Chapter 9, Machine Learning in Practice, starts with a real-world fitting problem. Then you’ll learn how to use a neural network to classify patterns. Finally, we perform clustering analysis. In this way, we’ll analyze supervised and unsupervised learning algorithms.

What you need for this book

In this book, machine learning algorithms are implemented in the MATLAB environment. So, to reproduce the many examples in this book, you need a new version of MATLAB (R2017a recommended) and the following toolboxes: statistics and machine learning toolbox, neural network toolbox, and fuzzy logic toolbox.

Who this book is for

This book is for data analysts, data scientists, students, or anyone who is looking to get started with machine learning and wants to build efficient data-processing and predicting applications. A mathematical and statistical background will really help in following this book well.


In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "MATLAB performs the math task and assigns the result to the ans variable."

A block of code is set as follows:

PC1 = 0.8852* Area + 0.3958   * Perimeter + 0.0043 * Compactness +
  0.1286 * LengthK + 0.1110 * WidthK - 0.1195 * AsymCoef + 0.1290 *

Any command-line input or output is written as follows:

ans =

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "A reference page in the Help browser."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your email address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title. To view the previously submitted errata, go to and enter the name of the book in the search field. The required information will appear under the Errata section.


Piracy of copyrighted material on the internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the internet, please provide us with the location address or website name immediately so that we can pursue a remedy. Please contact us at [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.


If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.