def detectpattern(path,savepath,min_supp=0.05): ff=open(savepath,'w') S=u.read(path) count = 0 for each in S: count += 1 patterns = prefixSpan(SquencePattern([], sys.maxint), S, min_supp * count) #print_patterns(patterns) seqNums = [] for each in patterns: seqNums.append(each.squence) maxSeqs = u.maxSeq(seqNums) for i in maxSeqs: for sth in i: #print >> ff,"[", for ssth in sth: print >> ff,ssth, #print >> ff,"]", print >> ff,"" ff.close()
print >> ff, ("pattern:{0}, support:{1}".format(name, p.support)) if __name__ == "__main__": ff = open("datas/result.txt", "w") S = u.read("datas/gxyseq.csv") min_supp = 0.01 count = 0 for each in S: count += 1 patterns = prefixSpan(SquencePattern([], sys.maxint), S, min_supp * count) print_patterns(patterns) seqNums = [] for each in patterns: seqNums.append(each.squence) maxSeqs = u.maxSeq(seqNums) print ("The sequential patterns :") for i in maxSeqs: for sth in i: print "[", for ssth in sth: print ssth, print "]", print "" print >> ff, "The sequential patterns :" for i in maxSeqs: for sth in i: print >> ff, "[", for ssth in sth: print >> ff, ssth, print >> ff, "]",
if __name__ == "__main__": ff = open('datas/result.txt','w') #S = u.read("datas/gxyseq.csv") S=u.read("PrefixSpan.txt") min_supp=0.05 count = 0 for each in S: count += 1 patterns = prefixSpan(SquencePattern([], sys.maxint), S, min_supp * count) print_patterns(patterns) seqNums = [] for each in patterns: seqNums.append(each.squence) maxSeqs = u.maxSeq(seqNums) print("The sequential patterns :") for i in maxSeqs: for sth in i: print "[", for ssth in sth: print ssth, print "]", print "" print >> ff,"The sequential patterns :" for i in maxSeqs: for sth in i: print >> ff,"[", for ssth in sth: print >> ff,ssth, print >> ff,"]",