def test_cobweb_fit():
    tree = CobwebTree()
    tree2 = CobwebTree()
    examples = [{'a': 'a'}, {'b': 'b'}, {'c': 'c'}]
    tree.fit(examples)
    tree2.fit(examples)
Example #2
0
# Create dictionaries
# Note that the y value is stored as a hidden variable because
# in this case we only want to use the X value to make predictions.
training_data = [{'X': v[0], '_y': y[i]} for i, v in enumerate(X)]
shuffle(training_data)

# Build test data
test_data = [{'X': v[0]} for i, v in enumerate(T)]
#test_data = [{'X': float(v)} for i,v in enumerate(X)]

# Fit cobweb models
cbt = CobwebTree()
cb3t = Cobweb3Tree()

cbt.fit(training_data, iterations=1)
cb3t.fit(training_data, iterations=1)
print(cb3t.root)

child = cb3t.categorize({'X': 4.16})
print(child.predict('X'))
print(child.predict('y'))

curr = child
print(curr)
while curr.parent is not None:
    curr = curr.parent
    print(curr)

# Predict test data
cby = [cbt.categorize(e).predict('_y') for e in test_data]
Example #3
0
# Create dictionaries
# Note that the y value is stored as a hidden variable because
# in this case we only want to use the X value to make predictions.
training_data = [{'X': v[0], '_y': y[i]} for i, v in enumerate(X)]
shuffle(training_data)

# Build test data
test_data = [{'X': v[0]} for i, v in enumerate(T)]
# test_data = [{'X': float(v)} for i,v in enumerate(X)]

# Fit cobweb models
cbt = CobwebTree()
cb3t = Cobweb3Tree()

cbt.fit(training_data, iterations=1)
cb3t.fit(training_data, iterations=1)
print(cb3t.root)

child = cb3t.categorize({'X': 4.16})
print(child.predict('X'))
print(child.predict('y'))

curr = child
print(curr)
while curr.parent is not None:
    curr = curr.parent
    print(curr)

# Predict test data
cby = [cbt.categorize(e).predict('_y') for e in test_data]