有没有办法写一个玩具Mahout的例子,它不使用序列文件而只是一组向量?
我正在尝试了解距离测量,并希望根据距离测量进行helloworld聚类。我不想用序列文件来膨胀它:
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;
}
这比预期的要容易:
List<Canopy> canopies = CanopyClusterer.createCanopies(vectorList,
new CosineDistanceMeasure(), 0.3, 0.3);
虽然我在晚些时候的Mahout版本中读到了冠层聚类是deprecated :(