<jupyter_start><jupyter_text>Rulefit demo - Titanic Dataset  H2O Rulefit algorithmRulefit algorithm combines tree ensembles and linear models to take advantage of both methods: a tree ensemble accuracy and a linear model interpretability. The general algorithm fits a tree ensebmle to the data, builds a rule ensemble by traversing each tree, evaluates the rules on the data to build a rule feature set and fits a sparse linear model (LASSO) to the rule feature set joined with the original feature set.For more information, refer to: http://statweb.stanford.edu/~jhf/ftp/RuleFit.pdf by <NAME> and <NAME>. Demo exampleWe will train a rulefit model to predict the rules defining whether or not someone will survive:<jupyter_code>import h2o
from h2o.estimators import H2ORuleFitEstimator, H2ORandomForestEstimator

# init h2o cluster
h2o.init()
df = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/gbm_test/titanic.csv",
                       col_types={'pclass': "enum", 'survived': "enum"})
x =  ["age", "sibsp", "parch", "sex", "pclass"]

# Split the dataset into train and test
train, test = df.split_frame(ratios=[.8], seed=1234)<jupyter_output>Parse progress: |████████████████████████████████████████████████████████████████| (done) 100%<jupyter_text>Using the `algorithm` parameter, a user can set whether algorithm will use DRF or GBM to fit a tree enseble. Using the `min_rule_length` and `max_rule_length` parameters, a user can set interval of tree enseble depths to be fitted. The bigger this interval is, the more tree ensembles will be fitted (1 per each depth) and the bigger the rule feature set will be.Using the `max_num_rules` parameter, the maximum number of rules to return can be set.Using the `model_type` parameter, the type of base learners in the enseble can be set.Using the `rule_generation_ntrees` parameter, the number of trees for tree enseble can be set.<jupyter_code>rfit = H2ORuleFitEstimator(algorithm="drf", 
                               min_rule_length=1, 
                               max_rule_length=10, 
                               max_num_rules=100, 
                               model_type="rules_and_linear",
                               rule_generation_ntrees=50,
                               seed=1234)
rfit.train(training_frame=train, x=x, y="survived")<jupyter_output>rulefit Model Build progress: |██████████████████████████████████████████████████| (done) 100%
Model Details
=============
H2ORuleFitEstimator :  RuleFit
Model Key:  RuleFit_model_python_1636562504000_1


Rulefit Model Summary:<jupyter_text>The output for the Rulefit model includes:    - model parameters    - rule importences in tabular form    - training and validation metrics of the underlying linear model<jupyter_code>from IPython.display import display
display(rfit.rule_importance())<jupyter_output>Rule Importance:
{'fraction_non_alphanumeric': 0.11261730969760167, 'fraction_numerical': 0.01737921445950643, 'mean_word_length': 3.970639032815199, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '600640', 'license': 'Apache-2.0', 'n_tokens_mistral': 958, 'n_tokens_neox': 844, 'n_words': 296, 'path': 'h2o-py/demos/rulefit_demo.ipynb', 'repo_name': 'LongerVision/h2o-3', 'size': '2900'}