Exemple #1
0
def test_filter_rows():
    data = filter_rows(weather_data, lambda r: value(weather_data, r, 'play'))
    assert relation(data) == 'weather.symbolic'
    assert attributes(data) == [
        'outlook', 'temperature', 'humidity', 'windy', 'play'
    ]
    assert rows(data)[0] == ['overcast', 'hot', 'high', False, True]
Exemple #2
0
def get_best_attribute(data, class_attr):
    attrs = list(filter(lambda a: a != class_attr, attributes(data)))
    print(f' ---\nDetermining best attribute from: {", ".join(attrs)}')
    lowest_attr = attrs[0]
    lowest_info = 1
    for attr in attrs:
        print_info_calc(data, class_attr, attr)
        info = attr_info(data, class_attr, attr)
        if info < lowest_info:
            lowest_attr = attr
            lowest_info = info
    print(f'Lowest info attribute is: {lowest_attr}')
    return (lowest_attr, lowest_info)
Exemple #3
0
def test_attributes():
    assert attributes(weather_data) == [
        'outlook', 'temperature', 'humidity', 'windy', 'play'
    ]
Exemple #4
0
def test_remove_attribute():
    data = remove_attribute(weather_data, 'outlook')
    assert relation(data) == 'weather.symbolic'
    assert attributes(data) == ['temperature', 'humidity', 'windy', 'play']
    assert rows(data)[0] == ['hot', 'high', False, False]
    assert rows(data)[7] == ['mild', 'high', False, False]
Exemple #5
0
from P458.data import (
    attributes,
    read_arff,
)
from P458.id3 import (
    id3, )
from P458.tree import (
    str_tree,
    decide,
)

data = read_arff('./data/contact-lenses.arff')
decision_tree = id3(data, 'contact-lenses')
row = ['sunny', 'hot', 'high', False, False]
result = decide(decision_tree, row, attributes(data))
print(' --- ')
print(str_tree(decision_tree))
print(f'For row: {row} id3 predicts: {result}')