cape-一个通过平衡来解释聚集结果中异常值的系统。
capexplain的Python项目详细描述
开普敦
作为最初的贡献,我们开发了一个名为cape(用聚合模式进行解释的反平衡)的新系统,通过反平衡来解释聚合查询中的异常值。也就是说,解释是与感兴趣的异常值相反的异常值。 cape(c使用a聚合p模式的计数器平衡e表达式)是一个系统,用于解释sql中按组查询的异常值(异常低或高)聚合函数结果。用户向系统提供一个查询,并为此查询提供一个令人惊讶的结果。然后,cape在离线模式挖掘步骤中使用在查询输入数据上发现的模式,通过在抵消感兴趣异常值的相反方向上找到一个相关的异常值来解释异常值。
安装
先决条件
cape需要python 3,并使用python的tkinter
作为图形用户界面。例如,在ubuntu上,您可以使用以下命令安装先决条件:
sudo apt-get install python3 python3-pip python3-tk
使用PIP安装
确保已安装pip(请参阅上一步)。
pip3 install capexplain
从Github安装
或者,您可以直接从源安装。为此,您需要python3和setuptools包。你可能想用virtual environment来表示。如果您已经安装了python3
和pip
,您可以通过运行:
</code></pre> <p>To install Cape, clone the github repository and use <code>setup.py</code> to install.</p> <pre><code class="language-shell">git clone git@github.com:IITDBGroup/cape.git capexplain cd capexplain python3 setup.py install
用法
cape提供支持多个子命令的单个二进制capexplain
。一般形式为:
capexplain COMMAND [OPTIONS]
选项特定于每个子命令。使用capexplain help
查看受支持命令的列表,并使用capexplain help COMMAND
获取子命令的更详细帮助。
概述
cape目前只支持postgresql作为后端数据库(版本9或更高)。要使用cape来解释聚合异常值,首先必须让cape查找要聚合的表的模式。这是一个脱机步骤,每个表只需执行一次(除非您希望使用不同的参数设置重新运行模式挖掘)。之后,您可以使用命令行或cape的ui请求对聚合查询结果中的异常值进行解释。
挖掘模式
使用capexplain mine [OPTIONS]
挖掘模式。cape将把发现的模式存储在数据库中。“挖掘”的模式将存储在名为pattern
的已创建模式中,运行mine
命令后生成的模式表是pattern.{target_table}_global
和pattern.{target_table}_local
。至少,您必须告诉cape如何连接到您要使用的数据库,以及它应该为哪个表生成模式。运行capexplain help mine
以获取mine命令的所有支持选项的列表。指定目标表和数据库连接所需的选项是:
-h ,--host <arg> - database connection host IP address (DEFAULT: 127.0.0.1) -u ,--user <arg> - database connection user (DEFAULT: postgres) -p ,--password <arg> - database connection password -d ,--db <arg> - database name (DEFAULT: postgres) -P ,--port <arg> - database connection port (DEFAULT: 5432) -t ,--target-table <arg> - mine patterns for this table
例如,如果您使用用户postgres
(默认)、密码test
在本地(默认)运行postgres服务器,并希望挖掘数据库mydb
中表employees
的模式,则运行:
capexplain mine -p test -d mydb -t employees
挖掘算法参数
cape的挖掘算法采用以下参数:
--gof-const <arg> - goodness-of-fit threshold for constant regression (DEFAULT: 0.1) --gof-linear <arg> - goodness-of-fit threshold for linear regression (DEFAULT: 0.1) --confidence <arg> - global confidence threshold -r ,--regpackage <arg> - regression analysis package to use {'statsmodels', 'sklearn'}(DEFAULT: statsmodels) --local-support <arg> - local support threshold (DEFAULT: 10) --global-support <arg> - global support thresh (DEFAULT: 100) -f ,--fd-optimizations <arg> - activate functional dependency detection and optimizations (DEFAULT: False) -a ,--algorithm <arg> - algorithm to use for pattern mining {'naive', 'optimized', 'naive_alternative'}(DEFAULT: optimized) --show-progress <arg> - show progress meters (DEFAULT: True) --manual-config - manually configure numeric-like string fields (treat fields as string or numeric?)(DEFAULT: False)
运行我们的“犯罪”数据示例
我们包含了“芝加哥犯罪”数据集的一个子集(https://data.cityofchicago.org/Public-Safety/Crimes-2001-to-present/)
在我们的存储库中供用户使用。要在postgres数据库的/testdb
目录下导入此数据集,请运行以下命令模板:
psql -h <host> -U <user name> -d <local database name where you want to store our example table> < ~/cape/testdb/crime_demonstration.sql
然后相应地运行capexplain
命令来研究这个示例。
解释异常值
要解释聚集异常值,请使用capexplain explain [OPTIONS]
。
-l ,--log <arg> - select log level {DEBUG,INFO,WARNING,ERROR}(DEFAULT: ERROR) --help - show this help message -h ,--host <arg> - database connection host IP address (DEFAULT: 127.0.0.1) -u ,--user <arg> - database connection user (DEFAULT: postgres) -p ,--password <arg> - database connection password -d ,--db <arg> - database name (DEFAULT: postgres) -P ,--port <arg> - database connection port (DEFAULT: 5432) --ptable <arg> - table storing aggregate regression patterns --qtable <arg> - table storing aggregation query result --ufile <arg> - file storing user question -o ,--ofile <arg> - file to write output to -a ,--aggcolumn <arg> - column that was input to the aggregation function
对于explain
选项,除了常见的选项外,用户还应该给出--ptable
、pattern.{target_table}
和--qtable
、target_table
。另外,我们目前只允许用户通过一个.txt
文件传递问题,用户需要按照以下格式提出问题:
attribute1, attribute 2, attribute3...., direction
value1,value2,value3...., high/low
请参考input.txt
看一个例子。
启动解释资源管理器图形用户界面
cape附带了一个图形用户界面,用于运行查询、选择感兴趣的异常值、探索与异常值相关的模式以及浏览系统生成的解释。您需要指定要连接到的Postgres服务器。资源管理器只能使用capexplain mine
为预先挖掘模式的表上的查询生成解释。
这是我们的演示视频:(https://www.youtube.com/watch?v=gWqhIUrcwz8)
$ capexplain help gui capexplain gui [OPTIONS]: Open the Cape graphical explanation explorer. SUPPORTED OPTIONS: -l ,--log <arg> - select log level {DEBUG,INFO,WARNING,ERROR}(DEFAULT: ERROR) --help - show this help message -h ,--host <arg> - database connection host IP address (DEFAULT: 127.0.0.1) -u ,--user <arg> - database connection user (DEFAULT: postgres) -p ,--password <arg> - database connection password -d ,--db <arg> - database name (DEFAULT: postgres) -P ,--port <arg> - database connection port (DEFAULT: 5432)
例如,如果使用用户postgres
(默认)、密码test
和数据库mydb
在本地(默认)运行Postgres服务器,则运行:
capexplain gui -p test -d mydb
链接
cape是由伊利诺伊理工学院和杜克大学的研究人员开发的。有关更多信息和出版物,请参见cape项目页http://www.cs.iit.edu/~dbgroup/projects/cape.html。