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

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

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Did you know that 50- 80% of your enterprise business processes can be automated with AssistEdge?  Identify processes, deploy bots and scale effortlessly with AssistEdge.

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!

Consuming AI in byte sized applications is the best way to transform digitally. #BuiltOnAI, EdgeVerve’s business application, provides you with everything you need to plug & play AI into your enterprise.  Learn more.

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

Comment (0)

Save
{{ articles[0].views | formatCount}} Views

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.