本文整理汇总了Python中Statistics.Statistics.print_prediction_stats方法的典型用法代码示例。如果您正苦于以下问题:Python Statistics.print_prediction_stats方法的具体用法?Python Statistics.print_prediction_stats怎么用?Python Statistics.print_prediction_stats使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statistics.Statistics
的用法示例。
在下文中一共展示了Statistics.print_prediction_stats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphDrawer
# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import print_prediction_stats [as 别名]
#.........这里部分代码省略.........
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:
edge = self.Graph[last_state][succ]
max_weight = edge[Config.WEIGHT]
if float(edge[Config.WEIGHT]) > max_weight:
best_succ[Config.PRED_PROB] = max_weight
best_succ[Config.PRED_ITEMS] = [succ[-1]]
else:
if float(edge[Config.WEIGHT]) == max_weight:
best_succ[Config.PRED_PROB] = max_weight
best_succ[Config.PRED_ITEMS].append(succ[-1])
# print '{0} ---> {1} count[{2}] weight[{3}]'.format(last_state,succ,edge[Config.COUNT], edge[Config.WEIGHT])
is_popularity_prediction = True
else:
best_succ[Config.PRED_PROB] = 0.0
best_succ[Config.PRED_ITEMS].append(self.most_popular_item)
# print 'popularity: last state: {0} best: {1}'.format(last_state, best_succ)
return best_succ, is_popularity_prediction