数据挖掘算法之-关联规则挖掘(AssociationRule)(购物篮分析)
在各种数据挖掘算法中,关联规则挖掘算是比较重要的一种,尤其是受购物篮分析的影响,关联规则被应用到很多实际业务中,本文对关联规则挖掘做一个小的总结。 首先,和聚类算法一样,关联规则挖掘属于无监督学习方法,它描述的是在一个事物中物品间同时出现的
在各种数据挖掘算法中,关联规则挖掘算是比较重要的一种,尤其是受购物篮分析的影响,关联规则被应用到很多实际业务中,本文对关联规则挖掘做一个小的总结。 首先,和聚类算法一样,关联规则挖掘属于无监督学习方法,它描述的是在一个事物中物品间同时出现的规律的知识模式,现实生活中,比如超市购物时,顾客购买记录常常隐含着很多关联规则,比如购买圆珠笔的顾客中有65%也购买了笔记本,利用这些规则,商场人员可以很好的规划商品摆放问题; 为叙述方便,设R= { I1,I2 ......Im} 是一组物品集,W 是一组事务集。W 中的每个事务T 是一组物品,T是R的子集。假设有一个物品集A,一个事务T,关联规则是如下形式的一种蕴含:A→B,其中A、B 是两组物品,A属于I子集,B属于I子集。 在关联规则中设计4个常用关键指标 1.置信度(confidence)定义:设W中支持物品集A的事务中,有c %的事务同时也支持物品集B,c %称为关联规则A→B 的可信度。
通俗解释:简单地说,可信度就是指在出现了物品集A 的事务T 中,物品集B 也同时出现的概率有多大。
实例说明:上面所举的圆珠笔和笔记本的例子,该关联规则的可信度就回答了这样一个问题:如果一个顾客购买了圆珠笔,那么他也购买笔记本的可能性有多大呢?在上述例子中,购买圆珠笔的顾客中有65%的人购买了笔记本, 所以可信度是65%。
概率描述:物品集A对物品集B的置信度confidence(A==>B)=P(A|B)
2.支持度(support)定义:设W 中有s %的事务同时支持物品集A 和B,s %称为关联规则A→B 的支持度。支持度描述了A 和B 这两个物品集的并集C 在所有的事务中出现的概率有多大。
通俗解释:简单地说,A==>B的支持度就是指物品集A和物品集B同时出现的概率。
实例说明:某天共有1000 个顾客到商场购买物品,其中有150个顾客同时购买了圆珠笔和笔记本,那么上述的关联规则的支持度就是15%。
概率描述:物品集A对物品集B的支持度support(A==>B)=P(A n B)
3.期望置信度(Expected confidence)定义:设W 中有e %的事务支持物品集B,e %称为关联规则A→B 的期望可信度度。
通俗解释:期望可信度描述了在没有任何条件影响时,物品集B 在所有事务中出现的概率有多大。
实例说明:如果某天共有1000 个顾客到商场购买物品,其中有250 个顾客购买了圆珠笔,则上述的关联规则的期望可信度就是25 %。
概率描述:物品集A对物品集B的期望置信度为support(B)=P(B)
4.提升度(lift)定义:提升度是可信度与期望可信度的比值
通俗解释:提升度反映了“物品集A的出现”对物品集B的出现概率发生了多大的变化。
实例说明:上述的关联规则的提升度=65%/25%=2.6
概率描述:物品集A对物品集B的期望置信度为lift(A==>B)=confidence(A==>B)/support(B)=p(B|A)/p(B)
总之,可信度是对关联规则的准确度的衡量,支持度是对关联规则重要性的衡量。支持度说明了这条规则在所有事务中有多大的代表性,显然支持度越大,关联规则越重要。有些关联规则可信度虽然很高,但支持度却很低,说明该关联规则实用的机会很小,因此也不重要。
在关联规则挖掘中,满足一定最小置信度以及支持度的集合成为频繁集(frequent itemset),或者强关联。关联规则挖掘则是一个寻找频繁集的过程。
关联规则挖掘的相关算法
1.Apriori算法:使用候选项集找频繁项集
Apriori算法是一种最有影响的挖掘布尔关联规则频繁项集的算法。其核心是基于两阶段频集思想的递推算法。该关联规则在分类上属于单维、单层、布尔关联规则。在这里,所有支持度大于最小支持度的项集称为频繁项集,简称频集。
该算法的基本思想是:首先找出所有的频集,这些项集出现的频繁性至少和预定义的最小支持度一样。然后由频集产生强关联规则,这些规则必须满足最小支持度和最小可信度。然后使用第1步找到的频集产生期望的规则,产生只包含集合的项的所有规则,其中每一条规则的右部只有一项,这里采用的是中规则的定义。一旦这些规则被生成,那么只有那些大于用户给定的最小可信度的规则才被留下来。为了生成所有频集,使用了递推的方法。
可能产生大量的候选集,以及可能需要重复扫描数据库,是Apriori算法的两大缺点。
2.基于划分的算法
Savasere等设计了一个基于划分的算法。这个算法先把数据库从逻辑上分成几个互不相交的块,每次单独考虑一个分块并对它生成所有的频集,然后把产生的频集合并,用来生成所有可能的频集,最后计算这些项集的支持度。这里分块的大小选择要使得每个分块可以被放入主存,每个阶段只需被扫描一次。而算法的正确性是由每一个可能的频集至少在某一个分块中是频集保证的。该算法是可以高度并行的,可以把每一分块分别分配给某一个处理器生成频集。产生频集的每一个循环结束后,处理器之间进行通信来产生全局的候选k-项集。通常这里的通信过程是算法执行时间的主要瓶颈;而另一方面,每个独立的处理器生成频集的时间也是一个瓶颈。
3.FP-树频集算法
针对Apriori算法的固有缺陷,J. Han等提出了不产生候选挖掘频繁项集的方法:FP-树频集算法。采用分而治之的策略,在经过第一遍扫描之后,把数据库中的频集压缩进一棵频繁模式树(FP-tree),同时依然保留其中的关联信息,随后再将FP-tree分化成一些条件库,每个库和一个长度为1的频集相关,然后再对这些条件库分别进行挖掘。当原始数据量很大的时候,也可以结合划分的方法,使得一个FP-tree可以放入主存中。实验表明,FP-growth对不同长度的规则都有很好的适应性,同时在效率上较之Apriori算法有巨大的提高。

In database optimization, indexing strategies should be selected according to query requirements: 1. When the query involves multiple columns and the order of conditions is fixed, use composite indexes; 2. When the query involves multiple columns but the order of conditions is not fixed, use multiple single-column indexes. Composite indexes are suitable for optimizing multi-column queries, while single-column indexes are suitable for single-column queries.

To optimize MySQL slow query, slowquerylog and performance_schema need to be used: 1. Enable slowquerylog and set thresholds to record slow query; 2. Use performance_schema to analyze query execution details, find out performance bottlenecks and optimize.

MySQL and SQL are essential skills for developers. 1.MySQL is an open source relational database management system, and SQL is the standard language used to manage and operate databases. 2.MySQL supports multiple storage engines through efficient data storage and retrieval functions, and SQL completes complex data operations through simple statements. 3. Examples of usage include basic queries and advanced queries, such as filtering and sorting by condition. 4. Common errors include syntax errors and performance issues, which can be optimized by checking SQL statements and using EXPLAIN commands. 5. Performance optimization techniques include using indexes, avoiding full table scanning, optimizing JOIN operations and improving code readability.

MySQL asynchronous master-slave replication enables data synchronization through binlog, improving read performance and high availability. 1) The master server record changes to binlog; 2) The slave server reads binlog through I/O threads; 3) The server SQL thread applies binlog to synchronize data.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

The installation and basic operations of MySQL include: 1. Download and install MySQL, set the root user password; 2. Use SQL commands to create databases and tables, such as CREATEDATABASE and CREATETABLE; 3. Execute CRUD operations, use INSERT, SELECT, UPDATE, DELETE commands; 4. Create indexes and stored procedures to optimize performance and implement complex logic. With these steps, you can build and manage MySQL databases from scratch.

InnoDBBufferPool improves the performance of MySQL databases by loading data and index pages into memory. 1) The data page is loaded into the BufferPool to reduce disk I/O. 2) Dirty pages are marked and refreshed to disk regularly. 3) LRU algorithm management data page elimination. 4) The read-out mechanism loads the possible data pages in advance.

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 Chinese version
Chinese version, very easy to use

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.