本文整理汇总了Java中org.apache.mahout.cf.taste.model.JDBCDataModel类的典型用法代码示例。如果您正苦于以下问题:Java JDBCDataModel类的具体用法?Java JDBCDataModel怎么用?Java JDBCDataModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDBCDataModel类属于org.apache.mahout.cf.taste.model包,在下文中一共展示了JDBCDataModel类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.mahout.cf.taste.model.JDBCDataModel; //导入依赖的package包/类
public static void main(String[] args) {
try {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("root");
dataSource.setDatabaseName("rec");
JDBCDataModel dm = new MySQLJDBCDataModel(dataSource,"ratings","userid","itemid","rating","");
UserSimilarity similarity = new PearsonCorrelationSimilarity(dm);
UserNeighborhood neighbor = new NearestNUserNeighborhood(2,similarity, dm);
Recommender recommender = new GenericUserBasedRecommender(dm, neighbor, similarity);
List<RecommendedItem> list = recommender.recommend(1, 3);// recommend
// one item
// to user
// 1
for (RecommendedItem ri : list) {
System.out.println(ri);
}
} catch (Exception e) {
e.printStackTrace();
}
}