apriori片段代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了apriori片段代码相关的知识,希望对你有一定的参考价值。
def data_probytime(data): timemark = ‘‘ for i in range(len(data)): lis = [] a = data[i][0] if timemark == a: continue else: timemark = a for j in range(i, len(data)): b = data[j][0] (time1, time2) = judge_time(a, b) days = timedelta(days=0) if time2 - time1 <= days: for item in data[i][1:]: if item not in lis: lis.append(item) for item2 in data[j][1:]: if item2 not in lis: lis.append(item2) else: for item3 in data[i][1:]: if item3 not in lis: lis.append(item3) yield lis
def data_probytime(data):
timemark =
‘‘
for
i
inrange(len(data)):
lis = []
a = data[i][
0]
if
timemark == a:
continue
else
:
timemark = a
for
j
inrange(i, len(data)):
b = data[j][
0]
(time1, time2) = judge_time(a, b)
days = timedelta(days=
0)
if
time2 - time1 <= days:
for
item
indata[i][
1:]:
if
item
notin
lis:
lis.append(item)
for
item2
indata[j][
1:]:
if
item2
notin
lis:
lis.append(item2)
else
:
for
item3
indata[i][
1:]:
if
item3
notin
lis:
lis.append(item3)
yield
lis
1 <?xml version="1.0" encoding="utf-8"?> 2 <KNOWNLADGESYSTEM> name="设备风险知识系统"> 3 <FKU name=‘设备风险知识系统‘hastarget=‘false‘> 4 <FKU name=‘隐患类别‘hastarget=‘true‘> 5 <FKU name=‘线路‘hastarget=‘truee‘> 6 <TARGETRES risk_factor="道岔"></TARGETRES> 7 </FKU> 8 <TARGETRES risk_factor="不良"></TARGETRES> 9 <TARGETRES risk_factor="报警"></TARGETRES> 10 <TARGETRES risk_factor="折断"></TARGETRES> 11 </FKU> 12 </FKU> 13 ... 14 15 <SKULIST> 16 <SKU name=‘隐患类别‘ resulttype unit=‘设备‘> 17 <VARLIST> 18 <VAR name=‘隐患定位‘type=‘SKU‘/> 19 <VAR name=‘隐患描述‘type=‘SKU‘> 20 <VALUE>道岔</<VALUE> 21 <VALUE>螺栓</<VALUE> 22 </VAR> 23 </VARLIST> 24 <BODY> 25 <RVALUE>发生概率:”螺栓”问题*0.9</RVALUE> 26 <SENTENCE type=‘rule‘> 27 <IF> 28 <PREM varname=‘道岔‘ rel="=="opval="松动"/> 29 </IF> 30 <THEN> 31 <SENTENCE type=‘exp‘> 32 <LVALUE>事故发生</LVALUE> 33 <RVALUE>p*0.9</RVALUE> 34 </SENTENCE> 35 </THEN> 36 </SENTENCE> 37 </BODY> 38 </SKU> 39 </SKULIST> 40 </KNOWNLADGESYSTEM>
以上是关于apriori片段代码的主要内容,如果未能解决你的问题,请参考以下文章