Mahout clustering without sequence files?

35 Views Asked by At

Is there any way to write a toy Mahout example that doesn't use sequence files but just a collection of vectors?

I am trying to learn about distance measures and want to do a helloworld clustering based on the distance measure. I'd prefer not to bloat it with sequence files:

    public static void main(String[] args) {

        Vector v1 = toVector("java is very good");
        Vector v2 = toVector("java is very bad");
        double distance = new CosineDistanceMeasure().distance(v1, v2);
        System.out.println("DistanceMeasureMain.main() distance is "
                + distance);

        // TODO: run KMeansDriver without sequence files if possible
    }

    private static Vector toVector(String string) {

        String[] words = string.split("\\s");
        Vector v = new SequentialAccessSparseVector(Integer.MAX_VALUE );
        int i = 0;
        for (String word : words) {
            v.set(word.hashCode(), 1);
        }
        return v;
    }
1

There are 1 best solutions below

0
Sridhar Sarnobat On

That was easier than expected:

List<Canopy> canopies = CanopyClusterer.createCanopies(vectorList,
                    new CosineDistanceMeasure(), 0.3, 0.3);

Though I read that canopy clustering is deprecated in later releases of Mahout :(