Run Aprili from Python with Orange

Introduction

--When I was looking for a Python implementation of Apriori, it seems that it is implemented in Orange, so a memo when I tried it

Caution

--There is a new version of Orange 3 and an old version of Orange 2 (Orange 2.7.8 as of 9/11/2016)

--Apriori module not found in Orange 3. .. can't find associate module

--So install Orange 2

Installation

Here is an example of installing on Ubuntu

Download the source file from Official Site and extract it.

Build and install as described in the Python Software Foundation (https://pypi.python.org/pypi/Orange/2.7)

python setup.py build
python setup.py install

If you don't need scipy, install it

Apriori

I referred to Association Analysis

The data is prepared as follows. The extension must be basket

$ more hayes-roth-train1-1.basket
a2,b2,c3,d4,D3
a3,b2,c1,d3,D1
<snip>

Run

>>> import Orange
>>> data = Orange.data.Table('hayes-roth-train1-1.basket')
>>> rules = Orange.associate.AssociationRulesSparseInducer(data, support=0.03, confidence=0.2, classification_rules=1, store_examples=True)
>>> print "%4s %4s %4s  %4s" % ("Supp", "Conf", "Lift", "Rule")
Supp Conf Lift  Rule
>>> for r in rules[:5]:
...     print "%4.1f %4.1f %4.1f   %s" % (r.support, r.confidence, r.lift, r)
...
 0.0  0.2  3.6   b4 -> c4
 0.0  0.3  3.6   c4 -> b4
 0.0  0.2  7.2   c4 -> b4 a1
 0.0  0.5  6.0   c4 a1 -> b4
 0.0  0.2  7.2   c4 -> b4 a1 D3

Extract Rule

See the following document and try it

Association rules and frequent itemsets Orange.data.Instance Orange.data.Value

>>> len(rules)
400
>>> rules[383]
b2 a2 -> c1
>>> rules[383].left
[], {"b2":1.000, "a2":1.000}
>>> rules[383].left.get_metas(str).keys()
['a2', 'b2']
>>> rules[383].right.get_metas(str).keys()
['c1']
>>> rules[383].confidence
0.7333333492279053
>>> rules[383].support
0.07692307978868484
>>> rules[383].n_applies_both
11.0

Does the target match the rule?

>>> rule = rules[383]
>>> for d in data:
...     if rule.appliesBoth(d):
...         print d
...
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d3":1.000, "D1":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d2":1.000, "D2":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d2":1.000, "D2":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d2":1.000, "D2":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d3":1.000, "D2":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d4":1.000, "D3":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d1":1.000, "D1":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d3":1.000, "D1":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d1":1.000, "D1":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d2":1.000, "D2":1.000}
[], {"a2":1.000, "b2":1.000, "c1":1.000, "d1":1.000, "D1":1.000}

>>> rule.examples
Orange.data.Table 'table'
>>> rule.match_both
<2, 3, 5, 40, 87, 105, 111, 116, 118, 135, 137>

in conclusion

--Check from now on if speed will come out --Is there any difference from scikit-learn?

Recommended Posts

Run Aprili from Python with Orange
Run Python with VBA
Run prepDE.py with python3
Run python from excel
Run iperf with python
Run python with PyCharm (Windows)
Run Python with CloudFlash (arm926ej-s)
Let's run Excel with Python
Run illustrator script from python
Run Label with tkinter [Python]
With skype, notify with skype from python!
Run DHT22 with RasPi + Python
Run Python from Excel VBA with xlwings & tutorial supplement
Run iphone safari from mac with python + selenium + safari-webdriver
Call C from Python with DragonFFI
Install Python from source with Ansible
Run Rotrics DexArm with python API
Run mruby with Python or Blender
Run XGBoost with Cloud Dataflow (Python)
Run python3 Django1.9 with mod_wsgi (deploy)
Python error detection run from Powershell
Run Python scripts synchronously from C #
Call python from nim with Nimpy
Until you run python with apache
Run Ansible from Python using API
Read fbx from python with cinema4d
Run Python Scripts from Cisco Memorandum_EEM
Collecting information from Twitter with Python (Twitter API)
Run Cloud Dataflow (Python) from App Engine
Receive textual data from mysql with python
Get html from element with Python selenium
[Note] Get data from PostgreSQL with Python
Run servo with Python on ESP32 (Windows)
Play audio files from Python with interrupts
Create wordcloud from your tweet with python3
Run Keras with CNTK backend from CentOS
Business efficiency starting from scratch with Python
Working with Azure CosmosDB from Python Part.2
Image acquisition from camera with Python + OpenCV
Getting started with Dynamo from Python boto
Try calling Python from Ruby with thrift
Scraping from an authenticated site with python
Run a Python web application with Docker
Use C ++ functions from python with pybind11
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Twilio with Python
Integrate with Python
Play with 2016-Python
sql from python
AES256 with python
python starts with ()
with syntax (Python)
MeCab from Python
Bingo with python
Zundokokiyoshi with python
Excel with Python
Microcomputer with Python
Cast with python