use of de.lmu.ifi.dbs.elki.data.model.KMeansModel in project elki by elki-project.
the class WithinClusterVarianceQualityMeasureTest method testVariance.
/**
* Test cluster variance.
*/
@Test
public void testVariance() {
Database db = makeSimpleDatabase(UNITTEST + "quality-measure-test.csv", 7);
Relation<DoubleVector> rel = db.getRelation(TypeUtil.DOUBLE_VECTOR_FIELD);
// Setup algorithm
KMeansLloyd<DoubleVector> kmeans = //
new ELKIBuilder<KMeansLloyd<DoubleVector>>(KMeansLloyd.class).with(KMeans.K_ID, //
2).with(KMeans.INIT_ID, //
FirstKInitialMeans.class).build();
// run KMeans on database
Clustering<KMeansModel> result = kmeans.run(db);
// Test Cluster Variance
KMeansQualityMeasure<? super DoubleVector> variance = new WithinClusterVarianceQualityMeasure();
final NumberVectorDistanceFunction<? super DoubleVector> dist = kmeans.getDistanceFunction();
final double quality = variance.quality(result, dist, rel);
assertEquals("Within cluster variance incorrect", 3.16666666666, quality, 1e-10);
}
Aggregations