本文整理汇总了Java中org.apache.mahout.cf.taste.model.DataModel.getUserIDs方法的典型用法代码示例。如果您正苦于以下问题:Java DataModel.getUserIDs方法的具体用法?Java DataModel.getUserIDs怎么用?Java DataModel.getUserIDs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.cf.taste.model.DataModel
的用法示例。
在下文中一共展示了DataModel.getUserIDs方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRecommend
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public void buildRecommend(String taskName) {
String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
HadoopUtil.download(taskName, itemmodelsPath, true);
try {
DataModel dataModel = new FileDataModel(new File(itemmodelsPath));
UserSimilarity similarity = new SpearmanCorrelationSimilarity(dataModel);
UserNeighborhood userNeighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);
LongPrimitiveIterator userIDs = dataModel.getUserIDs();
while (userIDs.hasNext()) {
Long userID = userIDs.nextLong();
long[] neighborhoods = userNeighborhood.getUserNeighborhood(userID);
for (long neighborhood : neighborhoods) {
double userSimilarity = similarity.userSimilarity(userID, neighborhood);
System.out.printf("(%s,%s,%f)", userID, neighborhood, userSimilarity);
System.out.println();
}
}
} catch (TasteException | IOException e) {
log.error(e);
}
}
示例2: main
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
String file = "other/testdata/pv.csv";
DataModel dataModel = RecommendFactory.buildDataModelNoPref(file);
//基于UserCF城市街区距离(曼哈顿)算法
RecommenderBuilder rb1 = RecommenderEvaluator.userCityBlock(dataModel);
//基于ItemCF对数自然相似度算法
RecommenderBuilder rb2 = RecommenderEvaluator.itemCityBlock(dataModel);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
System.out.print("userCityBlock =>");
result(uid, rb1, dataModel);
System.out.print("itemLoglikelihood=>");
result(uid, rb2, dataModel);
}
}
示例3: displayRecommendation
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void displayRecommendation(
List<RecommendedItem> recommendations, DataModel dataModel)
throws TasteException {
for (LongPrimitiveIterator users = dataModel.getUserIDs(); users
.hasNext();) {
long userId = users.nextLong();
// List<RecommendedItem> recommendations =
// recommender.recommend(userId, 5);
for (RecommendedItem recommendation : recommendations) {
System.out.println(userId + "," + recommendation.getItemID()
+ "," + recommendation.getValue());
}
}
}
示例4: main
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
String file = "other/testdata/pv.csv";
DataModel dataModel = RecommendFactory.buildDataModelNoPref(file);
RecommenderBuilder rb1 = RecommenderEvaluator.userCityBlock(dataModel);
RecommenderBuilder rb2 = RecommenderEvaluator.itemLoglikelihood(dataModel);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
System.out.print("userCityBlock =>");
filterOutdate(uid, rb1, dataModel);
System.out.print("itemLoglikelihood=>");
filterOutdate(uid, rb2, dataModel);
}
}
示例5: userCF
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void userCF(DataModel dataModel) throws TasteException {
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, true);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例6: itemCF
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void itemCF(DataModel dataModel) throws TasteException {
ItemSimilarity itemSimilarity = RecommendFactory.itemSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
RecommenderBuilder recommenderBuilder = RecommendFactory.itemRecommender(itemSimilarity, true);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例7: slopeOne
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void slopeOne(DataModel dataModel) throws TasteException {
RecommenderBuilder recommenderBuilder = RecommendFactory.slopeOneRecommender();
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例8: itemKNN
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void itemKNN(DataModel dataModel) throws TasteException {
ItemSimilarity itemSimilarity = RecommendFactory.itemSimilarity(RecommendFactory.SIMILARITY.EUCLIDEAN, dataModel);
RecommenderBuilder recommenderBuilder = RecommendFactory.itemKNNRecommender(itemSimilarity, new NonNegativeQuadraticOptimizer(), 10);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例9: svd
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void svd(DataModel dataModel) throws TasteException {
RecommenderBuilder recommenderBuilder = RecommendFactory.svdRecommender(new ALSWRFactorizer(dataModel, 10, 0.05, 10));
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例10: treeCluster
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void treeCluster(DataModel dataModel) throws TasteException {
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.LOGLIKELIHOOD, dataModel);
ClusterSimilarity clusterSimilarity = RecommendFactory.clusterSimilarity(RecommendFactory.SIMILARITY.FARTHEST_NEIGHBOR_CLUSTER, userSimilarity);
RecommenderBuilder recommenderBuilder = RecommendFactory.treeClusterRecommender(clusterSimilarity, 10);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
示例11: main
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
public static void main( String[] args ) throws IOException, TasteException, OptionException
{
CreateCsvRatingsFile();
// create data source (model) - from the csv file
File ratingsFile = new File(outputFile);
DataModel model = new FileDataModel(ratingsFile);
// create a simple recommender on our data
CachingRecommender cachingRecommender = new CachingRecommender(new SlopeOneRecommender(model));
// for all users
for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();){
long userId = it.nextLong();
// get the recommendations for the user
List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10);
// if empty write something
if (recommendations.size() == 0){
System.out.print("User ");
System.out.print(userId);
System.out.println(": no recommendations");
}
// print the list of recommendations for each
for (RecommendedItem recommendedItem : recommendations) {
System.out.print("User ");
System.out.print(userId);
System.out.print(": ");
System.out.println(recommendedItem);
}
}
}
示例12: runALSSVDRecommender
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
private static void runALSSVDRecommender(DataModel dataModel)
throws TasteException {
System.out.println("Start of Running an ALS SVD Recommendation");
RecommenderBuilder recommenderBuilder = EEGVideoRecommender.buildSVDRecommender();
SVDRecommender recommender = (SVDRecommender) recommenderBuilder
.buildRecommender(dataModel);
RunningAverage runningAverage = new FullRunningAverage();
LongPrimitiveIterator userIDs = dataModel.getUserIDs();
while (userIDs.hasNext()) {
long userID = userIDs.nextLong();
for (Preference pref : dataModel.getPreferencesFromUser(userID)) {
double ratingValue = pref.getValue();
double preferenceEstimate = recommender.estimatePreference(
userID, pref.getItemID());
System.out.println(userID + "," + pref.getItemID() + ","
+ ratingValue);
double errorValue = ratingValue - preferenceEstimate;
runningAverage.addDatum(errorValue * errorValue);
}
}
double rmse = Math.sqrt(runningAverage.getAverage());
System.out.println(rmse);
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, 0.9, 1.0);
System.out.println("ALS-based Recommender Average Score is: " + score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, 0.9, 1.0);
System.out.println("ALS-based Recommender RMS Score is:" + rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
null, dataModel, null, 2,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println("Precision Valus is : " + stats.getPrecision());
System.out.println("Recall Value is : " + stats.getRecall());
System.out.println("End of Running an ALS SVD Recommendation");
}
示例13: runUserBasedRecommender
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
private static void runUserBasedRecommender(DataModel dataModel)
throws TasteException {
UserSimilarity userSimilarity = RecommParametersMeasures
.getLogLikelihoodSimilarity(dataModel);
UserNeighborhood neighborhood = RecommParametersMeasures.getThreshold(
dataModel, userSimilarity, 0.1);
RecommenderBuilder recommenderBuilder = EEGVideoRecommender.userBuilder(
userSimilarity, neighborhood);
for (LongPrimitiveIterator users = dataModel.getUserIDs(); users
.hasNext();) {
long userId = users.nextLong();
List<RecommendedItem> recommendations = recommenderBuilder
.buildRecommender(dataModel).recommend(userId, 1);
for (RecommendedItem recommendation : recommendations) {
System.out.println(userId + "," + recommendation.getItemID()
+ "," + recommendation.getValue());
}
}
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, 0.9, 1.0);
System.out.println("User-based Recommender Average Score is: " + score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, 0.7, 0.3);
System.out.println("User-based Recommende RMS Score is:" + rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
null, dataModel, null, 1,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1);
System.out.println("Precision Valus is : " + stats.getPrecision());
System.out.println("Recall Value is : " + stats.getRecall());
}