Apache Ignite Documentation

GridGain Developer Hub - Apache Ignitetm

Welcome to the Apache Ignite developer hub run by GridGain. Here you'll find comprehensive guides and documentation to help you start working with Apache Ignite as quickly as possible, as well as support if you get stuck.


GridGain also provides Community Edition which is a distribution of Apache Ignite made available by GridGain. It is the fastest and easiest way to get started with Apache Ignite. The Community Edition is generally more stable than the Apache Ignite release available from the Apache Ignite website and may contain extra bug fixes and features that have not made it yet into the release on the Apache website.


Let's jump right in!


Documentation     Ask a Question     Download


Javadoc     Scaladoc     Examples

k-NN Classification

The Apache Ignite Machine Learning component provides two versions of the widely used k-NN (k-nearest neighbors) algorithm - one for classification tasks and the other for regression tasks.

This documentation reviews k-NN as a solution for classification tasks.

Trainer & Model

The k-NN algorithm is a non-parametric method whose input consists of the k-closest training examples in the feature space.

Also, k-NN classification's output represents a class membership. An object is classified by the majority votes of its neighbors. The object is assigned to a particular class that is most common among its k nearest neighbors. k is a positive integer, typically small. There is a special case when k is 1, then the object is simply assigned to the class of that single nearest neighbor.

Presently, Ignite supports a few parameters for k-NN classification algorithm:

  • k - a number of nearest neighbors
  • distanceMeasure - one of the distance metrics provided by the ML framework such as Euclidean, Hamming or Manhattan.
  • isWeighted - false by default, if true it enables a weighted KNN algorithm.
  • dataCache - holds a training set of objects for which the class is already known.
  • indexType - distributed spatial index, has three values: ARRAY, KD_TREE, BALL_TREE.
// Create trainer
KNNClassificationTrainer trainer = new KNNClassificationTrainer();

// Create trainer
KNNClassificationTrainer trainer = new KNNClassificationTrainer()
  .withDistanceMeasure(new EuclideanDistance())

// Train model.
KNNClassificationModel knnMdl = trainer.fit(

// Make a prediction. 
double prediction = knnMdl.predict(observation);


To see how kNN Classification can be used in practice, try this example that is available on GitHub and delivered with every Apache Ignite distribution.

The training dataset is the Iris dataset which can be loaded from the UCI Machine Learning Repository.

Updated 5 months ago

k-NN Classification

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.