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.0-cp313-cp313-win_amd64.whl (568.1 kB view details)

Uploaded CPython 3.13Windows x86-64

ruleopt-1.2.0-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.0-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.0-cp313-cp313-macosx_11_0_arm64.whl (569.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ruleopt-1.2.0-cp312-cp312-win_amd64.whl (568.3 kB view details)

Uploaded CPython 3.12Windows x86-64

ruleopt-1.2.0-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.0-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.0-cp312-cp312-macosx_11_0_arm64.whl (571.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ruleopt-1.2.0-cp311-cp311-win_amd64.whl (567.8 kB view details)

Uploaded CPython 3.11Windows x86-64

ruleopt-1.2.0-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.0-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.0-cp311-cp311-macosx_11_0_arm64.whl (571.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

ruleopt-1.2.0-cp310-cp310-win_amd64.whl (568.1 kB view details)

Uploaded CPython 3.10Windows x86-64

ruleopt-1.2.0-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.0-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.0-cp310-cp310-macosx_11_0_arm64.whl (572.8 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: ruleopt-1.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 568.1 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9098ca9d51ec1eb60aebe6ea12eab0a1a471024684aa3e008340b401a71dd130
MD5 d7fc325a3a53f1b2be5527770871a40d
BLAKE2b-256 837acab3febf849cbb0b432c10adb56fabcda27a570beaebb6e6716f7859d932

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a765fac05fbfe45139f65458c3e15a4f5818734a64e8549b3bf54a2add1542e2
MD5 e03d353b23a52f0c077bfa4ee8a96527
BLAKE2b-256 1e379ad8f274237f8b454b9e9df1b4b01cdfbbe44399d81252809c799b716e8c

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f0984942c0aab58cd1313f923a7feccd4a26ca313287d727eba79acc46ffded5
MD5 9f3e86594493536495bdc92abc64e48a
BLAKE2b-256 538d5e3c6942c6f98bf0045dbb9e9cd02bd1995875dfc104bd4a5c61712c5f5a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9e7b24dd0352c6ab49b4f26c3fa9f627252730b259b7b446c55a9b825ab04db3
MD5 4333da24183c20a8ac657f528b503fd6
BLAKE2b-256 c907031a161154eb5467e23c68b34e916582b2edfc908f2d0aff440acc89144f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleopt-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 568.3 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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 149977333a2d53eeabe1210cf91eeb463d3458a2eb11aaee37f825ae9ed11e9e
MD5 4e089d03f5de2536fc07cfc7600ba42f
BLAKE2b-256 df5505a2f83e20986de3f643e4744bfb9dc19b1f0df79a3ae6aeacc58dff7037

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4a7eaae83ffffc1c047b4bc014045aefb1c37288c6c1765e2bab75c0f7486237
MD5 5fe85f24cbbab269f10720194726a8b1
BLAKE2b-256 495713211fa288054059aa33071dd86cc991f95e6ed06f39c7be5c1cd12a3013

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 39008738def9b930de058bd748bc4e9fde650492bd81ce82ea3171c63dab4083
MD5 0d47201e5f280fea5c6179790a1d552b
BLAKE2b-256 0b84bf73f647dbbb3ac0c181d9183e448341687df8719b1805ac32daf75b0b47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1ce11eeceafc7ba57fcbbc06eb2b1141f191bd83730e58ace906aec369d113b3
MD5 20a5b4e10094fa1b7b509e246c2494a3
BLAKE2b-256 b16f28c15fe6311a8ee61da59dd34acbec1439dbde42a26d7a7714c31d9e31f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleopt-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 567.8 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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 3855fdc4c200009edd33a5db7d9b957ef4b71d6480796e477199d7445c719d66
MD5 f1c29bc2ffe98cb1db47d092117bc988
BLAKE2b-256 370eb238aedeae36c16eefc12ea2927ca72d20d54b592aea27eac5ad7955f5e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 73d68c45fed0fbf3f242a6b7145f56317b09c967b1b64e9247b473b53e5e9850
MD5 d78dbd75fedc42b74b0a8d1943ec96ab
BLAKE2b-256 7fd227eb389edddca3545b29d943ddf3cbc32592cd1e02e8ec9b185b5a237658

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3110edeed4d0b83e1821b963262f8259bd922cc17ddf145f5e7a54fc9ef08dd4
MD5 668b1fb0106b3b8acb9402d7ed17c56b
BLAKE2b-256 5e74cf5144baf11ef9112f8104e42ea15427af4364e67b2206148bf0bfda8ddb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 926dbbfa32b75c6d871b202f9de694bbe61ae6506892bdb9e603b71978226add
MD5 7476cc1eefb681ba97891be7a760ceed
BLAKE2b-256 1a858037d53f4271aae428c7d71fe16ec37db3faa0a42fe49a1183a733ebcc03

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ruleopt-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 568.1 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b114f1e0c0efab9c5dcccd5d62c774b6f766fb4ba1531f29dca6df915a2277ac
MD5 53044ecf886af66a8e6ece2f3f032eb3
BLAKE2b-256 a76b35c12e0da950474f9b3e843ed2b984d0ada99563ded5ace9aeb1b1cf7b8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4e8c6c31d0df14ede1970f35cb024659b0db66fbada57769ece0dcb3101f23b2
MD5 474b9856890203aecc16ae5b93ba6e48
BLAKE2b-256 b62d32334c6619031694bec739710efdd87b921c9e2f43600b68f9f11bdf6968

See more details on using hashes here.

File details

Details for the file ruleopt-1.2.0-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.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 84f927d8734a03443afe207a5408a861ff3d7f3d9f691dc97ba379aed23c1599
MD5 c20f734dab579899f3311b0cc2685482
BLAKE2b-256 0682ed8a6a1b841a08d64268355b16dbaa124a721cf60bf7708e08c06d3c9379

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for ruleopt-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 45c710f8ab603c7b125b518b78fa4c96d45de454df7165d590a7172467735b16
MD5 eb17034162b7e9c7c53ff8b3b66bdd48
BLAKE2b-256 e0ccd2365d26b094895b944b2e371f618561a1912d6b8e625863933cf9d898fd

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