File tree Expand file tree Collapse file tree 2 files changed +42
-1
lines changed
Expand file tree Collapse file tree 2 files changed +42
-1
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ 【** pyqpanda_alg.QARM文档注释补充** 】
2+
3+ <u >注意:官方算法文档请参考:https://qcloud.originqc.com.cn/document/pyqpanda-algorithm/index.html </u >
4+
5+ 补充原pyqpanda_alg.QARM文档中 “Package Contents” 模块下的 “Examples” 中的注释:
6+
7+ ``` python
8+ # 导入模块
9+ import os
10+ from pyqpanda_alg.QARM import QuantumAssociationRulesMining
11+ from pyqpanda_alg import QARM
12+
13+ # 数据读取
14+ def read (file_path ):
15+ if os.path.exists(file_path):
16+ trans_data = []
17+ with open (file_path, ' r' , encoding = ' utf8' ) as f:
18+ data_line = f.readlines()
19+ if data_line:
20+ for line in data_line:
21+ if line:
22+ data_list = line.strip().split(' ,' )
23+ trans_data.append([data.strip() for data in data_list])
24+ else :
25+ raise ValueError (" The file {} has no any data!" .format(file_path))# 异常处理,若文件为空或无有效行,抛出 ValueError
26+ else :
27+ raise FileNotFoundError (' The file {} does not exists!' .format(file_path))# 异常处理,若文件不存在,抛出 FileNotFoundError
28+ return trans_data
29+
30+
31+ if __name__ == ' __main__' :
32+ data_path = QARM .__path__ [0 ]# 获取 QARM 模块的安装路径,用于定位数据集文件夹。
33+ data_file = os.path.join(data_path, ' dataset/data2.txt' )# 拼接数据文件完整路径。
34+ trans_data = read(data_file)
35+ support = 0.2
36+ conf = 0.5
37+ qarm = QuantumAssociationRulesMining(trans_data, support, conf)# 实例化量子关联规则挖掘类,传入交易数据、支持度和置信度阈值。
38+ result = qarm.run()
39+ print (result)
40+ ```
41+
42+
You can’t perform that action at this time.
0 commit comments