@SuppressWarnings("deprecation") @Before public void setup() throws RecommenderBuildException { List<Rating> rs = new ArrayList<Rating>(); rs.add(Rating.create(1, 6, 4)); rs.add(Rating.create(2, 6, 2)); rs.add(Rating.create(1, 7, 3)); rs.add(Rating.create(2, 7, 2)); rs.add(Rating.create(3, 7, 5)); rs.add(Rating.create(4, 7, 2)); rs.add(Rating.create(1, 8, 3)); rs.add(Rating.create(2, 8, 4)); rs.add(Rating.create(3, 8, 3)); rs.add(Rating.create(4, 8, 2)); rs.add(Rating.create(5, 8, 3)); rs.add(Rating.create(6, 8, 2)); rs.add(Rating.create(1, 9, 3)); rs.add(Rating.create(3, 9, 4)); EventCollectionDAO dao = new EventCollectionDAO(rs); LenskitConfiguration config = new LenskitConfiguration(); config.bind(EventDAO.class).to(dao); config.bind(ItemScorer.class).to(ItemItemScorer.class); // this is the default config.bind(UserVectorNormalizer.class).to(DefaultUserVectorNormalizer.class); config.bind(VectorNormalizer.class).to(IdentityVectorNormalizer.class); LenskitRecommenderEngine engine = LenskitRecommenderEngine.build(config); session = engine.createRecommender(); recommender = session.getItemRecommender(); }
@Test public void testSnapshot() throws RecommenderBuildException { List<Rating> rs = new ArrayList<Rating>(); rs.add(Ratings.make(1, 5, 2)); rs.add(Ratings.make(1, 7, 4)); rs.add(Ratings.make(8, 4, 5)); rs.add(Ratings.make(8, 5, 4)); EventDAO dao = EventCollectionDAO.create(rs); LenskitConfiguration config = new LenskitConfiguration(); config.bind(EventDAO.class).to(dao); config.bind(ItemScorer.class).to(UserUserItemScorer.class); config.bind(NeighborFinder.class).to(SnapshotNeighborFinder.class); LenskitRecommenderEngine engine = LenskitRecommenderEngine.build(config); Recommender rec = engine.createRecommender(); assertThat(rec.getItemScorer(), instanceOf(UserUserItemScorer.class)); assertThat(rec.getItemRecommender(), instanceOf(TopNItemRecommender.class)); RatingPredictor pred = rec.getRatingPredictor(); assertThat(pred, instanceOf(SimpleRatingPredictor.class)); Recommender rec2 = engine.createRecommender(); assertThat(rec2.getItemScorer(), not(sameInstance(rec.getItemScorer()))); }
@Override public LenskitConfiguration getConfiguration() { LenskitConfiguration config = new LenskitConfiguration(); Provider<BinaryRatingDAO> provider = Providers.fromSupplier(packedDao, BinaryRatingDAO.class); config.bind(BinaryRatingDAO.class).toProvider(provider); PreferenceDomain dom = getPreferenceDomain(); if (dom != null) { config.addComponent(dom); } return config; }
@SuppressWarnings("deprecation") @Before public void setup() throws RecommenderBuildException { List<Rating> rs = new ArrayList<Rating>(); rs.add(Ratings.make(1, 5, 2)); rs.add(Ratings.make(1, 7, 4)); rs.add(Ratings.make(8, 4, 5)); rs.add(Ratings.make(8, 5, 4)); EventDAO dao = new EventCollectionDAO(rs); LenskitConfiguration config = new LenskitConfiguration(); config.bind(EventDAO.class).to(dao); config.bind(ItemScorer.class).to(UserUserItemScorer.class); config.bind(NeighborFinder.class).to(LiveNeighborFinder.class); engine = LenskitRecommenderEngine.build(config); }
/** * Create the LensKit recommender configuration for <b>unweighted</b> user profile creation. * * @return The LensKit recommender configuration. */ @SuppressWarnings("unchecked") public static LenskitConfiguration configureRecommender() { LenskitConfiguration config = new LenskitConfiguration(); // configure the rating data source config.bind(EventDAO.class).to(MOOCRatingDAO.class); config.set(RatingFile.class).to(new File("data/ratings.csv")); // use custom item and user DAOs // specify item DAO implementation with tags config.bind(ItemDAO.class).to(CSVItemTagDAO.class); // specify tag file config.set(TagFile.class).to(new File("data/movie-tags.csv")); // and title file config.set(TitleFile.class).to(new File("data/movie-titles.csv")); // our user DAO can look up by user name config.bind(UserDAO.class).to(MOOCUserDAO.class); config.set(UserFile.class).to(new File("data/users.csv")); // use the TF-IDF scorer you will implement to score items config.bind(ItemScorer.class).to(TFIDFItemScorer.class); return config; }