http://terryma.blog.sohu.com/58889892.html
關注推薦系統有好一陣了,居然沒有任何的產出,慚愧、慚愧。
這幾天學習了一下開源的java推薦系統Taste,有一些心得,慢慢的貼出來。
如果產生Item-based推薦:
假設有4個使用者 u1、u2、u3、u4
產品有n個 c1、c2、c3
步驟:
1.找出使用者對產品的打分。
2.找出產品之間的相似性。
3.可以對特定使用者給予推薦。
其中需要人工做的就是對產品之間的相似性,給出評分,這個是個比較麻煩的事情,如果有n個產品,就需要N!個評分。
如果用Taste實現,需要的代碼如下:
1。建立資料集,主要資料內容是使用者對產品的打分:
DataModel model = new FileDataModel(new File("data.txt"));2。建立item相似性,集合 例如:先建物(這裡有三個物品) final Item item1 = new GenericItem<String>("0"); final Item item2 = new GenericItem<String>("1"); final Item item3 = new GenericItem<String>("2“); 再記錄item的相似性 final Collection<GenericItemCorrelation.ItemItemCorrelation> correlations = new ArrayList<GenericItemCorrelation.ItemItemCorrelation>(2); correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item2, 1.0)); correlations.add(new GenericItemCorrelation.ItemItemCorrelation(item1, item3, 0.5)); 3.產生推薦 final ItemCorrelation correlation = new GenericItemCorrelation(correlations); final Recommender recommender = GenericItemBasedRecommender(dataModel, correlation); 4.最終產生推薦 final List<RecommendedItem> recommended = recommender.recommend("test1", 1); final RecommendedItem firstRecommended = recommended.get(0); |