O'Reilly logo

Hands-On Automated Machine Learning by Umit Mert Cakmak, Sibanjan Das

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required