<jupyter_start><jupyter_text>Read data 6 kidds of data (judgment calls)age 2, invariantinclude or exclude subvariables<jupyter_code>df_train_old, df_tune_old, df_test_old = Dataset().get_data(split_age=AgeSplit.OLD,load_csvs=False)
df_train_old = df_train_old.drop(columns=['AgeinYears','Race','Gender'])
df_tune_old = df_tune_old.drop(columns=['AgeinYears','Race','Gender'])
X_train_old = df_train_old.drop(columns="outcome")
y_train_old = df_train_old["outcome"].values
X_tune_old = df_tune_old.drop(columns="outcome")
y_tune_old = df_tune_old["outcome"].values

df_train_young, df_tune_young, df_test_young = Dataset().get_data(split_age=AgeSplit.YOUNG,load_csvs=False)
df_train_young = df_train_young.drop(columns=['AgeinYears','Race','Gender'])
df_tune_young = df_tune_young.drop(columns=['AgeinYears','Race','Gender'])
X_train_young = df_train_young.drop(columns="outcome")
y_train_young = df_train_young["outcome"].values
X_tune_young = df_tune_young.drop(columns="outcome")
y_tune_young = df_tune_young["outcome"].values

df_train_all, df_tune_all, df_test_all = Dataset().get_data(split_age=AgeSplit.AGEINVARIANT,load_csvs=False)
df_train_all = df_train_all.drop(columns=['AgeinYears','Race','Gender'])
df_tune_all = df_tune_all.drop(columns=['AgeinYears','Race','Gender'])
X_train_all = df_train_all.drop(columns="outcome")
y_train_all = df_train_all["outcome"].values
X_tune_all = df_tune_all.drop(columns="outcome")
y_tune_all = df_tune_all["outcome"].values
dset = Dataset()
# NOTE: This is just an example!
judg_calls = dset.get_judgement_calls_dictionary_default()
judg_calls["preprocess_data"]["step7_AMS"] = 1
judg_calls["preprocess_data"]["step8_OSI"] = 1
judg_calls["preprocess_data"]["step9_HEMA"] = 1
judg_calls["preprocess_data"]["step10_SFx"] = 1
judg_calls["preprocess_data"]["step11_SFxBas"] = 1
judg_calls["preprocess_data"]["step12_Clav"] = 1
judg_calls["preprocess_data"]["step13_NeuroD"] = 1
judg_calls["preprocess_data"]["step14_Vomit"] = 1
judg_calls["preprocess_data"]["step15_HA"] = 1
judg_calls["preprocess_data"]["step16_Seiz"] = 1
judg_calls["preprocess_data"]["step17_LOC"] = 1
judg_calls["extract_features"]["GCS"] = False

df_train_old_parent, df_tune_old_parent, df_test_old_parent = dset.get_data(split_age=AgeSplit.OLD,load_csvs=False, **judg_calls)
df_train_old_parent = df_train_old_parent.drop(columns=['AgeinYears','Race','Gender'])
df_tune_old_parent = df_tune_old_parent.drop(columns=['AgeinYears','Race','Gender'])
X_train_old_parent = df_train_old_parent.drop(columns="outcome")
y_train_old_parent = df_train_old_parent["outcome"].values
X_tune_old_parent = df_tune_old_parent.drop(columns="outcome")
y_tune_old_parent = df_tune_old_parent["outcome"].values

df_train_young_parent, df_tune_young_parent, df_test_young_parent = Dataset().get_data(split_age=AgeSplit.YOUNG,load_csvs=False, **judg_calls)
df_train_young_parent = df_train_young_parent.drop(columns=['AgeinYears','Race','Gender'])
df_tune_young_parent = df_tune_young_parent.drop(columns=['AgeinYears','Race','Gender'])
X_train_young_parent = df_train_young_parent.drop(columns="outcome")
y_train_young_parent = df_train_young_parent["outcome"].values
X_tune_young_parent = df_tune_young_parent.drop(columns="outcome")
y_tune_young_parent = df_tune_young_parent["outcome"].values

df_train_all_parent, df_tune_all_parent, df_test_all_parent = Dataset().get_data(split_age=AgeSplit.AGEINVARIANT,load_csvs=False, **judg_calls)
df_train_all_parent = df_train_all_parent.drop(columns=['AgeinYears','Race','Gender'])
df_tune_all_parent = df_tune_all_parent.drop(columns=['AgeinYears','Race','Gender'])
X_train_all_parent = df_train_all_parent.drop(columns="outcome")
y_train_all_parent = df_train_all_parent["outcome"].values
X_tune_all_parent = df_tune_all_parent.drop(columns="outcome")
y_tune_all_parent = df_tune_all_parent["outcome"].values<jupyter_output>kwargs {'clean_data': {}, 'preprocess_data': {'step1_injMech': False, 'step5_missSubGCS': True, 'step5_fake15GCS': True, 'step5_fake14GCS': True, 'step7_AMS': 1, 'step8_OSI': 1, 'step9_HEMA': 1, 'step10_SFx': 1, 'step11_SFxBas': 1, 'step12_Clav': 1, 'step13_NeuroD': 1, 'step14_Vomit': 1, 'step15_HA': 1, 'step15_HAStart': False, 'step16_Seiz': 1, 'step16_SeizOccur': False, 'step17_LOC': 1, 'step19_Drugs': False, 'step20_ActNormal': True}, 'extract_features': {'HEMA_umbrella': False, 'SFxPalp_umbrella': False, 'SFxBas_umbrella': False, 'AMS_umbrella': False, 'OSI_umbrella': False, 'Clav_umbrella': False, 'NeuroD_umbrella': False, 'Vomit_umbrella': False, 'HA_umbrella': False, 'Seiz_umbrella': False, 'LOC_umbrella': False, 'GCS': False, 'remove_constVal': True}}
kwargs {'clean_data': {}, 'preprocess_data': {'step1_injMech': False, 'step5_missSubGCS': True, 'step5_fake15GCS': True, 'step5_fake14GCS': True, 'step7_AMS': 1, 'step8_OSI': 1, 'step9_HEMA': 1, 'step10_SFx': 1, 'step11_SFxBas': 1[...]<jupyter_text>Fit models<jupyter_code>import os
import pickle as pkl
from os.path import join as oj

import matplotlib.pyplot as plt
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier, plot_tree

import numpy as np
import pandas as pd

import imodels
from rulevetting.api import validation


MODELS_DIR = './models'
os.makedirs(MODELS_DIR, exist_ok=True)

outcome_def = 'outcome'  # output
def predict_and_save(model, model_name, X_train, X_tune, y_train, y_tune, MODELS_DIR = './models'):
    '''Plots cv and returns cv, saves all stats
    '''
    os.makedirs(MODELS_DIR, exist_ok=True)
    results = {'model': model}
    for x, y, suffix in zip([X_train, X_tune],
                            [y_train, y_tune],
                            ['_train', '_tune']):
        stats, threshes = validation.all_stats_curve(y, model.predict_proba(x)[:, 1],
                                                     plot=suffix == '_tune')
        for stat in stats.keys():
            results[stat + suffix] = stats[stat]
        results['threshes' + suffix] = threshes
    pkl.dump(results, open(oj(MODELS_DIR, model_name + '.pkl'), 'wb'))
    return stats, threshes
feature_names=list(X_train_old).copy()
feature_names_ageinvariant=list(X_train_all).copy()
feature_names_parent=list(X_train_old_parent).copy()
feature_names_ageinvariant_parent=list(X_train_all_parent).copy()

def print_metrics(suffix, X_train, X_tune, y_train, y_tune, MODELS_DIR = './models'):
    os.makedirs(MODELS_DIR, exist_ok=True)
    vals = {s: [] for s in ['sens', 'spec', 'ppv', 'npv', 'lr+', 'lr-', 'brier_score', 'f1']}
    fnames = []
    for fname in sorted(os.listdir(MODELS_DIR)):
        if 'pkl' in fname:
            if not fname[:-4] == 'rf':
                r = pkl.load(open(oj(MODELS_DIR, fname), 'rb'))
                threshes = np.array(r['threshes' + suffix])
                m = r['model']

                # add more stats
                for x, y, suff in zip([X_train, X_tune],
                                      [y_train, y_tune],
                                      ['_train', '_tune']):
                    if suff == suffix:
                        stats, threshes = validation.all_stats_curve(y, m.predict_proba(x)[:, 1],
                                                                     plot=suffix == '_tune')
                        preds_proba = m.predict_proba(x)[:, 1]
                        brier_score = metrics.brier_score_loss(y, preds_proba)

                # pick best vals
                sens = np.array(r['sens' + suffix])
                spec = np.array(r['spec' + suffix])
                best_idx = np.argmax(5 * sens + spec)
                for k in vals.keys():
                    if not k == 'brier_score':
                        #                         print('k', k)
                        vals[k].append(stats[k][best_idx])
                vals['brier_score'].append(brier_score)
                fnames.append(fname[:-4])
    stats = pd.DataFrame.from_dict(vals)
    stats.index = fnames
    return (stats).round(2).transpose()<jupyter_output><empty_output><jupyter_text>RuleFit  Children old<jupyter_code># fit model with random seeds. Pick the best one
rules_repeated = np.array([])
for i in range(100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_old, y_train_old, feature_names=feature_names)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_old_' + str(i), X_train_old, X_tune_old, y_train_old, y_tune_old,
                                      MODELS_DIR = './models/rulefit_children_old/')
# one kind of stability between different seeds. Is it reasonable?
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_old_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:8], rules_repeated_times[1][:8])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_old, X_tune_old, y_train_old, y_tune_old, MODELS_DIR = './models/rulefit_children_old/')
stats_list['_train']
stats_list['_tune']
# sort based on sens
stats_list['_tune'].iloc[:,(-np.array(stats_list['_tune'][0:1])).argsort().squeeze()[:10]]
# interpretation
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=96)
rulefit.fit(X_train_old, y_train_old, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>Children young<jupyter_code>rules_repeated = np.array([])
for i in range(100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_young, y_train_young, feature_names=feature_names)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_young_' + str(i), X_train_young, X_tune_young, y_train_young, y_tune_young,
                                      MODELS_DIR = './models/rulefit_children_young/')
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_young_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:10], rules_repeated_times[1][:10])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_young, X_tune_young, y_train_young, y_tune_young, MODELS_DIR = './models/rulefit_children_young/')
stats_list['_train']
stats_list['_tune']
stats_list['_tune'].iloc[:,(-np.array(stats_list['_tune'][0:1])).argsort().squeeze()[:10]]
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=74)
rulefit.fit(X_train_young, y_train_young, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=85)
rulefit.fit(X_train_young, y_train_young, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>Children all<jupyter_code>rules_repeated = np.array([])
for i in range(100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_all, y_train_all, feature_names=feature_names_ageinvariant)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_all_' + str(i), X_train_all, X_tune_all, y_train_all, y_tune_all,
                                      MODELS_DIR = './models/rulefit_children_all/')
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_all_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:10], rules_repeated_times[1][:10])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_all, X_tune_all, y_train_all, y_tune_all, MODELS_DIR = './models/rulefit_children_all/')
stats_list['_train']
stats_list['_tune']
stats_list['_tune'].iloc[:,(-np.array(stats_list['_tune'][0:1])).argsort().squeeze()[:10]]
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=15)
rulefit.fit(X_train_all, y_train_all, feature_names=feature_names_ageinvariant)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=64)
rulefit.fit(X_train_all, y_train_all, feature_names=feature_names_ageinvariant)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>Children old parent<jupyter_code>rules_repeated = np.array([])
for i in range(100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_old_parent, y_train_old_parent, feature_names=feature_names_parent)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_old_parent_' + str(i), X_train_old_parent, X_tune_old_parent, y_train_old_parent, y_tune_old_parent,
                                      MODELS_DIR = './models/rulefit_children_old_parent/')
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_old_parent_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:15], rules_repeated_times[1][:15])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_old_parent, X_tune_old_parent, y_train_old_parent, y_tune_old_parent, MODELS_DIR = './models/rulefit_children_old_parent/')
stats_list['_train']
stats_list['_tune']
stats_list['_tune'].iloc[:,(-np.array(stats_list['_tune'][0:1])).argsort().squeeze()[:10]]
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=53)
rulefit.fit(X_train_old_parent, y_train_old_parent, feature_names=feature_names_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=89)
rulefit.fit(X_train_old_parent, y_train_old_parent, feature_names=feature_names_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>Children young parent<jupyter_code>print(sum(y_train_young_parent))
print(sum(y_tune_young_parent))<jupyter_output>5
0<jupyter_text>Cannot fit here.<jupyter_code>rules_repeated = np.array([])
for i in range(9,100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_young_parent, y_train_young_parent, feature_names=feature_names_parent)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_young_parent_' + str(i), X_train_young_parent, X_tune_young_parent, y_train_young_parent, y_tune_young_parent,
                                      MODELS_DIR = './models/rulefit_children_young_parent/')
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_young_parent_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:16], rules_repeated_times[1][:16])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_young_parent, X_tune_young_parent, y_train_young_parent, y_tune_young_parent, MODELS_DIR = './models/rulefit_children_young_parent/')
stats_list['_train']
stats_list['_tune']<jupyter_output><empty_output><jupyter_text>Children all parent<jupyter_code>rules_repeated = np.array([])
for i in range(100):
    rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=i)
    rulefit.fit(X_train_all_parent, y_train_all_parent, feature_names=feature_names_ageinvariant_parent)

    rules = rulefit.get_rules()
    rules = rules[rules.coef != 0].sort_values("support", ascending=False)
    rules_repeated = np.concatenate(
        (rules_repeated, 
         np.unique(np.array(rules['rule'].values.tolist()))),
        axis=None)
    
    stats, threshes = predict_and_save(rulefit, 'rulefit_children_all_parent_' + str(i), X_train_all_parent, X_tune_all_parent, y_train_all_parent, y_tune_all_parent,
                                      MODELS_DIR = './models/rulefit_children_all_parent/')
rules_repeated_times = np.unique(rules_repeated, return_counts=True)
rules_repeated_times = (rules_repeated_times[0][(-rules_repeated_times[1]).argsort()],
                        rules_repeated_times[1][(-rules_repeated_times[1]).argsort()])
pkl.dump(rules_repeated_times, open(oj('./models/rulefit_res/', 'children_all_parent_rules_repeated_times' + '.pkl'), 'wb'))
rules_repeated_times
(rules_repeated_times[0][:14], rules_repeated_times[1][:14])
suffixes = ['_train', '_tune']  # _train, _test1, _test2
stats_list = {}
for i, suffix in enumerate(suffixes):
    stats_list[suffix] = print_metrics(suffix, X_train_all_parent, X_tune_all_parent, y_train_all_parent, y_tune_all_parent, MODELS_DIR = './models/rulefit_children_all_parent/')
stats_list['_train']
stats_list['_tune']
stats_list['_tune'].iloc[:,(-np.array(stats_list['_tune'][0:1])).argsort().squeeze()[:30]]
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=0)
rulefit.fit(X_train_all_parent, y_train_all_parent, feature_names=feature_names_ageinvariant_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=63)
rulefit.fit(X_train_all_parent, y_train_all_parent, feature_names=feature_names_ageinvariant_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>Interpretation  sensitivity increases but F1 score decreases. What is a good model?Stability for changing random seeds for rulefit is not meaningful. We want a good model, but not a stable but bad model.Different seeds account for going into the local optimum.  age>=2, include subvaribles sensitivity,specificity.95 .81 Most important: SFxBasHem, SFxPalpDepress, NeuroDCranial, GCSEye, GCSVerbal, OSICut, SeizLen, LocLen, AMSSlow<jupyter_code>rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=96)
rulefit.fit(X_train_old, y_train_old, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>age<2, include subvaribles sensitivity,specificity.81 .62.69 .92 Most important: SFxBasHem, GCSEye, GCSVerbal, HASeverity, AMSSlow, ClavNeck, LocLen<jupyter_code>rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=74)
rulefit.fit(X_train_young, y_train_young, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=85)
rulefit.fit(X_train_young, y_train_young, feature_names=feature_names)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>age invariant , include subvaribles sensitivity,specificity.95 .64 Most important: LocLen, SeizLen, SFxPalp, SFxBasHem, SFxPalpDepress, SFxBasOto, AMSSlow, AMSRepeat, AMSOth, AMSAgitated, NeuroDMotor, Vomit, ClavPar, HemaSize<jupyter_code>rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=15)
rulefit.fit(X_train_all, y_train_all, feature_names=feature_names_ageinvariant)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>age >=2, no subvariables sensitivity,specificity1.00 .62.89 .90 Most important: High_impact_InjSev, Seiz, GCSTotal,SFxBas, Vomit, AMS, LOCSeparate<jupyter_code>rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=53)
rulefit.fit(X_train_old_parent, y_train_old_parent, feature_names=feature_names_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=89)
rulefit.fit(X_train_old_parent, y_train_old_parent, feature_names=feature_names_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output><jupyter_text>age <2, no subvariables Cannot run  age invariant , no subvaribles sensitivity,specificity1.00 .28.89 .81 - use this Most important: Vomit, Seiz, AMS, SFxPalp, SFxBas<jupyter_code>rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=0)
rulefit.fit(X_train_all_parent, y_train_all_parent, feature_names=feature_names_ageinvariant_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')
rulefit = imodels.RuleFitClassifier(max_rules=10, random_state=63)
rulefit.fit(X_train_all_parent, y_train_all_parent, feature_names=feature_names_ageinvariant_parent)

rules = rulefit.get_rules()
rules = rules[rules.coef != 0].sort_values("support", ascending=False)

rules[['rule', 'coef', 'support']].style.background_gradient(cmap='viridis')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13997997997998, 'fraction_numerical': 0.014294294294294295, 'mean_word_length': 6.053374752894663, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '116723', 'license': 'MIT', 'n_tokens_mistral': 9431, 'n_tokens_neox': 9000, 'n_words': 1283, 'path': 'rulevetting/projects/tbi_pecarn/notebooks/Rulefit_Xin.ipynb', 'repo_name': 'andleb/rule-vetting', 'size': '24975'}