RecommendationTrainer { public RecommendationModel<Serializable, Serializable> fit(DatasetBuilder<Object, BinaryObject> datasetBuilder, String objFieldName, String subjFieldName, String ratingFieldName) { try (Dataset<EmptyContext, RecommendationDatasetData<Serializable, Serializable>> dataset = datasetBuilder.build( environmentBuilder, new EmptyContextBuilder<>(), new RecommendationBinaryDatasetDataBuilder(objFieldName, subjFieldName, ratingFieldName), trainerEnvironment )) { return train(dataset); } catch (Exception e) { throw new RuntimeException(e); } }  RecommendationModel<Serializable, Serializable> fit(DatasetBuilder<Object, BinaryObject> datasetBuilder,
        String objFieldName, String subjFieldName, String ratingFieldName); RecommendationModel<O, S> fit(
        DatasetBuilder<K, ? extends ObjectSubjectRatingTriplet<O, S>> datasetBuilder); RecommendationTrainer withLearningEnvironmentBuilder(LearningEnvironmentBuilder environmentBuilder); RecommendationTrainer withTrainerEnvironment(LearningEnvironment trainerEnvironment); RecommendationTrainer withBatchSize(int batchSize); RecommendationTrainer withRegularizer(double regParam); RecommendationTrainer withLearningRate(double learningRate); RecommendationTrainer withMaxIterations(int maxIterations); RecommendationTrainer withMinMdlImprovement(double minMdlImprovement); RecommendationTrainer withK(int k);  }
@Test public void testFit() { int size = 100; Random rnd = new Random(0L); Double[][] ratings = new Double[size][size]; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (rnd.nextBoolean()) ratings[i][j] = ((i > size / 2) ^ (j > size / 2)) ? 1.0 : 0.0; } } int seq = 0; Map<Integer, ObjectSubjectRatingTriplet<Integer, Integer>> data = new HashMap<>(); for (ObjectSubjectRatingTriplet<Integer, Integer> triplet : toList(ratings)) data.put(seq++, triplet); RecommendationTrainer trainer = new RecommendationTrainer() .withLearningRate(50.0) .withBatchSize(10) .withK(2) .withMaxIterations(-1) .withMinMdlImprovement(0.5) .withLearningEnvironmentBuilder(LearningEnvironmentBuilder.defaultBuilder().withRNGSeed(1)) .withTrainerEnvironment(LearningEnvironmentBuilder.defaultBuilder().withRNGSeed(1).buildForTrainer()); RecommendationModel<Integer, Integer> mdl = trainer.fit(new LocalDatasetBuilder<>(data, 10)); int incorrect = 0; for (ObjectSubjectRatingTriplet<Integer, Integer> triplet : toList(ratings)) { double prediction = Math.round(mdl.predict(triplet)); if (Math.abs(prediction - triplet.getRating()) >= 1e-5) incorrect++; } assertEquals(0, incorrect); }