{"id":16654211,"url":"https://github.com/letmefly666/apriori","last_synced_at":"2026-04-22T11:36:16.220Z","repository":{"id":107869939,"uuid":"470626537","full_name":"LetMeFly666/Apriori","owner":"LetMeFly666","description":"Apriori算法实现关联规则的数据挖掘","archived":false,"fork":false,"pushed_at":"2023-04-16T13:14:07.000Z","size":1650,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-29T08:21:23.749Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://apriori.letmefly.xyz","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LetMeFly666.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-16T14:48:13.000Z","updated_at":"2022-09-29T13:08:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"c8269ba9-e883-4c64-866f-1194ea2ba460","html_url":"https://github.com/LetMeFly666/Apriori","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/LetMeFly666/Apriori","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FApriori","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FApriori/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FApriori/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FApriori/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LetMeFly666","download_url":"https://codeload.github.com/LetMeFly666/Apriori/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LetMeFly666%2FApriori/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32134785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T08:34:57.708Z","status":"ssl_error","status_checked_at":"2026-04-22T08:34:55.583Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T09:49:02.987Z","updated_at":"2026-04-22T11:36:11.213Z","avatar_url":"https://github.com/LetMeFly666.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003c!--\n * @Author: LetMeFly\n * @Date: 2022-03-16 22:50:20\n * @LastEditors: LetMeFly\n * @LastEditTime: 2022-04-16 19:54:07\n--\u003e\n# Apriori算法实现关联规则的数据挖掘\n\n## 前言\n\nApriori算法实现关联规则的数据挖掘\n\n+ 在线文档 [https://apriori.letmefly.xyz](https://apriori.letmefly.xyz)\n\n+ 项目地址 [https://github.com/LetMeFly666/apriori](https://github.com/LetMeFly666/apriori)\n\n+ See [FP-growth(https://github.com/LetMeFly666/FP-growth)](https://github.com/LetMeFly666/FP-growth) For More\n\n\n## 实现目标\n\n目标只有一个，就是对于一个给定的置信度，用**尽可能少的时间**求出\u003ccode\u003eSource/retail.dat\u003c/code\u003e的所有关联规则\n\n也就是说，此算法将会尽可能多地采用空间换时间、多线程等方法，在8G内存、i5处理器的电脑上计算出结果。\n\n### 数据分析\n\n这个数据共有\u003ccode\u003e88162\u003c/code\u003e行(消费记录)，总共有\u003ccode\u003e16470\u003c/code\u003e种产品。\n\n#### 数据存储方式\n\n##### 方法一\n\n每条消费记录存入一个vector中，```vector\u003cuint16_t\u003e items[88162]```\n\n每个vector中记录都有哪些商品。\n\n###### 存储方式示例\n\nData:\n\n```\n1 2 5\n3 4 5\n4\n```\n\nStorage:\n\n```cpp\nvector\u003cuint16_t\u003e itmes[3] = {\n    {1, 2, 5},\n    {3, 4, 5},\n    {4}\n};\n```\n\n###### 空间使用\n\n有多少数据大约就会使用多少空间(不是很清楚vector具体是怎么动态扩容的)\n\n经过统计共有908576个数据，需要约1e6*2Byte≈2M的内存空间\n\n##### 方法二\n\n每件商品存入一个vector中，```vector\u003cint\u003e itmes```\u003csmall\u003e(2^16=65536\u003c88162，不可用uint16_t，这里先不考虑数据压缩)\u003c/small\u003e\n\n每个vector记录这个商品出现在哪些消费记录中。\n\n###### 存储方式示例\n\nData:\n\n```\n1 2 5\n3 4 5\n4\n```\n\nStorage:\n\n```cpp\nvector\u003cint\u003e itmes[5] = {\n    {0},\n    {0},\n    {1},\n    {1, 2},\n    {0, 1}\n};\n```\n\n###### 空间使用\n\n类似方法一，共需要约1e6*4Byte≈4M的内存空间\n\n\n##### 方法三\n\n类似方法二，每件商品用一个bitset来存储。```bitset\u003c908576\u003e items[16470]```\n\nbitset的第i位代表这件商品是否出现在第i条消费记录中。\n\n###### 存储方式示例\n\nData:\n\n```\n1 2 5\n3 4 5\n4\n```\n\nStorage:\n\n```cpp\nbitset\u003c3\u003e items[5] = {\n    0b001,\n    0b001,\n    0b010,\n    0b110,\n    0b011\n};\n```\n\n###### 空间使用\n\n共有16470种商品，共有908576条记录，因此共需要空间16470*908576bit=1870530840Byte=1783.87722015380859375M=1.742067597806453704833984375G≈1.75G的内存空间。\n\n\n##### 方法四\n\n\u003cdel\u003e每条消费记录建立一个Trie树，树上插入这个消费记录的每个商品。\u003c/del\u003e每条消费记录建立一个\u003cdel\u003eset\u003c/del\u003eunordered_set```unordered_set\u003cuint16_t\u003e items[88162]```，这样查询一个商品是否在某个记录中就比较快。\n\n###### 存储方式示例\n\n不便展示\n\n###### 空间使用\n\n空间复杂度O(∑商品数)，只是常数比较大\n\n### 算法原理\n\nLn是所有的 商品个数为n的、支持度≥给定支持度的商品集 的集合\n\n对于一个确定的n，要判同时包含某n件商品的消费记录的条数，以此来确定是否能够满足给定支持度。\n\nLn是由Ln-1得到的。假设n=3，ab、ac∈Ln-1，由Ln-1得到Ln的时候，由ab和ac就可以组成abc(长度为3)。\n\n如果bc∉Ln-1，那么就直接排除abc。（其中bc是abc的一个长度为n-1的子集。这么剪枝要找到所有abc中长度为2的子集，复杂度为O(n)）\n\n#### 主要瓶颈\n\n1. 统计abc的出现次数\n\n2. 找C中前缀全部相同的项（abc + abd -\u003e abcd）\n\n\n## 后记\n\n算法已经实现，暂未优化。主要就是L1-\u003eL2比较慢。假如使用数据\u003ccode\u003eSource\\retail.dat\u003c/code\u003e且令最小支持度为2%，那么L1就有20个元素。\n\n一共88162条记录，88162*(20*19/2)=16,750,780，set.count再加个log(N)，应该是执行了最少1e8的运算。\n\n| 支持度 | 耗时 | 结果 |\n| :--: | :--: | :--: |\n| 5% | 0.333s | 20 + 22 + 12 + 1 = 55 |\n| 1% | 35.729s | 70 + 58 + 25 + 6 = 159 |\n| 0.8% | 75.483s | 101 + 98 + 38 + 6 = 243 |\n| 0.5% | 360.879s | 221 + 237 + 102 + 19 + 1 = 580 |\n\n## 不同的方法实现\n\n| 描述                                             | 方案一 | 方案二          |\n| ------------------------------------------------ | ------ | --------------- |\n| 方案四中，每条消费记录用set还是unordered_set来存 | set ❌  | unordered_set ✔ |\n\n\n## Release\n\n\u003cdetails\u003e\n\u003csummary\u003ev0.0.1-Bugx86版\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-x64-Debug.exe\"\u003eApriori-v0.0.1-x64-Debug.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-x64-Release.exe\"\u003eApriori-v0.0.1-x64-Release.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-x86-Debug.exe\"\u003eApriori-v0.0.1-x86-Debug.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-x86-Release.exe\"\u003eApriori-v0.0.1-x86-Release.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-Codes.rar\"\u003eApriori-v0.0.1-Codes.rar\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.1/Apriori-v0.0.1-Codes.zip\"\u003eApriori-v0.0.1-Codes.zip\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.0.1.zip\"\u003eSource code (zip)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.0.1.tar.gz\"\u003eSource code (tar.gz)\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ev0.0.2-Bugx86版\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-x64-Debug.exe\"\u003eApriori-v0.0.2-x64-Debug.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-x64-Release.exe\"\u003eApriori-v0.0.2-x64-Release.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-x86-Debug.exe\"\u003eApriori-v0.0.2-x86-Debug.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-x86-Release.exe\"\u003eApriori-v0.0.2-x86-Release.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-Codes.rar\"\u003eApriori-v0.0.2-Codes.rar\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.0.2/Apriori-v0.0.2-Codes.zip\"\u003eApriori-v0.0.2-Codes.zip\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.0.2.zip\"\u003eSource code (zip)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.0.2.tar.gz\"\u003eSource code (tar.gz)\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003ev0.1.0\u003c/summary\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/releases/download/v0.1.0/Apriori-v0.1.0-x64-Release.exe\"\u003eApriori-v0.1.0-x64-Release.exe\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.1.0.zip\"\u003eSource code (zip)\u003c/a\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"https://github.com/LetMeFly666/Apriori/archive/refs/tags/v0.1.0.tar.gz\"\u003eSource code (tar.gz)\u003c/a\u003e\u003c/li\u003e\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmefly666%2Fapriori","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletmefly666%2Fapriori","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletmefly666%2Fapriori/lists"}