Last active
August 29, 2015 14:17
-
-
Save aficionado/d3aaee0db9cab5a74652 to your computer and use it in GitHub Desktop.
Confidence Threshold Evaluation Comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Uses multiple confidence thresholds to evaluate a model. | |
""" | |
############################################################################## | |
# Copyright (c) 2015 BigML, Inc | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining | |
# a copy of this software and associated documentation files (the | |
# "Software"), to deal in the Software without restriction, including | |
# without limitation the rights to use, copy, modify, merge, publish, | |
# distribute, sublicense, and/or sell copies of the Software, and to | |
# permit persons to whom the Software is furnished to do so, subject to | |
# the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be | |
# included in all copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
############################################################################## | |
import sys | |
import argparse | |
from bigml.api import BigML | |
def main(args=sys.argv[1:]): | |
"""Parses command-line parameters and calls the actual main function. | |
""" | |
parser = argparse.ArgumentParser( | |
description="Generates a ROC curve using confidence as threshold", | |
epilog="BigML, Inc") | |
# model | |
parser.add_argument('--model', | |
required=True, | |
action='store', | |
dest='model', | |
help="Classification model") | |
# test set | |
parser.add_argument('--test', | |
required=True, | |
action='store', | |
dest='test', | |
help="Test set") | |
# positive class | |
parser.add_argument('--positive', | |
required=True, | |
action='store', | |
dest='positive', | |
help="Positive class") | |
# negative class | |
parser.add_argument('--negative', | |
required=True, | |
action='store', | |
dest='negative', | |
help="Negative class") | |
args = parser.parse_args(args) | |
api = BigML() | |
thresholds = [confidence/10.0 for confidence in range(11)] | |
evaluations = [] | |
for threshold in thresholds: | |
evaluation = api.create_evaluation(args.model, args.test, { | |
'name': "%s : %s" % (args.positive, threshold), | |
'confidence_threshold': threshold, | |
'positive_class': args.positive, | |
'negative_class': args.negative}) | |
api.ok(evaluation) | |
evaluations.append(evaluation['resource']) | |
evaluation = api.create_evaluation(args.model, args.test, { | |
'name': "%s : %s" % (args.negative, threshold), | |
'confidence_threshold': threshold, | |
'positive_class': args.negative, | |
'negative_class': args.positive}) | |
api.ok(evaluation) | |
evaluations.append(evaluation['resource']) | |
url_param = [evaluation[len('evaluation/'):] for evaluation in evaluations] | |
url_pattern = "labs/evaluationcomp/?evaluations=%s;positive_class=%s" | |
url = url_pattern % (",".join(url_param), args.positive) | |
# Use your VPC or private deployment URL here | |
print "https://bigml.com/" + url | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment