示例#1
0
    {'x1': 0, 'x2': 0, 'x3': 0},
    {'x1': 1, 'x2': 1, 'x3': 1},
    {'x1': 0, 'x2': 0, 'x3': 0}
]

columns = ['x1','x2','x3']

print 'Expect about .005555'
print g(test_records,'x3',['x2'])
print '\n'

print 'Expect about .001111'
print g(test_records,'x2',['x1'])
print '\n'

print 'Expect about .0003607'
print g(test_records,'x1')
print '\n'

print 'Checking k2 with order x1,x2,x3'
print k2(test_records,3,list(columns))
print '\n'

print 'Testing find all combinations'
print find_all_parent_val_combinations(len(columns),[0,1])
print '\n'

print 'Testing probability table construction'
print get_count_table(test_records,'x3',['x2'])
print '\n'
示例#2
0
for i in range(k):
    cf_lookup = {1: 'positive', 0: 'negative'}
    confustion_matrix = {'positive': {'positive': 0, 'negative': 0}, 'negative': {'positive': 0, 'negative': 0}}

    test_start_index,test_end_index = i*subset_size, i*subset_size + subset_size
    test_set = [bootstrapped_data[j] for j in range(test_start_index,test_end_index)]
    head_indices = [j for j in range(0,test_start_index)]
    tail_indices = [j for j in range(test_end_index,len(bootstrapped_data)-1)]
    train_set = [bootstrapped_data[j] for j in head_indices + tail_indices]

    if try_random_orderings:
        all_perms = list(permutations(classification_dims))
        shuffle(all_perms)
        network = get_best_network(train_set,3,all_perms[:num_k2_random_orderings])
    else:
        network = k2(train_set,5,classification_dims)[0]

    for node in network:
        print 'Node %s has parents %s' %(node,str(network[node]))
    correct = 0
    total = 0
    for record in test_set:
        class_probs = {}
        for class_value in target_class_values:
            class_prob = find_class_prob(record,train_set,network,'Class',class_value,classification_dims)
            class_probs[class_value] = class_prob
        guess = max(class_probs.iteritems(),key=itemgetter(1))[0]
        total += 1
        actual = record['Class']
        if guess == actual:
            correct += 1