在使用mahout的匿名推荐时候遇到了一个问题,您能帮我看看吗?

BravoZu 发布于 2012/06/15 10:27
阅读 510
收藏 0

@Breath_L 你好,想跟你请教个问题:报出下面的异常:recommender.MovieDataModel cannot be cast to org.apache.mahout.cf.taste.impl.model.PlusAnonymousUserDataModel

这是我在AnonymousRecommender类(继承了UserBasedRecommender类)中的实现:

public AnonymousRecommender() throws TasteException {

super();

plusAnonymousModel = (PlusAnonymousUserDataModel) super.getDataModel();

}

public  synchronized List<RecommendedItem> recommend(long userID, int howMany)throws TasteException {

   PreferenceArray anonymousPrefs = new GenericUserPreferenceArray(3);

   anonymousPrefs.setUserID(0,PlusAnonymousUserDataModel.TEMP_USER_ID);

   anonymousPrefs.setItemID(0, 50L);

   anonymousPrefs.setValue(0, 1.0f);

   anonymousPrefs.setItemID(1, 50L);

   anonymousPrefs.setValue(1, 3.0f);

   anonymousPrefs.setItemID(2, 50L);

   anonymousPrefs.setValue(2, 2.0f); 

   plusAnonymousModel.setTempPrefs(anonymousPrefs);

   List<RecommendedItem> recommendations = recommend(PlusAnonymousUserDataModel.TEMP_USER_ID, howMany, null);

  

   plusAnonymousModel.clearTempPrefs();

   return recommendations;

 }

然后在UserBasedRecommender类的构造方法如下:

public UserBasedRecommender() throws TasteException{

this(new MovieDataModel(),PrefileDao.getAllPrefile());

}

 public UserBasedRecommender(DataModel model,List<Prefile> prefileList) throws TasteException {

List<Prefile> prefiles = prefileList;

//UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(model);

UserSimilarity userSimilarity = new EuclideanDistanceSimilarity(model);

//userSimilarity.setPreferenceInferrer(new AveragingPreferenceInferrer(model));

UserNeighborhood neighborhood =

 new NearestNUserNeighborhood(3, userSimilarity, model);

recommender = new CachingRecommender(new GenericUserBasedRecommender(model, neighborhood, userSimilarity));

this.model = model;

   FastIDSet[] menWomen = GenderRescorer.parseMenWomen(prefiles);

   men = menWomen[0];

   women = menWomen[1];

   usersRateMoreMen = new FastIDSet(1000);

   usersRateLessMen = new FastIDSet(1000);

 }
采用的数据源是MySQLJDBC的连接方式!!!

加载中
0
Breath_L
Breath_L
MovieDataModel   无法转换成  PlusAnonymousUserDataModel,也许 UserBasedRecommender和 PlusAnonymousUserDataModel 有不同的地方,你仔细看看吧,具体我也了解,没用过
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部