有没有办法写一个不使用序列文件而只使用向量集合的玩具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;
}
答案 0 :(得分:0)
这比预期的容易:
List<Canopy> canopies = CanopyClusterer.createCanopies(vectorList,
new CosineDistanceMeasure(), 0.3, 0.3);
尽管我读到在更高版本的Mahout中树冠群集是deprecated:(