Search in sources :

Example 16 with KMeansModel

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);
}
Also used : KMeansLloyd(de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans.KMeansLloyd) KMeansModel(de.lmu.ifi.dbs.elki.data.model.KMeansModel) FirstKInitialMeans(de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans.initialization.FirstKInitialMeans) Database(de.lmu.ifi.dbs.elki.database.Database) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) Test(org.junit.Test) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)

Aggregations

KMeansModel (de.lmu.ifi.dbs.elki.data.model.KMeansModel)16 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)12 WritableIntegerDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore)12 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)12 IndefiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress)11 ArrayList (java.util.ArrayList)11 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)10 DoubleStatistic (de.lmu.ifi.dbs.elki.logging.statistics.DoubleStatistic)10 LongStatistic (de.lmu.ifi.dbs.elki.logging.statistics.LongStatistic)10 StringStatistic (de.lmu.ifi.dbs.elki.logging.statistics.StringStatistic)10 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)5 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)5 KMeansLloyd (de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans.KMeansLloyd)3 Database (de.lmu.ifi.dbs.elki.database.Database)3 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)2 FirstKInitialMeans (de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans.initialization.FirstKInitialMeans)2 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)2 Test (org.junit.Test)2 RandomlyGeneratedInitialMeans (de.lmu.ifi.dbs.elki.algorithm.clustering.kmeans.initialization.RandomlyGeneratedInitialMeans)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1