码迷,mamicode.com
首页 > 其他好文 > 详细

apriori片段代码

时间:2016-11-28 23:13:47      阅读:252      评论:0      收藏:0      [点我收藏+]

标签:cat   close   als   item   设备   end   out   tar   ...   

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 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


技术分享
 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>
View Code

 

 

apriori片段代码

标签:cat   close   als   item   设备   end   out   tar   ...   

原文地址:http://www.cnblogs.com/xinge23/p/6111412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!