本文整理汇总了Python中Statistics.Statistics.incorrect_prediction方法的典型用法代码示例。如果您正苦于以下问题:Python Statistics.incorrect_prediction方法的具体用法?Python Statistics.incorrect_prediction怎么用?Python Statistics.incorrect_prediction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statistics.Statistics
的用法示例。
在下文中一共展示了Statistics.incorrect_prediction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphDrawer
# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import incorrect_prediction [as 别名]
#.........这里部分代码省略.........
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:
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