predictionio优化

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了predictionio优化相关的知识,希望对你有一定的参考价值。

predictionio 的validScores方法 有点问题,因为model对象中的一个属性类型为Map<String, Item> items,在数据量很大的时候,肯定是不行,所以优化一下,采用join+filter的模式,代码如下

return all.mapToPair(new PairFunction<ItemScore, String, ItemScore>() {
            @Override
            public Tuple2<String, ItemScore> call(ItemScore idUser) throws Exception {
                return new Tuple2<>(idUser.getItemEntityId(), idUser);
            }
        }).join(model.getItems()).filter(new Function<Tuple2<String,Tuple2<ItemScore,Item>>, Boolean>() {
            @Override
            public Boolean call(Tuple2<String,Tuple2<ItemScore,Item>> itemScore) throws Exception {
                /*Item item = items.get(itemScore.getItemEntityId());*/

                Item item =itemScore._2._2;
                //logger.info("join end");

                return (item!=null && /*item != null 
                        && */passWhitelistCriteria(whitelist, itemScore._2._1.getItemEntityId())
                        && passBlacklistCriteria(blacklist, itemScore._2._1.getItemEntityId())
                       /* && passCategoryCriteria(categories, item)*/
                       /* && passUnseenCriteria(seenItemEntityIds, itemScore.getItemEntityId())*///看过或买过的不要
                       /* && passAvailabilityCriteria(unavailableItemEntityIds, itemScore.getItemEntityId())*/);
            }
        }).map(new Function<Tuple2<String, Tuple2<ItemScore,Item>>, ItemScore>() {
             @Override
             public ItemScore call(Tuple2<String, Tuple2<ItemScore,Item>> userItemCount) throws Exception {
                 return userItemCount._2._1;
             }
         });

以上是关于predictionio优化的主要内容,如果未能解决你的问题,请参考以下文章

predictionIO E-Commerce Recommendation 买了又买-物相似

predictionio 部署脚本

predictionIO E-Commerce Recommendation 源码分析

基于 PredictionIO 搭建全栈式机器学习平台

优化 C# 代码片段、ObservableCollection 和 AddRange

使用 C++ 反转句子中的每个单词需要对我的代码片段进行代码优化