def TestClassifierThreshold(classifier, labelled_data): """Returns a sorted list by the threshold (threshold, (label, guess)).""" roc = [] for (label, sample) in labelled_data: (threshold, guess) = classifier.ClassifyThreshold(sample) roc.append((threshold, (label, guess))) roc = sorted(roc, reverse=True) tf_roc = [label == guess for (t, (label, guess)) in roc] graph.roc(tf_roc) return roc
def TestClassifierThreshold(classifier, labelled_data): """Returns a sorted list by the threshold (threshold, (label, guess)).""" roc = [] for (label, sample) in labelled_data: (threshold, guess) = classifier.ClassifyThreshold(sample) roc.append((threshold, (label, guess))) roc = sorted(roc, reverse=True) tf_roc = [label == guess for (t,(label,guess)) in roc] graph.roc(tf_roc) return roc
def plot_roc(threshold, samples, known_labels = known_labels, title=''): def ThresholdAndLabel(sample): label, sample = dataset.ExtractLabel(sample) return threshold(sample), label roc_curve = [] #for threshold, label in sorted(map(ThresholdAndLabel, samples), key = lambda x: x[0], reverse=True): for threshold, label in sorted(map(ThresholdAndLabel, samples), key = lambda x: x, reverse=True): roc_curve.append( label in known_labels ) graph.roc(roc_curve, label = title) pass
def p_roc(threshold, title, style, samples = test_samples, known_labels = KNOWN_LABELS): def ThresholdAndLabel(sample): label, sample = dataset.ExtractLabel(sample) return threshold(sample), label ct = collections.defaultdict(lambda: [0, 0]) for threshold, label in map(ThresholdAndLabel, samples): ct[threshold][label in KNOWN_LABELS] += 1 roc_curve = [] for threshold, score in sorted(ct.items(), key = lambda x: x[0], reverse=True): roc_curve.append(tuple(score)) graph.roc(roc_curve, style, label = title)
def plot_roc(threshold, samples, known_labels=known_labels, title=''): def ThresholdAndLabel(sample): label, sample = dataset.ExtractLabel(sample) return threshold(sample), label roc_curve = [] #for threshold, label in sorted(map(ThresholdAndLabel, samples), key = lambda x: x[0], reverse=True): for threshold, label in sorted(map(ThresholdAndLabel, samples), key=lambda x: x, reverse=True): roc_curve.append(label in known_labels) graph.roc(roc_curve, label=title) pass
def p_roc(threshold, title, style, samples=test_samples, known_labels=KNOWN_LABELS): def ThresholdAndLabel(sample): label, sample = dataset.ExtractLabel(sample) return threshold(sample), label ct = collections.defaultdict(lambda: [0, 0]) for threshold, label in map(ThresholdAndLabel, samples): ct[threshold][label in KNOWN_LABELS] += 1 roc_curve = [] for threshold, score in sorted(ct.items(), key=lambda x: x[0], reverse=True): roc_curve.append(tuple(score)) graph.roc(roc_curve, style, label=title)
roc_curve = [] for threshold, score in sorted(ct.items(), key=lambda x: x[0], reverse=True): roc_curve.append(tuple(score)) print roc_curve[0:10] return roc_curve for output, nfeatures in [('synthetic-all.pdf', [5, 10, 15, 20, 35, 50]), ('synthetic-3features.pdf', [3]), ('synthetic-5features.pdf', [5]), ('synthetic-10features.pdf', [10]), ('synthetic-50features.pdf', [50])]: print "Generating ", output test_samples = list( generate_samples(classes=ALL_CLASSES, samples=5000, labelled=True, nfeatures=nfeatures)) R1 = roc_performance(exact_novelty_detector, test_samples, KNOWN_CLASSES) R2 = roc_performance(uniform_novelty_detector, test_samples, KNOWN_CLASSES) R3 = roc_performance(independent_novelty_detector, test_samples, KNOWN_CLASSES) graph.newfig() graph.roc(data=R1, style='g^-', label='exact') graph.roc(data=R2, style='b*-', label='uniform') graph.roc(data=R3, style='ro-', label='independent') graph.savefig(output)
ct[threshold][label in known_labels] += 1 roc_curve = [] for threshold, score in sorted(ct.items(), key = lambda x: x[0], reverse=True): roc_curve.append(tuple(score)) print roc_curve[0:10] return roc_curve for output, nfeatures in [('synthetic-all.pdf', [5, 10, 15, 20, 35, 50]), ('synthetic-3features.pdf', [3]), ('synthetic-5features.pdf', [5]), ('synthetic-10features.pdf', [10]), ('synthetic-50features.pdf', [50])]: print "Generating ", output test_samples = list(generate_samples(classes = ALL_CLASSES, samples = 5000, labelled = True, nfeatures = nfeatures)) R1 = roc_performance(exact_novelty_detector, test_samples, KNOWN_CLASSES) R2 = roc_performance(uniform_novelty_detector, test_samples, KNOWN_CLASSES) R3 = roc_performance(independent_novelty_detector, test_samples, KNOWN_CLASSES) graph.newfig() graph.roc(data = R1, style = 'g^-', label = 'exact') graph.roc(data = R2, style = 'b*-', label = 'uniform') graph.roc(data = R3, style = 'ro-', label = 'independent') graph.savefig(output)