在关系数据库中查找统计相关性
我有一个大型 SQL 数据库,其中包含状态特征和奖励指标之间的关联。例如,
A ^ B ^ C ^ D ^ Action(E) => 0.1
F ^ G ^ W ^ D ^ Action(R,P,H) => 0.9
A ^ T ^ U ^ Y ^ Action(A,S) => 0.2
我的特征可能是离散的、连续的或名义的。我正在尝试找到一组可用于最大化奖励指标的规则或模式。挖掘这些数据以找到最强的统计相关性的最佳工具是什么(最好用 Python 编写或从 Python 访问)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有一系列完善的技术专门针对您的问题中提出的用例。鉴于实现这些技术的库的出身和广泛选择,即使对于许多数据分析师来说,它们也不是众所周知的。
此类技术称为频繁项集(或频繁项集学习);还使用术语关联规则和市场包集分析,但后者不太常见。 (顺便说一句,也许这些听起来含糊的名字导致了它们相对默默无闻)。
arules背景文档的第一句话(arules是实现关联规则的R包):
来说,AR/FI 是一种无监督机器学习技术,根据 HTF 的说法,它是“凹凸狩猎”或“模式寻找”的简化
。两个术语单独使用或一起使用是网络搜索的最佳初始查询术语。您可以在维基百科中找到这两个术语的条目; 关联规则是一个很好的高级概述,但对于程序员来说足够详细。这两个术语描述了该技术; “Apriori”和“Eclat”是原始关联规则算法的两个最广泛使用的实现,该算法最初由 IBM Almaden Research 开发。
要使用先验,您需要传入您希望算法测试关联的数据库字段;您还传递了一个阈值关联 - 又名支持级别。我通常选择 5%,然后朝一个方向或另一个方向调整它,直到获得我想要的规则数量(支持级别越高,返回的规则越少)。
apriori 返回的是关联规则本身。
如果你想要一个Python库来做AR/FI,那么 Orange 是唯一的我知道的一个(可能还有其他)。 (您可能知道,Orange 有一个 GUI,但它有一个很好的 Python 脚本接口)。我从未使用过 Orange,但我只是简单浏览了一下它的关联规则模块,它的实现方式似乎与我个人使用过的 AR 库类似。我认为教程(Python)非常好。
我的建议可能是使用 R 绑定 RPy2 通过 Python 访问 R 对 AR/FI 的强大支持。
R 是唯一用于关联规则的语言/平台,并且我拥有相当数量的所有五个 AR/FI 库。对于我的第一个 AR/FI 项目,我选择 R 与 AR/FI 库的可用性或质量无关,而是与易于使用的关系数据库驱动程序(适用于 MySQL、PostgreSQL 和 SQLite)有关;现在还有最常用的 NoSQL 事务数据库(如 MongoDB 和 CouchDB)的驱动程序/绑定。 MySQL 驱动程序/绑定允许我通过 R 连接到我的数据库,并将数据直接提供给 apriori 算法。
There is a well-established family of techniques directed to precisely to the use case presented in your Question. Given the pedigree and braod selection of libraries implementing these techniques, they are not well known even to many data analysts.
This class of techniques is called Frequent Itemsets (or Frequent Itemset Learning); the terms Association Rules and Market Bakset Analysis are also used but the latter is much less common. (As an aside, perhaps the vague-sounding names contribute to their relative obscurity).
The first sentence of arules background Docs (arules is an R Package implementing Association Rules) :
Taxonomically, AR/FI is an unsupervised machine learning technique, that according to HTF is a simplification of "bump hunting" or "mode finding"
In any event, those two terms--used either by themselves or together are the best inital query terms for Web searches. You will find Wikipedia entries for both terms; the one for Association Rules is a good high-level overview, but sufficiently detailed for a programmer. So those two terms describe the technique; "Apriori" and "Eclat" are the two most widely used implementations of the original Association Rules algorithm, which was originally devleoped at IBM Almaden Research.
To use apriori, you pass in the database fields that you want the algorithm to test for association; you also pass in a threshold association--aka support level. i usuaully chose 5% then tune it in one direction or the other until i get the number of rules that i want (the higher the support level, the fewer rules returned).
What apriori returns is the association rules themselves.
If you want a python library to do AR/FI, then Orange is the only one that i know of (there could be others). (Orange has a GUI, as you probably know, but it has a nice scripting interface for python). I have never used Orange but i just had a brief look at its Association Rules module and and it seems to be implemented similarly to the AR libraries i have personally used. The tutorial (in python) i thought was very good.
My recommendation might be to access R's strong support for AR/FI via Python using the R bindings, RPy2.
R is the only language/platform have used for Association Rules, and i have all of the five AR/FI libraries a fair amount. For my first AR/FI project, my choice of R had nothing to do with the availability or quality of the AR/FI libraries, but rather with the simple-to-use relational database drivers (for MySQL, PostgreSQL, and SQLite); now there are also drivers/bindings for the most commonly used NoSQL transaction databases like MongoDB and CouchDB. The MySQL drivers/bindings allowed me to connect to my database via R, and feed the data directly to the apriori algorithm.
您的“尝试找到一组可用于最大化奖励指标的规则或模式”的问题听起来很像 强化学习。如果在给定状态下执行操作后,您过渡到另一个新状态,并且您正在寻找最佳策略(即在状态 x 时采取什么操作),那么您的问题基本上就是强化学习的问题。如果转移概率(如果我在状态 x 执行一段时间的操作,则转移到状态 y 的概率)已知,那么您可能需要查看 MDP,如果您不知道转换概率,请查看 Q-学习。请注意,根据您的状态空间,您可能需要聪明才能扩展强化学习,但如果它是 4D 的,那么您可能没问题。虽然我不知道强化学习的 python 实现,但应该有一个。您可能还想查看 Dr. Ng 关于强化学习的讲座。
Your problem of "trying to find a set of rules or patterns that can be used to maximize the reward metric" sounds a lot like Reinforcement Learning. If after preforming an action in a given state you transition to another new state and you are looking for an optimal policy (i.e. what action to take when in state x) then your problem is basically exactly that of Reinforcement Learning. If the transition probabilities (if i do action a while in state x then the probability of transitioning to state y) are known then you may want to look into MDPs, if you do not know the transition probabilities then look into Q-Learning. Note, depending on your state space you may need to be clever to get Reinforcement Learning to scale, but if it's 4D then you're probably OK. While I do not know of a python implementation for Reinforcement Learning, there should be one out there. You may also want to check out Dr. Ng's Lectures on RL.