Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Setting Stopping Criteria for H2O k-Means [Code Snippets]

DZone's Guide to

Setting Stopping Criteria for H2O k-Means [Code Snippets]

Get the code you need to set the stopping criteria for your H2O k-Means algorithm using your choice of R, Python, Java, or Scala!

· AI Zone
Free Resource

Insight for I&O leaders on deploying AIOps platforms to enhance performance monitoring today. Read the Guide.

Sometimes, you may be looking for k-Means stopping criteria based on the number of reassigned observations within cluster.

H2O k-Means implementation has the following two stopping criteria in k-Means:

  1. Outer loop for estimate_k: Stop when the relative reduction of sum-of-within-centroid-sum-of-squares is small enough
  2. lloyds iteration: Stop when the elative fraction of reassigned points is small enough.

In the H2O machine learning library, you just need to set estimate_k to True and then have max_iterations set to a very high number (i.e. 100).

Using this combination, the algorithm will find the best suitable K until it hits the max. There are no other fine-tuning parameters available.

In R, here is what you can do:

h2o.kmeans(x = predictors, k = 100, estimate_k = T, standardize = F,
                          training_frame = train, validation_frame=valid, seed = 1234)

In Python, here is what you can do:

iris_kmeans = H2OKMeansEstimator(k = 100, estimate_k = True, standardize = False, seed = 1234)
iris_kmeans.train(x = predictors, training_frame = train, validation_frame=valid)

In Java or Scala, here is what you can do:

_estimate_k  = TRUE
_max_iterations = 100 (or a larger number.)

That's it. Enjoy!

TrueSight is an AIOps platform, powered by machine learning and analytics, that elevates IT operations to address multi-cloud complexity and the speed of digital transformation.

Topics:
machine learning ,h2o ,python ,java ,ai ,k-means ,stop ,algorithm

Published at DZone with permission of Avkash Chauhan, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}