Skip to content

Instantly share code, notes, and snippets.

@aficionado
Last active December 15, 2015 13:39
Show Gist options
  • Save aficionado/5269230 to your computer and use it in GitHub Desktop.
Save aficionado/5269230 to your computer and use it in GitHub Desktop.
Plot Support vs Confidence for BigML promotional sources
from bigml.api import BigML
from bigml.model import Model
api = BigML()
def support_vs_confidence(model_id):
model = api.get_model(model_id)
local_model = Model(model)
leaves = local_model.get_leaves()
outputs = unique([leaf['output'] for leaf in leaves])
colors = linspace(0, 1, len(outputs))
colordict = dict(zip(outputs, colors))
total_count = float(reduce(lambda x,y: x+y, [leaf['count'] for leaf in leaves]))
support = [leaf['count']/total_count for leaf in leaves]
confidence = [leaf['confidence'] for leaf in leaves]
output = [colordict[leaf['output']] for leaf in leaves]
scatter(support, confidence, c=output)
title(model['object']['name'])
xlabel("support")
ylabel("confidence")
figure()
subplot(221)
support_vs_confidence('model/51553a43035d0731c3000143')
subplot(222)
support_vs_confidence('model/51553a48035d0731be00017c')
subplot(223)
support_vs_confidence('model/51553a4d0c0b5e04c4000150')
subplot(224)
support_vs_confidence('model/51553a520c0b5e04c5000278')
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment