fastsrs 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastsrs/__init__.py +80 -0
- fastsrs/data.py +43 -0
- fastsrs/nobounds.py +1264 -0
- fastsrs/optimal.py +897 -0
- fastsrs/proprules.py +284 -0
- fastsrs/rashomon_epsilon.py +875 -0
- fastsrs/rashomon_nsize.py +875 -0
- fastsrs/two_step.py +1338 -0
- fastsrs/two_step_rashomon_epsilon.py +1354 -0
- fastsrs/util.py +452 -0
- fastsrs-0.1.0.dist-info/METADATA +363 -0
- fastsrs-0.1.0.dist-info/RECORD +15 -0
- fastsrs-0.1.0.dist-info/WHEEL +5 -0
- fastsrs-0.1.0.dist-info/licenses/LICENSE +21 -0
- fastsrs-0.1.0.dist-info/top_level.txt +1 -0
fastsrs/__init__.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"""FastSRS: Fast Rashomon Sets of Sparse Rule Sets.
|
|
2
|
+
|
|
3
|
+
Source code for the paper *"Fast Rashomon Sets of Sparse Rule Sets"* by
|
|
4
|
+
Cristina Molero-Río, Boxuan Li, Tong Wang, and Cynthia Rudin.
|
|
5
|
+
|
|
6
|
+
Quick start::
|
|
7
|
+
|
|
8
|
+
from fastsrs import ORS, load_binary_csv, merge_interval, merge_logical
|
|
9
|
+
|
|
10
|
+
X, y, col_ls = load_binary_csv("datasets/heart.csv")
|
|
11
|
+
model = ORS(X, y, col_ls, "fpgrowth")
|
|
12
|
+
model.set_parameters(c1=0.00025, c2=0.001, c3=0.00025 / 3)
|
|
13
|
+
model.set_fixed_bounds()
|
|
14
|
+
model.generate_rules(5, 2, 2000, method="fpgrowth", criteria="precision")
|
|
15
|
+
grs, maps = model.train(500, 0.25, False)
|
|
16
|
+
merge_interval(model, grs)
|
|
17
|
+
merge_logical(model, grs)
|
|
18
|
+
model.printMRS(grs)
|
|
19
|
+
|
|
20
|
+
Submodules
|
|
21
|
+
----------
|
|
22
|
+
optimal
|
|
23
|
+
``ORS`` learner for a single optimal sparse rule set (re-exported here).
|
|
24
|
+
rashomon_epsilon
|
|
25
|
+
``ORS`` variant whose ``train()`` also returns every rule set visited so an
|
|
26
|
+
epsilon-Rashomon set can be extracted with :func:`get_epsilon_rashomon`.
|
|
27
|
+
rashomon_nsize
|
|
28
|
+
``ORS`` variant that collects a size-bounded Rashomon set.
|
|
29
|
+
two_step
|
|
30
|
+
``ORS`` variant with two-step training (subsample warm-up, then full data).
|
|
31
|
+
two_step_rashomon_epsilon
|
|
32
|
+
Two-step trainer combined with epsilon-Rashomon-set collection.
|
|
33
|
+
nobounds
|
|
34
|
+
Ablation: no Theorem-1/2 bounds during rule screening.
|
|
35
|
+
proprules
|
|
36
|
+
Rule-count statistics through the screening pipeline.
|
|
37
|
+
util
|
|
38
|
+
Preprocessing, prediction, metric and diversity helpers.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
__version__ = "0.1.0"
|
|
42
|
+
|
|
43
|
+
from .util import (
|
|
44
|
+
preprocess_data,
|
|
45
|
+
predict_MRS,
|
|
46
|
+
predict_MRS_mix,
|
|
47
|
+
getConfusion,
|
|
48
|
+
accuracy,
|
|
49
|
+
merge_interval,
|
|
50
|
+
merge_logical,
|
|
51
|
+
calculate_rules,
|
|
52
|
+
calculate_conditions,
|
|
53
|
+
calculate_values,
|
|
54
|
+
prediction_diversity,
|
|
55
|
+
structural_diversity,
|
|
56
|
+
canonical_form,
|
|
57
|
+
get_epsilon_rashomon,
|
|
58
|
+
)
|
|
59
|
+
from .data import load_binary_csv
|
|
60
|
+
from .optimal import ORS
|
|
61
|
+
|
|
62
|
+
__all__ = [
|
|
63
|
+
"__version__",
|
|
64
|
+
"ORS",
|
|
65
|
+
"load_binary_csv",
|
|
66
|
+
"preprocess_data",
|
|
67
|
+
"predict_MRS",
|
|
68
|
+
"predict_MRS_mix",
|
|
69
|
+
"getConfusion",
|
|
70
|
+
"accuracy",
|
|
71
|
+
"merge_interval",
|
|
72
|
+
"merge_logical",
|
|
73
|
+
"calculate_rules",
|
|
74
|
+
"calculate_conditions",
|
|
75
|
+
"calculate_values",
|
|
76
|
+
"prediction_diversity",
|
|
77
|
+
"structural_diversity",
|
|
78
|
+
"canonical_form",
|
|
79
|
+
"get_epsilon_rashomon",
|
|
80
|
+
]
|
fastsrs/data.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Helpers for loading data in the binary format FastSRS expects."""
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import pandas as pd
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def load_binary_csv(path, target_col="Class", drop_constant=True):
|
|
8
|
+
"""Load an all-binary CSV into the ``(X, y, col_ls)`` triple used by ``ORS``.
|
|
9
|
+
|
|
10
|
+
Parameters
|
|
11
|
+
----------
|
|
12
|
+
path : str or path-like
|
|
13
|
+
CSV with 0/1 indicator columns and an integer target column. Use
|
|
14
|
+
:func:`fastsrs.preprocess_data` to build one from raw data.
|
|
15
|
+
target_col : str, default ``"Class"``
|
|
16
|
+
Name of the target column.
|
|
17
|
+
drop_constant : bool, default ``True``
|
|
18
|
+
Remove feature columns that take a single value, which carry no
|
|
19
|
+
information and would otherwise slow down rule mining.
|
|
20
|
+
|
|
21
|
+
Returns
|
|
22
|
+
-------
|
|
23
|
+
X : numpy.ndarray of shape (n_samples, n_features)
|
|
24
|
+
y : numpy.ndarray of shape (n_samples,), dtype float
|
|
25
|
+
col_ls : numpy.ndarray of feature names aligned with the columns of ``X``
|
|
26
|
+
"""
|
|
27
|
+
df = pd.read_csv(path, header=0, sep=",")
|
|
28
|
+
if target_col not in df.columns:
|
|
29
|
+
raise ValueError(
|
|
30
|
+
f"target column {target_col!r} not found in {path}; "
|
|
31
|
+
f"available columns: {list(df.columns)[:10]}..."
|
|
32
|
+
)
|
|
33
|
+
y = np.array(df[target_col], dtype=float)
|
|
34
|
+
df = df.drop(target_col, axis=1)
|
|
35
|
+
col_ls = df.columns.values.copy()
|
|
36
|
+
X = df.to_numpy()
|
|
37
|
+
|
|
38
|
+
if drop_constant:
|
|
39
|
+
constant = [c for c in range(X.shape[1]) if len(np.unique(X[:, c])) == 1]
|
|
40
|
+
X = np.delete(X, constant, axis=1)
|
|
41
|
+
col_ls = np.delete(col_ls, constant)
|
|
42
|
+
|
|
43
|
+
return X, y, col_ls
|