Machine Learning Methods: Clustering

Interactive courseware module that addresses the theory behind multiple clustering methods and how to apply them to real data sets.
Updated 14 Sep 2023

Machine Learning Methods: Clustering

View on File Exchange or Open in MATLAB Online

MATLAB Versions Tested

Curriculum Module

Created with R2023b. Compatible with R2023b and later releases.


This curriculum module contains interactive MATLAB® live scripts that apply fundamental concepts and basic terminology related to clustering.


You can use these live scripts as demonstrations in lectures, class activities, or interactive assignments outside class. This module covers distance-based, density based, and probabilistic algorithms including k-means, DBSCAN, and GMMs. It also includes examples of applying each algorithm to a data set containing beak measurements for different species of penguins.

The instructions inside the live scripts will guide you through the exercises and activities. Get started with each live script by running it one section at a time. To stop running the script or a section midway (for example, when an animation is in progress), use the image_0.png Stop button in the RUN section of the Live Editor tab in the MATLAB Toolstrip.

Contact Us

Contact the MathWorks teaching resources team if you have a question or would like to provide any feedback.


This module assumes knowledge of basic statistics and probability, including Gaussian distributions and Bayes' theorem. If you would like to refresh your knowledge on these topics, more courseware on Gaussian distributions can be found here, and more courseware on Bayes' theorem can be found here. There is minimal MATLAB knowledge required for these scripts, but you can use MATLAB Onramp as a resource to acquire familiarity with live scripts and MATLAB syntax.

Getting Started

Accessing the Module

On MATLAB Online:

Use the image_1.png link to download the module. You will be prompted to log in or create a MathWorks account. The project will be loaded, and you will see an app with several navigation options to get you started.

On Desktop:

Download or clone this repository. Open MATLAB, navigate to the folder containing these scripts and double-click on MLMethodsClustering.prj. It will add the appropriate files to your MATLAB path and open an app that asks you where you would like to start.

Ensure you have all the required products (listed below) installed. If you need to include a product, add it using the Add-On Explorer. To install an add-on, go to the Home tab and select image_2.png Add-Ons > Get Add-Ons.


MATLAB® is used throughout. Tools from the Statistics and Machine Learning Toolbox™ are used frequently as well.


image_3.png In this script, students will... - Learn what clustering is and what types of problems it can be applied to - Explore a step-by-step example of using k-means to cluster random data - Apply k-means to a real world data set, optimizing parameters along the way Academic disciplines - Machine Learning - Artificial Intelligence
image_4.png In this script, students will... - Learn about two more clustering methods: DBSCAN and GMMs - Work through step-by-step examples of applying each algorithm to an example data set - Cluster the same real world data set using each method, considering their pros and cons - Learn about a variety of methods to evaluate clustering results Academic disciplines - Machine Learning - Artificial Intelligence - Statistics

Related Courseware Modules

image_5.png Available on: image_6.png image_7.png GitHub

image_8.png Available on: image_9.png image_10.png GitHub

Or feel free to explore our other modular courseware content.

Educator Resources

Copyright 2023 The MathWorks™, Inc

Cite As

Ryan Weinstein (2024). Machine Learning Methods: Clustering (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2023b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on AI, Data Science, and Statistics in Help Center and MATLAB Answers
More Files in the  Distance Learning Community

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!




Version Published Release Notes

See release notes for this release on GitHub:


To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.