当前位置: 首页>>代码示例>>Python>>正文


Python Statistics.correct_prediction方法代码示例

本文整理汇总了Python中Statistics.Statistics.correct_prediction方法的典型用法代码示例。如果您正苦于以下问题:Python Statistics.correct_prediction方法的具体用法?Python Statistics.correct_prediction怎么用?Python Statistics.correct_prediction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Statistics.Statistics的用法示例。


在下文中一共展示了Statistics.correct_prediction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GraphDrawer

# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import correct_prediction [as 别名]

#.........这里部分代码省略.........
            # print sum
            # print 'curr:  ' + str(curr_node)
            for s in node_successors:
                count = self.Graph[curr_node][s][Config.COUNT]
                self.Graph[curr_node][s][Config.WEIGHT] = float(count) / float(sum)
                # print 'succ:   ' + str(s) + ' ' + str(self.Graph[curr_node][s])

    def predict(self,testset):
        """
        :param testset: a map - 'itemIP' --> list<Purchase>

        the main idea is:
            1. for each session
                1.1 hide the last item purchased
                1.2 predict the last item using the model
                1.3 save the
        """
        y_true = []
        y_pred = []
        y_score = []

        for key in testset.keys():
            sequence = testset[key]
            seq_length = len(sequence)
            if seq_length > 1:
                actual = sequence[-1].itemID
                prediction, is_popularity_prediction = self.__predict_sequence__(sequence[:-1])

                if prediction != None and is_popularity_prediction:
                    y_true.append(1)
                    if actual in prediction[Config.PRED_ITEMS]:
                        y_pred.append(1)
                        y_score.append(prediction[Config.PRED_PROB]) #distanse 0
                        self.stats.correct_prediction()
                    else:
                        y_score.append(0)
                        y_pred.append(0)
                        self.stats.incorrect_prediction()
                    # print '**************'
                    # raw_seq = [x.itemID for x in sequence]
                    # print raw_seq
                    # print 'prediction[{0}]  actual[{1}]  success[{2}]'.format(prediction[Config.PRED_ITEMS], actual, actual in prediction[Config.PRED_ITEMS])
                    # print '----------------------'
                    # print ' '
        return y_true,y_score, y_pred

    def roc(self,y_true, y_score):
        self.stats.draw_ROC_curve(y_true,y_score)



    def print_prediction_stats(self,y_true, y_score,y_pred):
        self.stats.print_prediction_stats(y_true, y_score,y_pred)

    def __predict_sequence__(self,sequence):
        states = self.extract_states(sequence)
        last_state = states[-1]
        best_succ = dict()
        best_succ[Config.PRED_PROB] = 0.0
        best_succ[Config.PRED_ITEMS] = []

        is_popularity_prediction = False
        if self.Graph.__contains__(last_state):
            successors = self.Graph.successors(last_state)
            max_weight = 0.0
            for succ in successors:
开发者ID:galdreiman,项目名称:Sequential-Based-RecommenderSystem,代码行数:70,代码来源:GraphDrawer.py


注:本文中的Statistics.Statistics.correct_prediction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。