<jupyter_start><jupyter_text>Multiprocessing: n_workersSpecify the number of processes used for the calculation of SHAP values.  `n_workers=-1` means using all processors.  If the program is running on a multi-core server, we can expect a reduction in computation time.<jupyter_code>%%time
shap_value = explainer.shap_values(X_test_std[i], n_workers=-1)<jupyter_output>CPU times: user 56.8 ms, sys: 152 ms, total: 209 ms
Wall time: 716 ms<jupyter_text>Skip the calculation of SHAP values: skip_featuresWe can skips the calculation of SHAP values for the features specified in `skip_features`.  The features to be skipped can be specified by feature name or index number.  Note that we need to pass a list of feature names to KernelExplainer's `feature_names` argument when specifying `skip_features` by feature names.<jupyter_code>explainer = shappack.KernelExplainer(model.predict, X_train_std[0:100], feature_names=boston.feature_names)
skip_features=["PTRATIO", "TAX"]
shap_value = explainer.shap_values(X_test_std[i], skip_features=skip_features, n_workers=-1)
feature_names = np.delete(boston.feature_names, explainer.skip_idx)
x_test = np.delete(X_test[i], explainer.skip_idx)
shap.force_plot(explainer.base_val[0], shap_value, x_test, feature_names)<jupyter_output><empty_output><jupyter_text>Incorporate own characteristic function: characteristic_funcWe can incorporate own implemented characteristic functions into the `characteristic_func` argument.<jupyter_code>def my_characteristic_func(instance, subsets, model, data):
    n_subsets = subsets.shape[0]
    n_data = data.shape[0]
    synth_data = np.tile(data, (n_subsets, 1))
    for i, subset in enumerate(subsets):
        offset = i * n_data
        features_idx = np.where(subset == 1.0)[0]
        synth_data[offset : offset + n_data, features_idx] = instance[:, features_idx][0]
    model_preds = model(synth_data)
    ey = np.zeros(n_subsets)
    for i in range(n_subsets):
        ey[i] = np.min(model_preds[i * n_data : i * n_data + n_data])
    return ey
shap_value = explainer.shap_values(X_test_std[i], characteristic_func=my_characteristic_func)
shap.force_plot(explainer.base_val[0], shap_value, X_test[i], boston.feature_names)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09521680822530175, 'fraction_numerical': 0.012516763522574878, 'mean_word_length': 6.05993690851735, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, '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': '390229', 'license': 'MIT', 'n_tokens_mistral': 765, 'n_tokens_neox': 737, 'n_words': 191, 'path': 'examples/Kernel_SHAP_regression.ipynb', 'repo_name': 'tsurubee/shappack', 'size': '2237'}