skope-rules
raw JSON → 1.0.1 verified Mon Apr 27 auth: no python
skope-rules is a Python library for interpretable machine learning. It extracts decision rules from tree-based models to provide transparent predictions. Last version: 1.0.1 (released 2023). Low release cadence.
pip install skope-rules Common errors
error ImportError: No module named 'skope_rules' ↓
cause Incorrect import path; module is installed as 'skrules'.
fix
Run 'from skrules import SkopeRules' instead.
error AttributeError: 'SkopeRules' object has no attribute 'predict_proba' ↓
cause skope-rules does not provide predict_proba by default.
fix
Use clf.predict() for class labels, or check the documentation for alternatives.
Warnings
gotcha The import path uses 'skrules' not 'skope_rules'. Using 'from skope_rules import SkopeRules' will raise ImportError. ↓
fix Use 'from skrules import SkopeRules'.
gotcha SkopeRules.score() returns a list of scores (one per class) for multi-class problems, not a single accuracy. This differs from sklearn convention. ↓
fix Use clf.score(X_test, y_test) which returns per-class scores. For overall accuracy, compute manually: (clf.predict(X_test) == y_test).mean()
deprecated Parameter 'max_depth_duplication' is deprecated in favor of 'max_depth' in future versions? Not officially deprecated yet, but be cautious with parameter names. ↓
fix Use 'max_depth' if available, else 'max_depth_duplication'.
Imports
- SkopeRules wrong
from skope_rules import SkopeRulescorrectfrom skrules import SkopeRules
Quickstart
from skrules import SkopeRules
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf = SkopeRules(max_depth_duplication=2, n_estimators=10, random_state=42)
clf.fit(X_train, y_train)
scores = clf.score(X_test, y_test)
print(scores)