Git Product home page Git Product logo

pyids's Introduction

pyIDS

pyIDS is a custom implementation of IDS (Interpretable Decision Sets) algorithm introduced in

LAKKARAJU, Himabindu; BACH, Stephen H.; LESKOVEC, Jure. Interpretable decision sets: A joint framework for description and prediction. In: Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining. ACM, 2016. p. 1675-1684.

If you find this package useful in your research, please cite our paper on this Interpretable Decision Sets Implementation:

Jiri Filip, Tomas Kliegr. PyIDS - Python Implementation of Interpretable Decision Sets Algorithm by Lakkaraju et al, 2016. RuleML+RR2019@Rule Challenge 2019. http://ceur-ws.org/Vol-2438/paper8.pdf

Installation

The pyarc, pandas, scipy and numpy packages need to be installed before using pyIDS.

All of these packages can be installed using pip.

For pyarc, please refer to the Installation section of its README file.

Examples

training a simple IDS model

import pandas as pd
from pyids.algorithms.ids_classifier import mine_CARs
from pyids.algorithms.ids import IDS

from pyarc.qcba.data_structures import QuantitativeDataFrame
import io
import requests

url = "https://raw.githubusercontent.com/kliegr/arcBench/master/data/folds_discr/train/iris0.csv"
s = requests.get(url).content
df = pd.read_csv(io.StringIO(s.decode('utf-8')))
cars = mine_CARs(df, rule_cutoff=50)
lambda_array = [1, 1, 1, 1, 1, 1, 1]

quant_dataframe = QuantitativeDataFrame(df)

ids = IDS(algorithm="SLS")
ids.fit(quant_dataframe=quant_dataframe, class_association_rules=cars, lambda_array=lambda_array)

acc = ids.score(quant_dataframe)

optimizing for best lambda parameters using coordinate ascent, as described in the original paper

import pandas as pd
import io
import requests

from pyids.algorithms.ids_classifier import mine_CARs
from pyids.algorithms.ids import IDS
from pyids.model_selection.coordinate_ascent import CoordinateAscent

from pyarc.qcba.data_structures import QuantitativeDataFrame


url = "https://raw.githubusercontent.com/jirifilip/pyids/master/data/titanic.csv"
s = requests.get(url).content
df = pd.read_csv(io.StringIO(s.decode('utf-8')))
quant_df = QuantitativeDataFrame(df)
cars = mine_CARs(df, 20)


def fmax(lambda_dict):
    print(lambda_dict)
    ids = IDS(algorithm="SLS")
    ids.fit(class_association_rules=cars, quant_dataframe=quant_df, lambda_array=list(lambda_dict.values()))
    auc = ids.score_auc(quant_df)
    print(auc)
    return auc



coord_asc = CoordinateAscent(
    func=fmax,
    func_args_ranges=dict(
        l1=(1, 1000),
        l2=(1, 1000),
        l3=(1, 1000),
        l4=(1, 1000),
        l5=(1, 1000),
        l6=(1, 1000),
        l7=(1, 1000)
    ),
    ternary_search_precision=50,
    max_iterations=3
)

best_lambdas = coord_asc.fit()

pyids's People

Contributors

jirifilip avatar joschout avatar kliegr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pyids's Issues

missing pyarc file

Dear Jiri,
It seems that in pyIDS, pyarc file is missing. In the examples you posted, it has "from pyarc.qcba.data_structures import QuantitativeDataFrame", but it seems that there is no "pyarc" file.

can you share correct code for original IDS

can you share correct code for original IDS pls
as you wrote
correct errors in code to allow it to run (wrong identation etc.)
in
https://github.com/jirifilip/pyIDS/blob/master/scripts/other/reference_implementation_testing.ipynb

git pull https://github.com/lvhimabindu/interpretable_decision_sets interpretable_decision_sets_lakkaraju
locate your python site_packages directory
copy interpretable_decision_sets_lakkaraju into site_packages
correct errors in code to allow it to run (wrong identation etc.)

Possibly incorrect L_max in the objective function

L_max is incorrectly calculated in the part of the objective function minimizing the number of literals in the current ruleset.

This part of the objective function uses as an upper bound L_max * len_all_rules, with:

  • len_all_rules: the total number of all possible rules
  • L_max: length of the longest rule over all possible rules, in number of predicates.

Currently, L_max is calculated over the current ruleset, which is a subset of the initial set of rules. It should be calculated over all rules.

L_max = solution_set.max_rule_length()

iteritems() no longer working

The pandas method .iteritems() is now just called .items(), and in the latest version of pandas the old name no longer exists, so the code breaks. Could you replace the two occurrences in pyids/algorithms/ids_classifier.py?

pyarc is running on my computer but testing_rule_miner.py fails

how to install this pyIDS on Windows ?
pyarc is running on my computer
but I get this error for testing_rule_miner.py
File "e:\rule_induction_classification_Prism_etc\code\pyIDS-master\pyIDS-master\testing_rule_miner.py", line 1, in
from pyids.rule_mining import RuleMiner
File "e:\rule_induction_classification_Prism_etc\code\pyIDS-master\pyIDS-master\pyids_init_.py", line 1, in
from .ids import *
File "e:\rule_induction_classification_Prism_etc\code\pyIDS-master\pyIDS-master\pyids\ids.py", line 1, in
from .data_structures import IDS, mine_CARs, mine_IDS_ruleset
File "e:\rule_induction_classification_Prism_etc\code\pyIDS-master\pyIDS-master\pyids\data_structures_init_.py", line 2, in
from .ids_classifier import *
File "e:\rule_induction_classification_Prism_etc\code\pyIDS-master\pyIDS-master\pyids\data_structures\ids_classifier.py", line 1, in
from pyarc.qcba.data_structures import QuantitativeDataFrame
File "e:\WINPYTHON_N1\WPy64-3741\python-3.7.4.amd64\Lib\site-packages\pyarc\qcba_init_.py", line 2, in
from .classifier import *
File "e:\WINPYTHON_N1\WPy64-3741\python-3.7.4.amd64\Lib\site-packages\pyarc\qcba\classifier.py", line 1, in
from .data_structures import QuantitativeDataFrame

builtins.ModuleNotFoundError: No module named 'pyarc.qcba.data_structures'

image

Bug: removing an integer from a set of IDSRules

soln_set.ruleset.remove(rule_idx)

Inside the optimize_delta() method of the SLSOptiimizer, there is an iteration over the rules in the current solution set. This iteration uses an enumeration, giving back both an index in the array or omega_estimates and the corresponding rule. When the omega_estimate for the current rule is below the threshold value, the current rule must be removed from the current solution set.

soln_set.ruleset.remove(rule_idx) should be changed to soln_set.ruleset.remove(rule).

Currently, this can result in a KeyError

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.