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 manuscript.

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 Gurobi, CPLEX and OR-Tools.

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 ORToolsSolver

# 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 = ORToolsSolver()
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

ruleopt-1.0.1-cp312-cp312-win_amd64.whl (310.0 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

ruleopt-1.0.1-cp312-cp312-musllinux_1_1_x86_64.whl (854.3 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ x86-64

ruleopt-1.0.1-cp312-cp312-musllinux_1_1_i686.whl (812.2 kB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.1+ i686

ruleopt-1.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (852.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

ruleopt-1.0.1-cp312-cp312-macosx_11_0_arm64.whl (312.4 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

ruleopt-1.0.1-cp312-cp312-macosx_10_9_x86_64.whl (319.4 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ x86-64

ruleopt-1.0.1-cp311-cp311-win_amd64.whl (311.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

ruleopt-1.0.1-cp311-cp311-musllinux_1_1_x86_64.whl (865.6 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ x86-64

ruleopt-1.0.1-cp311-cp311-musllinux_1_1_i686.whl (834.5 kB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.1+ i686

ruleopt-1.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (862.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

ruleopt-1.0.1-cp311-cp311-macosx_11_0_arm64.whl (311.8 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

ruleopt-1.0.1-cp311-cp311-macosx_10_9_x86_64.whl (318.7 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ x86-64

ruleopt-1.0.1-cp310-cp310-win_amd64.whl (311.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

ruleopt-1.0.1-cp310-cp310-musllinux_1_1_x86_64.whl (828.2 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ x86-64

ruleopt-1.0.1-cp310-cp310-musllinux_1_1_i686.whl (793.3 kB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.1+ i686

ruleopt-1.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (821.3 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

ruleopt-1.0.1-cp310-cp310-macosx_11_0_arm64.whl (312.2 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

ruleopt-1.0.1-cp310-cp310-macosx_10_9_x86_64.whl (318.8 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ x86-64

ruleopt-1.0.1-cp39-cp39-win_amd64.whl (311.7 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

ruleopt-1.0.1-cp39-cp39-musllinux_1_1_x86_64.whl (830.3 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ x86-64

ruleopt-1.0.1-cp39-cp39-musllinux_1_1_i686.whl (796.0 kB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.1+ i686

ruleopt-1.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (823.8 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

ruleopt-1.0.1-cp39-cp39-macosx_11_0_arm64.whl (312.8 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

ruleopt-1.0.1-cp39-cp39-macosx_10_9_x86_64.whl (319.4 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ x86-64

Supported by

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