Back
Close

Computing with Data

elgeish
148K views

Clustering

Using the iris dataset, we try to fit the 150 samples into 3 clusters using the k-means algorithm:

import numpy as np
from sklearn import datasets
from sklearn.cluster import KMeans
from sklearn.metrics import *
iris = datasets.load_iris()
# instead of running the algorithm many times with random
# initial values for centroids, we picked one that works well;
# the values below were obtained from one of the random runs:
centroids = np.array([
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants