Пример #1
0
def infox(table, col, res_col):
    """
    informacja atrybutu
    """
    s = 0 # sum
    for subt in table_helpers.get_subtables(table, col):
        s += (float(len(subt[col])) / len(table[col])) * info(subt, res_col)
    return s
Пример #2
0
def main_c45(table, result):
    """
    zwraca drzewo tree z wynikiem algorytmu C4.5 w postaci listy lis
    przyjmuje słownik table i klucz to vartości z wynikiem result
    """
    refactor_table_numbers(table)
    col = max([(k, gain(table, k, result)) for k in table.keys() if k != result],
              key=lambda x: x[1])[0]
    tree = []
    for subt in get_subtables(table, col):
        v = subt[col][0]
        if is_mono(subt[result]):
            tree.append(['%s=%s' % (col, v),
                         '%s=%s' % (result, subt[result][0])])
        else:
            del subt[col]
            tree.append(['%s=%s' % (col, v)] + main_c45(subt, result))
    return tree