use of org.apache.ignite.ml.clustering.KMeansModel in project ignite by apache.
the class KMeansLocalClustererExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String[] args) {
// IMPL NOTE based on KMeansDistributedClustererTestSingleNode#testClusterizationOnDatasetWithObviousStructure
System.out.println(">>> K-means local clusterer example started.");
int ptsCnt = 10000;
DenseLocalOnHeapMatrix points = new DenseLocalOnHeapMatrix(ptsCnt, 2);
DatasetWithObviousStructure dataset = new DatasetWithObviousStructure(10000);
List<Vector> massCenters = dataset.generate(points);
EuclideanDistance dist = new EuclideanDistance();
OrderedNodesComparator comp = new OrderedNodesComparator(dataset.centers().values().toArray(new Vector[] {}), dist);
massCenters.sort(comp);
KMeansLocalClusterer clusterer = new KMeansLocalClusterer(dist, 100, 1L);
KMeansModel mdl = clusterer.cluster(points, 4);
Vector[] resCenters = mdl.centers();
Arrays.sort(resCenters, comp);
System.out.println("Mass centers:");
massCenters.forEach(Tracer::showAscii);
System.out.println("Cluster centers:");
Arrays.asList(resCenters).forEach(Tracer::showAscii);
System.out.println("\n>>> K-means local clusterer example completed.");
}
use of org.apache.ignite.ml.clustering.KMeansModel in project ignite by apache.
the class LocalModelsTest method importExportKMeansModelTest.
/**
*/
@Test
public void importExportKMeansModelTest() throws IOException {
executeModelTest(mdlFilePath -> {
KMeansModel mdl = getClusterModel();
Exporter<KMeansModelFormat, String> exporter = new FileExporter<>();
mdl.saveModel(exporter, mdlFilePath);
KMeansModelFormat load = exporter.load(mdlFilePath);
Assert.assertNotNull(load);
KMeansModel importedMdl = new KMeansModel(load.getCenters(), load.getDistance());
Assert.assertTrue("", mdl.equals(importedMdl));
return null;
});
}
Aggregations