Computer scienceData scienceInstrumentsScikit-learnScikit-learn basics

Training a model with scikit-learn

Unsupervised algorithm

Report a typo

K-means is one of the best-known techniques for clustering which bases itself on the idea of unsupervised learning. Suppose we want to train the K-means model on the built-in Iris dataset. We loaded it using load_iris() and saved the feature matrix to X and the target values to y.

from sklearn.cluster import KMeans
from sklearn import datasets

X, y = datasets.load_iris(return_X_y=True)
k_means = KMeans()
k_means.fit(y)

Then we fitted the model on the data. However, there is one mistake in the code. Recall which data we need for unsupervised learning, correct the line and print the corrected line in the text field below.

Enter a short text
___

Create a free account to access the full topic