Apriori关联规则挖掘 - 属性错误

时间:2016-07-14 10:13:30

标签: python associations attributeerror apriori

我想在Python上找到apriori的关联规则。我有一个文本数据(解释)。在我的main函数中,我指出我的单词集是每行的列表列表,union列表是文本文档中所有单词的列表。然后,我为apriori创建了一个Counter矩阵。然后,我将此矩阵转换为数据框以便给出标签。然后我想应用apriori函数,但我采取属性错误:'list'对象没有属性'split'

我的逻辑是否正确?有没有人可以帮我解决错误。

数据样本:

explanation:
[ 'ustu yuklenmis bilgilerinize olan problem yemek ederim', 'secenek ve arz fazla kofte ederim yapip yuklenen']


word_set: 
 ['ustu', 'yuklenmis', 'bilgilerinize', 'olan', 'problem', 'yemek', 'ederim'], ['secenek', 've', 'arz', 'fazla', 'kofte', 'ederim', 'yapip', 'yuklenen']

union_list:
 ['ustu', 'yuklenmis', 'bilgilerinize', 'olan', 'problem', 'yemek', 'ederim','secenek', 've', 'arz', 'fazla', 'kofte', 'ederim', 'yapip', 'yuklenen']

代码:

def transformation_matrix(transactions, support=None): 
    word_set, union_list

    matrix = []
    for item in range(0, len(word_set)):
        count = Counter(word_set[item])
        mat = [count[x] for x in union_list]
        matrix.append(mat)
    return matrix


def data_frame(transactions, support=None):

    matrix = transformation_matrix(transactions, support=None)
    frame_matrix = pd.DataFrame(matrix)
    return frame_matrix


def apriori(transactions, support=None):

    frame_matrix = data_frame(transactions, support=None)
    rules = apriori(frame_matrix, 10)
    return rules


if __name__ == '__main__':

    word_set = []
    for item in explanation:

       splitted = item.split()
       myset = list(set(splitted))
       word_set.append(myset)

    union_list = list(itertools.chain(*word_set))


    print transformation_matrix(explanation[1:30], support=None)
    print data_frame(explanation[1:30], support=None)
    print apriori(explanation[1:30], support=None)

0 个答案:

没有答案