MCPcopy Create free account
hub / github.com/S1mpleyang/ConstructionActionRecognition / plot_roc

Function plot_roc

draw/roc_plot.py:22–73  ·  view source on GitHub ↗
(
        model_name,
        label,
        predict,
        color,
        linestyle=":",
        linewidth=2,
)

Source from the content-addressed store, hash-verified

20"""
21
22def plot_roc(
23 model_name,
24 label,
25 predict,
26 color,
27 linestyle=":",
28 linewidth=2,
29):
30 y_test = torch.load(label)
31 y_test = y_test.numpy().astype(np.int32)
32 try:
33 y_score = torch.load(predict)
34 y_score = y_score.numpy().astype(np.float64)
35 except:
36 y_score = np.load(predict)
37 y_score = y_score[0:, ].astype(np.float64)
38 n_classes = 7
39
40 # 计算每一类的ROC
41 fpr = dict()
42 tpr = dict()
43 roc_auc = dict()
44 for i in range(n_classes):
45 fpr[i], tpr[i], _ = roc_curve(y_test[:, i], y_score[:, i])
46 roc_auc[i] = auc(fpr[i], tpr[i])
47
48 # Compute micro-average ROC curve and ROC area(方法二)
49 fpr["micro"], tpr["micro"], _ = roc_curve(y_test.ravel(), y_score.ravel())
50 roc_auc["micro"] = auc(fpr["micro"], tpr["micro"])
51
52 # Compute macro-average ROC curve and ROC area(方法一)
53 # First aggregate all false positive rates
54 all_fpr = np.unique(np.concatenate([fpr[i] for i in range(n_classes)]))
55 # Then interpolate all ROC curves at this points
56 mean_tpr = np.zeros_like(all_fpr)
57 for i in range(n_classes):
58 mean_tpr += interp(all_fpr, fpr[i], tpr[i])
59 # Finally average it and compute AUC
60 mean_tpr /= n_classes
61 fpr["macro"] = all_fpr
62 tpr["macro"] = mean_tpr
63 roc_auc["macro"] = auc(fpr["macro"], tpr["macro"])
64
65 # Plot all ROC curves
66 lw = 2
67 # plt.plot(fpr["micro"], tpr["micro"],
68 # label='micro-average ROC curve of SwimTransformer(area = {0:0.2f})'
69 # ''.format(roc_auc["micro"]),
70 # color='red', linestyle='-', linewidth=2)
71 plt.plot(fpr["macro"], tpr["macro"],
72 label='{0} (AUC = {1:.3f})'.format(model_name, roc_auc["macro"]),
73 color=color, linestyle=linestyle, linewidth=linewidth)
74
75
76##ours

Callers 1

roc_plot.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected