public static void main(String[] args) throws Exception { ToolRunner.run(new FactorizationEvaluator(), args); }
addInputOption(); addOption("userFeatures", null, "path to the user feature matrix", true); addOption("itemFeatures", null, "path to the item feature matrix", true); addOption("usesLongIDs", null, "input contains long IDs that need to be translated"); addOutputOption(); Map<String,List<String>> parsedArgs = parseArguments(args); if (parsedArgs == null) { return -1; Path errors = getTempPath("errors"); Job predictRatings = prepareJob(getInputPath(), errors, TextInputFormat.class, PredictRatingsMapper.class, DoubleWritable.class, NullWritable.class, SequenceFileOutputFormat.class); conf.set(USER_FEATURES_PATH, getOption("userFeatures")); conf.set(ITEM_FEATURES_PATH, getOption("itemFeatures")); boolean usesLongIDs = Boolean.parseBoolean(getOption("usesLongIDs")); if (usesLongIDs) { conf.set(ParallelALSFactorizationJob.USES_LONG_IDS, String.valueOf(true)); FileSystem fs = FileSystem.get(getOutputPath().toUri(), getConf()); FSDataOutputStream outputStream = fs.create(getOutputPath("rmse.txt")); try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outputStream, Charsets.UTF_8))){ double rmse = computeRmse(errors); writer.write(String.valueOf(rmse));
double computeRmse(Path errors) { RunningAverage average = new FullRunningAverage(); for (Pair<DoubleWritable,NullWritable> entry : new SequenceFileDirIterable<DoubleWritable, NullWritable>(errors, PathType.LIST, PathFilters.logsCRCFilter(), getConf())) { DoubleWritable error = entry.getFirst(); average.addDatum(error.get() * error.get()); } return Math.sqrt(average.getAverage()); }
double computeRmse(Path errors) { RunningAverage average = new FullRunningAverage(); for (Pair<DoubleWritable,NullWritable> entry : new SequenceFileDirIterable<DoubleWritable, NullWritable>(errors, PathType.LIST, PathFilters.logsCRCFilter(), getConf())) { DoubleWritable error = entry.getFirst(); average.addDatum(error.get() * error.get()); } return Math.sqrt(average.getAverage()); }
addInputOption(); addOption("userFeatures", null, "path to the user feature matrix", true); addOption("itemFeatures", null, "path to the item feature matrix", true); addOption("usesLongIDs", null, "input contains long IDs that need to be translated"); addOutputOption(); Map<String,List<String>> parsedArgs = parseArguments(args); if (parsedArgs == null) { return -1; Path errors = getTempPath("errors"); Job predictRatings = prepareJob(getInputPath(), errors, TextInputFormat.class, PredictRatingsMapper.class, DoubleWritable.class, NullWritable.class, SequenceFileOutputFormat.class); conf.set(USER_FEATURES_PATH, getOption("userFeatures")); conf.set(ITEM_FEATURES_PATH, getOption("itemFeatures")); boolean usesLongIDs = Boolean.parseBoolean(getOption("usesLongIDs")); if (usesLongIDs) { conf.set(ParallelALSFactorizationJob.USES_LONG_IDS, String.valueOf(true)); FileSystem fs = FileSystem.get(getOutputPath().toUri(), getConf()); FSDataOutputStream outputStream = fs.create(getOutputPath("rmse.txt")); double rmse = computeRmse(errors); writer = new BufferedWriter(new OutputStreamWriter(outputStream, Charsets.UTF_8)); writer.write(String.valueOf(rmse));
public static void main(String[] args) throws Exception { ToolRunner.run(new FactorizationEvaluator(), args); }
private double computeRmse(Path errors) { RunningAverage average = new FullRunningAverage(); for (Pair<DoubleWritable,NullWritable> entry : new SequenceFileDirIterable<DoubleWritable, NullWritable>(errors, PathType.LIST, PathFilters.logsCRCFilter(), getConf())) { DoubleWritable error = entry.getFirst(); average.addDatum(error.get() * error.get()); } return Math.sqrt(average.getAverage()); }
addInputOption(); addOption("userFeatures", null, "path to the user feature matrix", true); addOption("itemFeatures", null, "path to the item feature matrix", true); addOption("usesLongIDs", null, "input contains long IDs that need to be translated"); addOutputOption(); Map<String,List<String>> parsedArgs = parseArguments(args); if (parsedArgs == null) { return -1; Path errors = getTempPath("errors"); Job predictRatings = prepareJob(getInputPath(), errors, TextInputFormat.class, PredictRatingsMapper.class, DoubleWritable.class, NullWritable.class, SequenceFileOutputFormat.class); conf.set(USER_FEATURES_PATH, getOption("userFeatures")); conf.set(ITEM_FEATURES_PATH, getOption("itemFeatures")); boolean usesLongIDs = Boolean.parseBoolean(getOption("usesLongIDs")); if (usesLongIDs) { conf.set(ParallelALSFactorizationJob.USES_LONG_IDS, String.valueOf(true)); FileSystem fs = FileSystem.get(getOutputPath().toUri(), getConf()); FSDataOutputStream outputStream = fs.create(getOutputPath("rmse.txt")); double rmse = computeRmse(errors); writer = new BufferedWriter(new OutputStreamWriter(outputStream, Charsets.UTF_8)); writer.write(String.valueOf(rmse));
public static void main(String[] args) throws Exception { ToolRunner.run(new FactorizationEvaluator(), args); }