1

我在 Mahout 中下载了 Jester 示例代码,并尝试在 jester 数据集上运行它以查看评估结果。运行成功,但控制台只有结果:

log4j:WARN No appenders could be found for logger (org.apache.mahout.cf.taste.impl.model.file.FileDataModel).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

我希望看到评估分数范围从 0 到 10。任何人都可以帮助我找出如何获得分数?

我正在使用 mahout-core-0.6.jar,以下是代码:

JesterDataModel.java:
package Jester;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.regex.Pattern;

import com.google.common.collect.Lists;
import org.apache.mahout.cf.taste.example.grouplens.GroupLensDataModel;
import org.apache.mahout.cf.taste.impl.common.FastByIDMap;
import org.apache.mahout.cf.taste.impl.model.GenericDataModel;
import org.apache.mahout.cf.taste.impl.model.GenericPreference;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.model.Preference;
import org.apache.mahout.common.iterator.FileLineIterator;
//import org.apache.mahout.cf.taste.impl.common.FileLineIterable;

public final class JesterDataModel extends FileDataModel {

  private static final Pattern COMMA_PATTERN = Pattern.compile(",");

  private long userBeingRead;

  public JesterDataModel() throws IOException {
    this(GroupLensDataModel.readResourceToTempFile("\\jester-data-1.csv"));
  }


  public JesterDataModel(File ratingsFile) throws IOException {
     super(ratingsFile);
  }

  @Override
  public void reload() {
     userBeingRead = 0;
    super.reload();
  }

  @Override
  protected DataModel buildModel() throws IOException {
    FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>  ();
    FileLineIterator iterator = new FileLineIterator(getDataFile(), false);
    FastByIDMap<FastByIDMap<Long>> timestamps = new FastByIDMap<FastByIDMap<Long>>();
    processFile(iterator, data, timestamps, false);
    return new GenericDataModel(GenericDataModel.toDataMap(data, true));
  }

   @Override
  protected void processLine(String line,
                         FastByIDMap<?> rawData,
                         FastByIDMap<FastByIDMap<Long>> timestamps,
                         boolean fromPriorData) {
  FastByIDMap<Collection<Preference>> data = (FastByIDMap<Collection<Preference>>) rawData;
  String[] jokePrefs = COMMA_PATTERN.split(line);
  int count = Integer.parseInt(jokePrefs[0]);
  Collection<Preference> prefs = Lists.newArrayListWithCapacity(count);
  for (int itemID = 1; itemID < jokePrefs.length; itemID++) { // yes skip first one, just a count
   String jokePref = jokePrefs[itemID];
  if (!"99".equals(jokePref)) {
    float jokePrefValue = Float.parseFloat(jokePref);
    prefs.add(new GenericPreference(userBeingRead, itemID, jokePrefValue));
  }
}
data.put(userBeingRead, prefs);
userBeingRead++;

}

}

JesterRecommenderEvaluatorRunner.java
package Jester;

import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.eval.RecommenderEvaluator;
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator;
import org.apache.mahout.cf.taste.model.DataModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public final class JesterRecommenderEvaluatorRunner {

  private static final Logger log = LoggerFactory.getLogger(JesterRecommenderEvaluatorRunner.class);

  private JesterRecommenderEvaluatorRunner() {
    // do nothing
  }

  public static void main(String... args) throws IOException, TasteException {
    RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
    DataModel model = new JesterDataModel();
    double evaluation = evaluator.evaluate(new JesterRecommenderBuilder(),
                                       null,
                                       model,
                                       0.9,
                                       1.0);
    log.info(String.valueOf(evaluation));
  }

}

4

1 回答 1

0

Mahout 0.7 很旧,0.6 很旧。以后从 SVN 至少使用 0.7 或更好。我认为问题正是您所确定的:您的类路径中没有任何 slf4j 绑定。如果您在 Mahout 中使用“.job”文件,您将拥有所有依赖包。然后你会真正看到输出。

于 2013-04-03T09:08:31.227 回答