3000 explained code solutions for 75 technologies

python-scikit-learnK means clustering example

from sklearn import datasets, cluster

X, _ = datasets.load_iris(return_X_y=True)
model = cluster.KMeans(n_clusters = 3)

clusters = model.predict(X)ctrl + c
from sklearn import

import module from scikit-learn


create KMeans clustering model


number of clusters we want to see


train model with a given features and target variable dataset


predict target variable based on given features dataset