RuleFit: a forest distilled into a sparse linear model of readable rules.
feature <= threshold / feature > threshold, and then fits a sparse linear model (L1 / L2 penalised least squares via coordinate descent) over the rules plus the original features. The result is a small, human-readable set of rules with coefficients, keeping the predictive power of the forest but with linear-model interpretability.Classes
RuleFit regressor: forest rules distilled into a sparse linear model.
__init__( self, n_estimators: int = 100, tree_size: int = 3, max_rules: Optional[int] = None, penalty: str = 'l1', alpha: float = 0.1, max_iter: int = 1000, tol: float = 0.0001, random_state: Optional[int] = None, feature_names: Optional[List[str]] = None, )
Overview
-
Fit a
RandomForestRegressor - Walk each tree, turning every root-to-leaf path into a conjunction of
feature <= t / feature > t conditions (a rule)
- Deduplicate rules, optionally capping to the most frequent
- Build a design matrix of rule indicators plus the raw features
- Fit a penalised linear model (L1 / L2) over that design matrix via
Theory
The prediction is the linear form
where r(x) \in \{0, 1\} is a rule indicator. The coefficients are found by minimising
so an L1 penalty drives most rule coefficients to exactly zero, leaving a small readable rule set.
Parameters
n_estimators
tree_size
max_rules
None = unlimited).
penalty
alpha
max_iter
tol
random_state
feature_names
Attributes
rules_
rule_coefs_
feature_coefs_
intercept_
n_rules_
n_features_
Notes
Complexity:
- Training: forest fit O(T \cdot n \cdot \log n) plus
- Prediction: O(p) per sample.
-
When you want a small set of readable
if feature > trules - When the target has threshold effects a plain linear model misses
- When you need sparse, auditable coefficients
References
See Also
>>> from tuiml.algorithms.glassbox import RuleFitRegressor
>>> import numpy as np
>>> X = np.array([[i] for i in range(40)], dtype=float)
>>> y = np.where(X.ravel() < 20.0, 0.0, 5.0)
>>> reg = RuleFitRegressor(n_estimators=50, tree_size=2, random_state=0)
>>> _ = reg.fit(X, y)
>>> float(np.abs(reg.predict(np.array([[25.0]]))[0] - 5.0)) < 1.5
True
>>> isinstance(reg.get_rules(), list) and len(reg.get_rules()) > 0
True
Methods
__repr__
(self) -> str
RuleFit classifier: forest rules distilled into a sparse linear model.
__init__( self, n_estimators: int = 100, tree_size: int = 3, max_rules: Optional[int] = None, penalty: str = 'l1', alpha: float = 0.1, max_iter: int = 1000, tol: float = 0.0001, random_state: Optional[int] = None, feature_names: Optional[List[str]] = None, )
Overview
-
Fit a
RandomForestClassifier - Walk each tree, turning every root-to-leaf path into a conjunction of
feature <= t / feature > t conditions (a rule)
- Deduplicate rules, optionally capping to the most frequent
- Encode the binary labels as 0/1 and build a design matrix of rule
- Fit a penalised linear model (L1 / L2) over that design matrix via
Theory
The score is the linear form
interpreted as the class-1 probability (a linear probability model, the approach of the original RuleFit paper), clipped to [0, 1]. Coefficients minimise a penalised least-squares objective on the 0/1 target, with L1 shrinkage yielding a sparse, readable rule set.
Parameters
n_estimators
tree_size
max_rules
None = unlimited).
penalty
alpha
max_iter
tol
random_state
feature_names
Attributes
rules_
rule_coefs_
feature_coefs_
intercept_
classes_
n_rules_
n_features_
Notes
Complexity:
- Training: forest fit O(T \cdot n \cdot \log n) plus
- Prediction: O(p) per sample.
- Binary classification where a small readable rule set is required
- When the decision boundary has threshold effects a logistic model misses
- When you want sparse, auditable coefficients
References
See Also
>>> from tuiml.algorithms.glassbox import RuleFitClassifier
>>> import numpy as np
>>> X = np.array([[i] for i in range(40)], dtype=float)
>>> y = np.where(X.ravel() < 20.0, 0, 1)
>>> clf = RuleFitClassifier(n_estimators=50, tree_size=2, random_state=0)
>>> _ = clf.fit(X, y)
>>> clf.predict(np.array([[5.0], [35.0]])).tolist()
[0, 1]
>>> isinstance(clf.get_rules(), list) and len(clf.get_rules()) > 0
True
Methods
__repr__
(self) -> str