# scikit-learn: Theory of K-Means Clustering

In this course, we will explore a class of unsupervised machine learning models: clustering algorithms. Clustering algorithms seek to automatically learn, from the properties of the data, an optimal partitioning of the points into a discrete labeling of groups.

k-Means clustering is presented first as an algorithm and then as an approach to minimizing a particular objective function. One challenge with clustering algorithms is that it’s not obvious how to measure success.

Duration (mins)

Learners

#### NA / 5

Rating

We will cover the following tasks in 52 minutes:

### Introduction

In this chapter, let’s go over the course objectives and get a feel of the course material we will encounter later. We get to look at a few motivating examples of k-means clustering, and then build our own implementation.

### Setting

In this chapter, we start out by cultivating our intuition for the settings most appropriate for k-Means clustering. Next, we generate a two-dimensional dataset containing four distinct blobs. To emphasize that this is an unsupervised algorithm, we will leave the labels out of the visualization.

### k-Means: By Example

Now that we have intuitive understanding of k-means, we will implement a clustering on our dataset from Chapter 2 using sklearn.cluster.KMeans. Lastly, we use our intuition to build a mathematically sound construction of k-means objective function.

### Plotting the Results

Let’s visualize the results by plotting the data colored according to labels. We will also plot the cluster centers as determined by the k-means estimator:

### Algorithm: Expectation-Maximization

In this chapter, we break down the work-horse behind k-means: the EM algorithm. Once we understand the fundamentals thoroughly, we implement the EM algorithm from scratch and visualize our results!

### Failure Cases: Suboptimal Local Minimum

Here we look at situations where k-means fails in practice, and try to piece together why this is so.

First, although the E–M procedure is guaranteed to improve the result in each step, there is no assurance that it will lead to the global best solution. For example, if we use a different random seed in our simple procedure, the particular starting guesses lead to poor results.

### Failure Cases: Number of Clusters

Another common challenge with k-means is that you must tell it how many clusters you expect: it cannot learn the number of clusters from the data. For example, if we ask the algorithm to identify six clusters, it will happily proceed and find the best six clusters.

## Watch Preview

Preview the instructions that you will follow along in a hands-on session in your browser.

## About the Host (Snehan Kekre)

Snehan Kekre is a Machine Learning and Data Science Instructor at Coursera. He studied Computer Science and Artificial Intelligence at Minerva Schools at KGI, based in San Francisco. His interests include AI safety, EdTech, and instructional design. He recognizes that building a deep, technical understanding of machine learning and AI among students and engineers is necessary in order to grow the AI safety community. This passion drives him to design hands-on, project-based machine learning courses on Rhyme.

##### How is this different from YouTube, PluralSight, Udemy, etc.?
In Rhyme, all projects are completely hands-on. You don't just passively watch someone else. You use the software directly while following the host's (Snehan Kekre) instructions. Using the software is the only way to achieve mastery. With the "Live Guide" option, you can ask for help and get immediate response.
##### Can I buy Rhyme sessions for my company or learning institution?
Absolutely. We offer Rhyme for workgroups as well larger departments and companies. Universities, academies, and bootcamps can also buy Rhyme for their settings. You can select projects and trainings that are mission critical for you and, as well, author your own that reflect your own needs and tech environments. Please email us at help@rhyme.com
##### What kind of accessibility options does Rhyme provide?
Rhyme strives to ensure that visual instructions are helpful for reading impairments. The Rhyme interface has features like resolution and zoom that will be helpful for visual impairments. And, we are currently developing a close-caption functionality to help with hearing impairments. Most of the accessibility options of the cloud desktop's operating system or the specific application can also be used in Rhyme. If you have questions related to accessibility, please email us at accessibility@rhyme.com
##### Why don't you just use containers or virtual browsers?
We started with windows and linux cloud desktops because they have the most flexibility in teaching any software (desktop or web). However, web applications like Salesforce can run directly through a virtual browser. And, others like Jupyter and RStudio can run on containers and be accessed by virtual browsers. We are currently working on such features where such web applications won't need to run through cloud desktops. But, the rest of the Rhyme learning, authoring, and monitoring interfaces will remain the same.
##### I have a different question
Please email us at help@rhyme.com and we'll respond to you within one business day.

## More Projects by Snehan Kekre

45 minutes
###### scikit-learn: Logistic Regression for Sentiment Analysis
1 hour and 26 minutes
###### Project: Predictive Modelling with Azure Machine Learning Studio
1 hour and 6 minutes
###### Project: Named Entity Recognition using LSTMs with Keras
1 hour and 10 minutes
###### Project: Support Vector Machines with scikit-learn
1 hour and 40 minutes
57 minutes
###### Project: Image Super Resolution using Autoencoders in Keras
1 hour and 4 minutes
58 minutes
52 minutes
###### Project: Predict Employee Turnover with scikit-learn
1 hour and 4 minutes
###### Logistic Regression with NumPy and Python
1 hour and 3 minutes
###### Project: Real-Time Object Detection with YOLOv3
1 hour and 5 minutes
47 minutes
53 minutes
55 minutes
53 minutes
52 minutes
###### Project: Generate Synthetic Images with DCGANs in Keras
1 hour and 7 minutes
47 minutes
47 minutes
###### Create Interactive Dashboards with Streamlit and Python
1 hour and 33 minutes
###### Project: Facial Expression Recognition in Keras
1 hour and 24 minutes
58 minutes
43 minutes
###### Build a Data Science Web App with Streamlit and Python
1 hour and 21 minutes
###### Project: Anomaly Detection in Time Series Data with Keras
1 hour and 3 minutes
41 minutes
###### Project: Perform Feature Analysis with Yellowbrick
1 hour and 15 minutes
48 minutes
52 minutes
52 minutes
52 minutes
###### Build a Machine Learning Web App with Streamlit and Python
1 hour and 21 minutes
59 minutes
58 minutes
###### Project: Regression Analysis with Yellowbrick
1 hour and 10 minutes
43 minutes
57 minutes
42 minutes