Last active
August 21, 2019 10:20
-
-
Save debonx/2282062fa3ae6e3e5891b884c17f7e77 to your computer and use it in GitHub Desktop.
Example of Unsupervised Machine Learning with KMeans (sklearn).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
from sklearn import datasets | |
# From sklearn.cluster, import Kmeans class | |
from sklearn.cluster import KMeans | |
# Load data | |
iris = datasets.load_iris() | |
samples = iris.data | |
# Use KMeans() to create a model that finds 3 clusters | |
model = KMeans(n_clusters = 3) | |
# Use .fit() to fit the model to samples | |
model.fit(samples) | |
# Use .predict() to determine the labels of samples | |
labels = model.predict(samples) | |
# Print the labels | |
print(labels) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment