This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# register the model | |
tru.add_python_model(model_name_v2, | |
models[model_name_v2], | |
train_split_name='2014-CA', | |
train_parameters = train_params) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tru.tester.get_model_test_results(test_types = ["fairness"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tru.tester.add_fairness_test(test_name = "Impact Ratio Test", | |
data_split_name_regex = ".", | |
all_data_collections=True, | |
all_protected_segments=True, | |
metric = "DISPARATE_IMPACT_RATIO", | |
fail_if_outside = [0.8, 1.25]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tru.add_segment_group("Sex", {"Male": "Sex == 'Male'", "Female": "Sex == 'Female'"}) | |
tru.set_as_protected_segment(segment_group_name = "Sex", segment_name = "Female") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import trushap, and optionally alias as shap to preserve your SHAP code. | |
from truera.client.experimental.trushap import trushap as shap | |
# Initialize the explainer. | |
# Include TruEra authentication (optional) to add the model to your TruEra deployment. | |
explainer = shap.Explainer(model, connection_string = CONNECTION_STRING, token = TOKEN) | |
# Calculate shapley values AND add data split to your TruEra deployment. | |
shap_values = explainer(X, id_col_name = "id") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data_collections = tru.get_data_collections() | |
for dc in data_collections: | |
tru.set_data_collection(dc) | |
data_splits = ["train","2010","2011","2012","2013","2014","2015","2016"] | |
ref_model = "linear_" + dc | |
for split in data_splits: | |
tru.tester.add_performance_test( | |
data_split_name = split, | |
metric = 'AUC', | |
warn_threshold_type = "ABSOLUTE", #this is default, specifying for clarity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tru.set_data_collection("data_collection") | |
splits = tru.get_data_splits() | |
for split in splits: | |
tru.set_data_collection("data_collection") | |
tru.set_data_split(split) | |
xs = tru.get_xs() | |
ys = tru.get_ys() | |
tru.set_data_collection("data_collection_v2") | |
ys_mean = ys.mean() | |
ys_std = ys.std() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class target_encoder(BaseEstimator, TransformerMixin): | |
def __init__(self): | |
pass | |
def fit(self, X, y = None): | |
return self | |
def transform(self, X, y = None): | |
#target encode lat and long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class target_encoder(BaseEstimator, TransformerMixin): | |
def __init__(self): | |
pass | |
def fit(self, X, y = None): | |
return self | |
def transform(self, X, y = None): | |
#target encode lat and long |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
project_name = 'Fire_Party' | |
tru.set_environment('local') | |
tru.add_project(project_name, score_type='probits') | |
extra_data_columns = ['year'] | |
train_split_name = 'train' | |
burned_fraction_th = 0.01 | |
for window_size in range(1,11): | |
key = f'{window_size}year_window' | |
print(key) | |
tru.add_data_collection(key) |