Skip to main content

Optimization-Based Rule Learning for Classification

Project description

RuleOpt

Optimization-Based Rule Learning for Classification

RuleOpt is an optimization-based rule learning algorithm designed for classification problems. Focusing on scalability and interpretability, RuleOpt utilizes linear programming for rule generation and extraction. An earlier version of this work is available in our journal paper.

The Python library ruleopt is capable of extracting rules from ensemble models, and it also implements a novel rule generation scheme. The library ensures compatibility with existing machine learning pipelines, and it is especially efficient for tackling large-scale problems.

Here are a few highlights of ruleopt:

  • Efficient Rule Generation and Extraction: Leverages linear programming for scalable rule generation (stand-alone machine learning method) and rule extraction from trained random forest and boosting models.
  • Interpretability: Prioritizes model transparency by assigning costs to rules in order to achieve a desirable balance with accuracy.
  • Integration with Machine Learning Libraries: Facilitates smooth integration with well-known Python libraries scikit-learn, LightGBM, and XGBoost, and existing machine learning pipelines.
  • Extensive Solver Support: Supports a wide array of solvers, including HiGHS, Gurobi and CPLEX.

Installation

To install ruleopt, use the following pip command:

pip install ruleopt

Usage

To use ruleopt, you need to initialize the ruleopt class with your specific parameters and fit it to your data. Here's a basic example:

from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris

from ruleopt import RUGClassifier
from ruleopt.rule_cost import Gini
from ruleopt.solver import HiGHSSolver

# Set a random state for reproducibility
random_state = 42

# Load the Iris dataset
X, y = load_iris(return_X_y=True)

# Split the dataset into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=random_state
)

# Define tree parameters
tree_parameters = {"max_depth": 3, "class_weight": "balanced"}

solver = HiGHSSolver()
rule_cost = Gini()

# Initialize the RUGClassifier with specific parameters
rug = RUGClassifier(
    solver=solver,
    random_state=random_state,
    max_rmp_calls=20,
    rule_cost=rule_cost,
    **tree_parameters,
)

# Fit the RUGClassifier to the training data
rug.fit(X_train, y_train)

# Predict the labels of the testing set
y_pred = rug.predict(X_test)

Documentation

For more detailed information about the API and advanced usage, please refer to the full documentation.

Contributing

Contributions are welcome! If you'd like to improve ruleopt or suggest new features, feel free to fork the repository and submit a pull request.

License

ruleopt is released under the BSD 3-Clause License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ruleopt-1.2.1-cp313-cp313-win_amd64.whl (568.8 kB view details)

Uploaded CPython 3.13Windows x86-64

ruleopt-1.2.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ruleopt-1.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ruleopt-1.2.1-cp313-cp313-macosx_11_0_arm64.whl (570.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ruleopt-1.2.1-cp312-cp312-win_amd64.whl (569.0 kB view details)

Uploaded CPython 3.12Windows x86-64

ruleopt-1.2.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ruleopt-1.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ruleopt-1.2.1-cp312-cp312-macosx_11_0_arm64.whl (571.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ruleopt-1.2.1-cp311-cp311-win_amd64.whl (568.6 kB view details)

Uploaded CPython 3.11Windows x86-64

ruleopt-1.2.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ruleopt-1.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ruleopt-1.2.1-cp311-cp311-macosx_11_0_arm64.whl (572.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ruleopt-1.2.1-cp310-cp310-win_amd64.whl (568.8 kB view details)

Uploaded CPython 3.10Windows x86-64

ruleopt-1.2.1-cp310-cp310-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

ruleopt-1.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

ruleopt-1.2.1-cp310-cp310-macosx_11_0_arm64.whl (573.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file ruleopt-1.2.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: ruleopt-1.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 568.8 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ruleopt-1.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 764a2758d6ffe62d6337ba3003a52f470cf7621ca83340cafe8e9565770013ac
MD5 6d6a10131dc2398fc97350784c489c07
BLAKE2b-256 c82a708383f2ea28a763a4664744fc1ca6654e179cae3a690cd745c32f96750b

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ef156371a31d13c166f5e64944d603d3672b2f4558451805bb9fbed4b08b0d6
MD5 d1cbbcc0105cbe5f4ac35c0a478cedf0
BLAKE2b-256 4b6b7b41b665f7836f32169ef4dad1cb490cb5eb279c100680bd666b77570d79

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2fd2e410db98e34f714bd222288106bc245fd2358e4a1851c6fac9d86b4907a1
MD5 be9b06a27ee8e8c621d9b936b7baa113
BLAKE2b-256 8bbfbe39e33910c104d887e9ad0c4d30791298a7e992b0945b55e145bc7f7874

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7dcdbfa3769369f29acf8c6ebe156b2a1144f90bd27f2bf801f6a88f6fbc5a63
MD5 491622e5fbb061be4924d55fdf44c00a
BLAKE2b-256 c54a5a8af1018c84b0e388c64f6631ec69aa01c348fe3e12445056d24e4a9ab7

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: ruleopt-1.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 569.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ruleopt-1.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6f2d13de9b218aaaf1154d23cbffcd598a5da187a306e9cb130a0ed3c8ab345f
MD5 362202872287264856afee18f668e3c0
BLAKE2b-256 a9e1c44a4f9c2e9156c78ccd6972990958e36a966a2e8123f1c06cccd006637e

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b9b0e14479590fe87e59f3620390e7fecc408d7f38d1bc4b578a1334a5ea4181
MD5 6dc8b0241c4296904886b27c55215077
BLAKE2b-256 b18ac40442e206a3556cd561d636b47bf6401bbd4c59e5af4199da4d2c8d45b4

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 401fc58d684eb87dd61eba5dc35aa2394c649f75ef2143bc879c11cf41772d7c
MD5 5b7c695b12f56ba5ab46d9d399630e9e
BLAKE2b-256 53569569653486e0685ee0ed578617464ed19ddcd0171cf0770ee0603f93b3db

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 545deb87f3d8fc33fb6d9bc2f6c14c492652bbec6c4a8bee9c622edfef3c9380
MD5 cdf05efd7e775ee2467c88b9a7555a8b
BLAKE2b-256 b6ddcb950fc27378cf81612657b7bebdfe2e78d43c86a8b1d3d0d6a899cbf144

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: ruleopt-1.2.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 568.6 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ruleopt-1.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 afcd1f98ee7101d17c9997754a1074be07c848a2a4a3855b1f0a94c90d503670
MD5 d1d767f680e8f22b6580fa48627bf4e6
BLAKE2b-256 5595d1230a2ad65db3a746a2731e0812109c8523ed87867e077a8d988f2c9d8d

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aec9cc7f07504b0c62c35ea2baedab75024bff4b886d2d51f4b5c9f7ebd41afb
MD5 638f2482f64b012f576a89e146a24fa7
BLAKE2b-256 8933d10a83d051a799a1469e633c8e939fc1b7e5ad08452d3aead8827c6f4ba3

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a3542e7c088b7ab0c7063b3443ee2be72ac8afcd93c6e737cc3d213d38cb725f
MD5 81c043b174689fd20c239114011eaddd
BLAKE2b-256 f4cea33123f010e5146436c9fb4cb7992b6e0c3ba56a856b6924e949d5cb4f52

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 40111edbb27e8d84b54a6c53d94b0544ab2cab9cb963bf2fe35fd4624fce9feb
MD5 05a421b6f2455dbec86a55ad162cc42e
BLAKE2b-256 c2b528b1b00c70c063926c0fcea6cd5c14d6101e78f038cf54c51ec5821e8a4d

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: ruleopt-1.2.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 568.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ruleopt-1.2.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0f5c934be24cb11f57453a885ecd655659e6f064ec73ee41de9e606b629a63ec
MD5 2687923e283fe7843967c49fa651227d
BLAKE2b-256 42aa773a3585b9da1e255e262af914aeb82eae837bb878d65939272c612ba6af

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e5c66ab5ba10de36010626ff8736d218b48fb095aa79aeb72ba2dcafda39888c
MD5 8803c32831b668dd38b12cd8780b35f0
BLAKE2b-256 19faf5e2c648592e11e6397be481cbf29de46be4ddc87b1d1c107833bbe6ca46

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c447abc4ef35f5b20a3d83fd1d5f6a59dd4607a705402cc68be9ab6073c3c91f
MD5 2752a946bbacce48372990f644cb123b
BLAKE2b-256 6fb7fef3a586fb3c15a39887c5a7c4e8ec72ea6a435c5d20c214283222b6af72

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruleopt-1.2.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 83f8ef7f2b67efb0166280e4af5e082c26df841481b01d7f4fc22b45a9ff9ca7
MD5 9cafc9991e3cab394c0f16f9e06aa971
BLAKE2b-256 77b1e9b66c0b310afeacc94cc567563fcd91f9095a38ead6b85204fcbfbe458f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page