Machine Learning in R: K Means Clustering

This is a great exercise to get your feet wet in Machine Learning. In this example we will be using the k means algorithm to group the Petal.Lengths and Petal. Widths of three Species of flower. We wil then see how we did both graphically and numerically. It’s fun.

Machine Learning in R: K Means Clustering

Duration (mins)


5.0 / 5


Task List

We will cover the following tasks in 21 minutes:


Imagine for a moment.

Exploratory Analysis

Why not get a quick glimpse at our data? EA is great for that.

kmeans time

No super data munging necessary. In this chapter we just get to it. We will build our model using k means. But not before looking and discussing (generally) its calls.

How did we do?

So let’s look and see how we did graphically?

Precise Accuracy

We will build a table and then I will go over how we calculate a accuracy number, which I’ll state here. Total Correct/Total Correct + Total Incorrect. Don’t be scared. Come in.

Final Thoughts

Yep. you now have an introduction to the Kmeans model. There are plenty of opportunities to use the skill in the future. I’ll name a few uses before sending you off. Thank you.

Watch Preview

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

Chris Shockley

About the Host (Chris Shockley)

I am a R enthusiast, hiker, and amateur astronomer. My favorite hike is located in Mt. Rainier National Park, my favorite Deep Sky Object is Alberio, and my favorite R package is dplyr (since I use it everyday). I am single too. Maybe because I spend too much time playing? I have a dog named Coog (Lllasa Apso), who would rather be outside than inside, which means I have to take him on a lot of walks. I work as a Data Analyst/Financial Analyst for a Metals Co. located in Seattle, WA. I have been in my current position for 4 years. My hope is that I can help you, even if its with my enthusiasm. Yes you can learn R and the Rhyme Interface will help you. But. You also must take what you learn and practice, practice, practice. So... Let's get after it. See you soon.

Frequently Asked Questions

In Rhyme, all sessions are completely hands on. You don't just passively watch someone else. You use the software directly while following the host's (Chris Shockley) 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.
Nothing! Just join through your web browser. Your host (Chris Shockley) has already installed all required software and configured all data.
You can go to, sign up for free, and follow this visual guide How to use Rhyme to create your own sessions. If you have custom needs or company-specific environment, please email us at
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 sessions 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
Please email us at and we'll respond to you within one business day.

No sessions available