Commit 48a4331d authored by Carsten Eie Frigaard's avatar Carsten Eie Frigaard
Browse files


parent 7b9809ae
......@@ -10,3 +10,4 @@ L07/Yolov5_setup/temp.jpg
\ No newline at end of file
%% Cell type:markdown id: tags:
# K-Means Demo
%% Cell type:code id: tags:
``` python
import matplotlib.pyplot as plt
from sklearn.datasets import make_blobs
features, label = make_blobs(n_samples=500, centers=3, cluster_std=0.55, random_state=0)
plt.figure(figsize=(10, 6))
plt.scatter(features[:, 0], features[:, 1], s=50);
%% Output
%% Cell type:code id: tags:
``` python
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=2)
kmeans = KMeans(n_clusters=3)
kmeansLabels = kmeans.predict(features)
plt.scatter(features[:, 0], features[:, 1], c=kmeansLabels, s=50, cmap='viridis')
clusterCenters = kmeans.cluster_centers_
plt.scatter(clusterCenters[:, 0], clusterCenters[:, 1], c='red', s=200, alpha=0.8)
%% Output
This source diff could not be displayed because it is too large. You can view the blob instead.
No preview for this file type
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment