我想推荐一个用户,当前用户可以添加为朋友的用户列表。
我正在使用 Cassandra 和 mahout。在 mahout 集成包中已经有CassandraDataModel的实现。我想使用这个类。
所以我的推荐类看起来如下
public class UserFriendsRecommender {
@Inject
private CassandraDataModel dataModel;
public List<RecommendedItem> recommend(Long userId, int number) throws TasteException{
UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(dataModel);
// Optional:
userSimilarity.setPreferenceInferrer(new AveragingPreferenceInferrer(dataModel));
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(3, userSimilarity, dataModel);
Recommender recommender = new GenericUserBasedRecommender(dataModel, neighborhood, userSimilarity);
Recommender cachingRecommender = new CachingRecommender(recommender);
List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, number);
return recommendations;
}
}
CassandraDataModel 有 4 个列族
static final String USERS_CF = "users";
static final String ITEMS_CF = "items";
static final String USER_IDS_CF = "userIDs";
static final String ITEM_IDS_CF = "itemIDs";
我很难理解这门课,尤其是专栏家庭的。有没有我可以寻找的例子,或者如果有人可以用一个小例子来解释会很棒。?
javadoc 说这个
* <p>
* First, it uses a column family called "users". This is keyed by the user ID
* as an 8-byte long. It contains a column for every preference the user
* expresses. The column name is item ID, again as an 8-byte long, and value is
* a floating point value represnted as an IEEE 32-bit floating poitn value.
* </p>
*
* <p>
* It uses an analogous column family called "items" for the same data, but
* keyed by item ID rather than user ID. In this column family, column names are
* user IDs instead.
* </p>
*
* <p>
* It uses a column family called "userIDs" as well, with an identical schema.
* It has one row under key 0. It contains a column for every user ID in the
* model. It has no values.
* </p>
*
* <p>
* Finally it also uses an analogous column family "itemIDs" containing item
* IDs.
* </p>