Last active
August 9, 2023 03:05
-
-
Save joshreini1/e302e81cc200b8a5c4bf0b78a75b2c77 to your computer and use it in GitHub Desktop.
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
! pip install truera | |
from truera.client.truera_workspace import TrueraWorkspace #import truera | |
from truera.client.truera_authentication import TokenAuthentication # import authentication | |
tru = TrueraWorkspace("https://app.truera.net", TokenAuthentication("ADD YOUR AUTH TOKEN")) | |
tru.add_project("My project", score_type="CHOOSE A SCORE TYPE: regression, classification, probits or logits") | |
tru.add_data_collection("data_collection_1") # the schema that will hold your data "splits" and model | |
tru.add_data( | |
data = data, | |
data_split_name = "train", | |
column_spec=ColumnSpec( | |
id_col_name = "id", | |
pre_data_col_names=["X1","X2"], | |
label_col_names="target") | |
) | |
tru.add_python_model("model_1", my_model_object) #add python model | |
tru.set_data_split("train") | |
preds = tru.get_ys_pred().reset_index(names = "id") | |
tru.add_data( | |
data = preds, | |
data_split_name = "train", | |
column_spec=ColumnSpec( | |
id_col_name="id", | |
prediction_col_names="prediction") | |
) | |
tru.set_influence_type("shap") | |
# reduce settings for speed | |
tru.set_num_internal_qii_samples(100) | |
tru.set_num_default_influences(100) | |
explainer = tru.get_explainer("train") | |
infs = explainer.get_feature_influences().reset_index(names = "id") | |
model_output_context = ModelOutputContext(model_name='model_1', | |
score_type='regression', | |
background_split_name='train', | |
influence_type='kernel-shap') | |
tru.add_data( | |
data = infs, | |
data_split_name = "train", | |
column_spec = ColumnSpec( | |
id_col_name = "id", | |
feature_influence_col_names = ["X1_influence","X2_influence"]), | |
model_output_context=model_output_context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment