Unsupervised Learning using K-Means Clustering
This article was AI-drafted and has not been reviewed yet. Spotted a mistake? Tell us.
Learn how to perform unsupervised learning using K-Means clustering and Scikit-Learn.
Introduction to Unsupervised Learning
Unsupervised learning is a type of machine learning where the algorithm learns patterns and relationships in the data without any prior knowledge of the output. In this tutorial, we will learn how to perform unsupervised learning using K-Means clustering and Scikit-Learn.
Installing the Required Libraries
To install the required libraries, run the following command in your terminal:
pip install scikit-learn
Loading the Dataset
We will use the Iris dataset, a classic multiclass classification problem.
from sklearn import datasets
iris = datasets.load_iris()
X = iris.data
Building the Model
We will build a simple K-Means clustering model using Scikit-Learn.
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=3)
kmeans.fit(X)
print(kmeans.labels_)
Conclusion
In this tutorial, we learned how to perform unsupervised learning using K-Means clustering and Scikit-Learn. We loaded the dataset, built the model, and trained it on the data.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based unsupervised learning courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for unsupervised learning books — check the publication year so the examples match current versions.
Search Amazon →