本文介绍了在mahout-0.6上的"Mahout in Action"中运行示例代码时,获取IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Mahout并阅读行动中的Mahout".

I'm learning Mahout and reading "Mahout in Action".

当我尝试运行第7章SimpleKMeansClustering.java中的示例代码时,弹出一个异常:

When I tried to run the sample code in chapter7 SimpleKMeansClustering.java, an exception popped up:

线程主"中的异常java.io.IOException:错误值类:0.0:null不是org.apache.hadoop.io.SequenceFile $ Reader.next(SequenceFile .java:1874)在SimpleKMeansClustering.main(SimpleKMeansClustering.java:95)

Exception in thread "main" java.io.IOException: wrong value class: 0.0: null is not class org.apache.mahout.clustering.WeightedPropertyVectorWritable at org.apache.hadoop.io.SequenceFile$Reader.next(SequenceFile.java:1874) at SimpleKMeansClustering.main(SimpleKMeansClustering.java:95)

我在mahout-0.5上成功执行了此代码,但是在mahout-0.6上我看到了此异常.即使我将目录名称从clusters-0更改为clusters-0-final,我仍然面临着这种异常.

I successed this code on mahout-0.5, but on mahout-0.6 I saw this exception.Even I changed directory name from clusters-0 to clusters-0-final, I'm still facing this exception.

    KMeansDriver.run(conf, vectors, new Path(canopyCentroids, "clusters-0-final"), clusterOutput, new TanimotoDistanceMeasure(), 0.01, 20, true, false);//First, I changed this path.

    SequenceFile.Reader reader = new SequenceFile.Reader(fs,  new Path("output/clusters/clusteredPoints/part-m-00000"), conf);//I double checked this folder and filename.

    IntWritable key = new IntWritable();
    WeightedVectorWritable value = new WeightedVectorWritable();
    int i=0;
    while(reader.next(key, value)) {
        System.out.println(value.toString() + " belongs to cluster " + key.toString());
        i++;
    }
    System.out.println(i);
    reader.close();

有人对此异常有任何想法吗?我已经尝试解决很长时间了,还没有任何想法.互联网上的资源很少.

Does anyone have any idea about this exception? I have been trying to solve it for a long time and haven't got any idea. And there are few sources on the internet.

预先感谢

推荐答案

为了使此示例在Mahout 0.6中工作,请添加

In order to make this example work in Mahout 0.6, add

import org.apache.mahout.clustering.WeightedPropertyVectorWritable;

导入并替换行:

 WeightedVectorWritable value = new WeightedVectorWritable();

作者

WeightedPropertyVectorWritable value = new WeightedPropertyVectorWritable();

之所以发生这种情况,是因为Mahout 0.6代码以新的WeightedPropertyVectorWritable类型写入了集群输出值.

This happens because the Mahout 0.6 code writes the clustering output values in the new type WeightedPropertyVectorWritable.

这篇关于在mahout-0.6上的"Mahout in Action"中运行示例代码时,获取IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:07