<jupyter_start><jupyter_text>Model in-prod, debugging, run: "PTD-80"<jupyter_code>import pickle
import shap

import neptune.new as neptune
import pandas as pd
import xgboost as xgb

from sklearn.impute import SimpleImputer
from sklearn.model_selection import train_test_split
rnd_state = 987245
base_namespace = "model_debugging"
run_id = "PTD-80"<jupyter_output><empty_output><jupyter_text>Fetch project and resume run<jupyter_code>project = neptune.get_project(name="common/project-tabular-data")

run = neptune.init(
    project="common/project-tabular-data",
    run=run_id,
    monitoring_namespace=f"{base_namespace}/monitoring",
)<jupyter_output><empty_output><jupyter_text>Download model from the run<jupyter_code>run["model_training/pickled_model"].download("xgb.model")
with open("xgb.model", "rb") as file:
    bst = pickle.load(file)<jupyter_output><empty_output><jupyter_text>Prepare data<jupyter_code>data = pd.read_csv('../data/train.csv')
data.dropna(axis=0, subset=['SalePrice'], inplace=True)
y = data.SalePrice
X = data.drop(['SalePrice'], axis=1).select_dtypes(exclude=['object'])<jupyter_output><empty_output><jupyter_text>Run model debugging logic and log results  Look at specific trees<jupyter_code>ax = xgb.plot_tree(bst, num_trees=5)
run[f"{base_namespace}/trees"].log(neptune.types.File.as_image(ax.figure))
ax = xgb.plot_tree(bst, num_trees=6)
run[f"{base_namespace}/trees"].log(neptune.types.File.as_image(ax.figure))<jupyter_output><empty_output><jupyter_text>SHAP explainers<jupyter_code>shap.initjs()
explainer = shap.TreeExplainer(bst)
shap_values = explainer.shap_values(X)
shap.force_plot(explainer.expected_value, shap_values[0,:], X.iloc[0,:])
shap.force_plot(explainer.expected_value, shap_values, X)
shap.summary_plot(shap_values, X)<jupyter_output><empty_output><jupyter_text>Mark run as "debugged" and close it<jupyter_code>run["sys/tags"].add("debugged")
run.stop()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13835828600929273, 'fraction_numerical': 0.008260196179659268, 'mean_word_length': 9.09375, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '331992', 'license': 'MIT', 'n_tokens_mistral': 756, 'n_tokens_neox': 739, 'n_words': 103, 'path': 'notebooks/model-in-prod-debug.ipynb', 'repo_name': 'neptune-ai/project-tabular-data', 'size': '1937'}