Created
April 19, 2012 17:43
-
-
Save beaucronin/2422554 to your computer and use it in GitHub Desktop.
Learning noisy-XOR with Veritable
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
# generate some noisy-XOR data | |
from random import random | |
N = 1000 | |
noise = 0.1 | |
data = [] | |
for _ in range(N): | |
x1 = random() < 0.5 | |
x2 = random() < 0.5 | |
keep = random() > noise | |
y = x1 != x2 if keep else x1 == x2 | |
data.append({ 'x1': x1, 'x2': x2, 'y': y }) |
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
# NOTE: assumes that generate.py has been run, and that an appropriate | |
# data variable is defined | |
import veritable | |
from veritable.utils import clean_data | |
schema = { | |
'x1': {'type': 'boolean'}, | |
'x2': {'type': 'boolean'}, | |
'y': {'type': 'boolean'} | |
} | |
clean_data(data, schema, assign_ids=True) | |
api = veritable.connect() | |
table = api.create_table('noisy_XOR', force=True) | |
table.batch_upload_rows(data) | |
analysis = table.create_analysis(schema) | |
analysis.wait() | |
pr1 = analysis.predict({'x1': False, 'x2': False, 'y': None}) | |
pr1.credible_values('y', p=.05) | |
# => {False: 0.82, True: 0.18} | |
pr2 = analysis.predict({'x1': True, 'x2': False, 'y': None}) | |
pr2.credible_values('y', p=.05) | |
# => {False: 0.12, True: 0.88} | |
pr3 = analysis.predict({'x1': False, 'x2': True, 'y': None}) | |
pr3.credible_values('y', p=.05) | |
# => {False: 0.19, True: 0.81} | |
pr4 = analysis.predict({'x1': True, 'x2': True, 'y': None}) | |
pr4.credible_values('y', p=.05) | |
# => {False: 0.93, True: 0.07} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment