K-means algorithm in action

You can now apply the KMeans algorithm to see how it works:

from sklearn.cluster import KMeansestimators = [{'estimator': KMeans, 'args':(), 'kwargs':{'n_clusters': 4}}]unsupervised_learner = Unsupervised_AutoML(estimators)

You can see the estimators:

unsupervised_learner.estimators

These will output the following:

[{'args': (), 'estimator': sklearn.cluster.k_means_.KMeans, 'kwargs': {'n_clusters': 4}}]

You can now invoke fit_predict to obtain predictions and performance_metrics:

predictions, performance_metrics = unsupervised_learner.fit_predict(X, y)

Metrics will be written to the console:

################## KMeans metrics #####################  Silhouette Coefficient: 0.631 Estimated number of clusters: 4.000 ...

Get Hands-On Automated Machine Learning now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.