Ejemplo n.º 1
0
def MLEM2_OnlyK_Identified(FILENAME, iter1, iter2, k, p):

    # rule induction
    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules/' + 'rules_' + str(
        iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename) else mlem2.getRulesByMLEM2(FILENAME, iter1, iter2)

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # only-k rule filter
    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules_onlyK/' + 'rules-' + str(
        k) + '_' + str(iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename) else [r for r in rules if len(r.getSupport()) >= k]

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # PerIdentifiedClass を求める
    ans = mlem2.getPerIdentifiedClass(rules, p)

    # save
    savepath = DIR_UCI + '/' + FILENAME + '/Identify_MLEM2_OnlyK.csv'
    with open(savepath, "a") as f:
        f.writelines(
            'Identify_MLEM2_OnlyK,{k},{p},{FILENAME},{iter1},{iter2},{ans}'.
            format(
                FILENAME=FILENAME, k=k, p=p, iter1=iter1, iter2=iter2,
                ans=ans) + "\n")

    return (ans)
Ejemplo n.º 2
0
def MLEM2_RuleClusteringByConsistentSim_Identified(FILENAME, iter1, iter2, k,
                                                   p):

    # rule induction
    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules/' + 'rules_' + str(
        iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename) else mlem2.getRulesByMLEM2(FILENAME, iter1, iter2)

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # rule clustering
    filepath = DIR_UCI + '/' + FILENAME + '/' + FILENAME + '-train' + str(
        iter1) + '-' + str(iter2) + '.tsv'
    decision_table = mlem2.getDecisionTable(filepath)
    colnames = mlem2.getColNames(decision_table)

    filepath = DIR_UCI + '/' + FILENAME + '/' + FILENAME + '.nominal'
    list_nominal = mlem2.getNominalList(filepath)
    list_judgeNominal = mlem2.getJudgeNominal(decision_table, list_nominal)

    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules_cluster_consistent_sim/' + 'rules-' + str(
        k) + '_' + str(iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename
    ) else clustering.getRuleClusteringByConsistentSimilarity(
        rules, colnames, list_judgeNominal, k=k)

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # PerIdentifiedClass を求める
    ans = mlem2.getPerIdentifiedClass(rules, p)

    # save
    savepath = DIR_UCI + '/' + FILENAME + '/Identify_MLEM2_RuleClusteringByConsistentSim.csv'
    with open(savepath, "a") as f:
        f.writelines(
            'Identify_MLEM2_RuleClusteringByConsistentSim,{k},{p},{FILENAME},{iter1},{iter2},{ans}'
            .format(
                FILENAME=FILENAME, k=k, p=p, iter1=iter1, iter2=iter2,
                ans=ans) + "\n")

    return (ans)
Ejemplo n.º 3
0
def MLEM2_RuleClusteringBySameCondition_Identified(FILENAME, iter1, iter2, k,
                                                   p):

    # rule induction
    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules/' + 'rules_' + str(
        iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename) else mlem2.getRulesByMLEM2(FILENAME, iter1, iter2)

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # rule clustering
    fullpath_filename = DIR_UCI + '/' + FILENAME + '/rules_cluster_same_condition/' + 'rules-' + str(
        k) + '_' + str(iter1) + '-' + str(iter2) + '.pkl'
    rules = mlem2.loadPickleRules(fullpath_filename) if os.path.isfile(
        fullpath_filename) else clustering.getRuleClusteringBySameCondition(
            rules, k=k)

    # rule save
    if not os.path.isfile(fullpath_filename):
        mlem2.savePickleRules(rules, fullpath_filename)

    # PerIdentifiedClass を求める
    ans = mlem2.getPerIdentifiedClass(rules, p)

    # save
    savepath = DIR_UCI + '/' + FILENAME + '/Identify_MLEM2_SameCondition.csv'
    with open(savepath, "a") as f:
        f.writelines(
            'Identify_MLEM2_SameCondition,{k},{p},{FILENAME},{iter1},{iter2},{ans}'
            .format(
                FILENAME=FILENAME, k=k, p=p, iter1=iter1, iter2=iter2,
                ans=ans) + "\n")

    return (ans)