Last active
December 15, 2015 13:39
-
-
Save aficionado/5269230 to your computer and use it in GitHub Desktop.
Plot Support vs Confidence for BigML promotional sources
This file contains 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
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