Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.apache.mahout.cf.yanTest;
- import org.apache.mahout.cf.taste.impl.model.jdbc.MySQLJDBCDataModel;
- import org.apache.mahout.cf.taste.impl.recommender.*;
- import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender;
- import org.apache.mahout.cf.taste.recommender.*;
- import java.util.*;
- import javax.naming.Context;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- class YaoT {
- private YaoT() {
- }
- public static void main(String[] args) throws Exception {
- Context ctx = new InitialContext();
- @DataSourceDefinition(
- name = "java:global/MyApp/MyDataSource",
- className = "org.apache.mahout.cf.yanTest",
- url = "jdbc:derby://localhost/testDatabase",
- user = "root",
- password = "1234")
- DataSource data;
- ctx.bind("testDatabase/testtable", data);
- MySQLJDBCDataModel model = new MySQLJDBCDataModel(data, "testtable", "user_ID", "item_ID", "user_ID", null);
- Recommender recommender = new CachingRecommender(new SlopeOneRecommender(model));
- List<RecommendedItem> recommendations = recommender.recommend(1, 1);
- for (RecommendedItem recommendation : recommendations) {
- System.out.println(recommendation);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement