# How to check for “statistical significance” of categorical feature in black box models

Let's say we have a categorical feature $$X_i$$ and we have build a black-box classification model like xgboost with $$X_i$$ as one of many predictors. We'd like to ask a question: does $$X_i$$ affects the overall prediction and, if so, how much?

In particular $$X_i$$ could be:

• a dichotomous variable
• a n-level variable where we are interested in the potential difference between two particular levels

In white-box models like linear regression we have tests to obtain statistical significance. But can we obtain statistical-significance-alike with black box models? Does any tool from explainable artifficial intelligence field is applicable to that? Or would it be better to just perform standard t-test on the output probabilities predictions?

First, you have to encode the feature. Models only take numerical features.

Then assessing the solution:

• You can either see the feature importance of the model

• Or use an XAI tool that will help you to understand the predictions. I normally use SHAP (SHapley Additive exPlanations):is a game theoretic approach to explain the output of any machine learning model. It connects optimal credit allocation with local explanations using the classic Shapley values from game theory and their related extensions. https://github.com/slundberg/shap

• "Most models only take numerical features." – Ben Reiniger Feb 6 at 13:31
• For my understanding a model only work with numerical features. There are several implementations that use their own encoding before starting to optimize right? – Carlos Mougan Feb 6 at 13:33
• Tree models are capable of dealing with categorical variables without encoding (externally or internally): datascience.stackexchange.com/a/52103/55122 – Ben Reiniger Feb 6 at 13:38
{"ft_lang_label":"__label__en","ft_lang_prob":0.93442774,"math_prob":0.935174,"size":743,"snap":"2020-45-2020-50","text_gpt3_token_len":158,"char_repetition_ratio":0.10013532,"word_repetition_ratio":0.0,"special_character_ratio":0.19784656,"punctuation_ratio":0.07692308,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9802135,"pos_list":[0,1,2],"im_url_duplicate_count":[null,4,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-12-01T08:45:29Z\",\"WARC-Record-ID\":\"<urn:uuid:302c1355-a7dc-49b7-bac8-f6ffc2a1a177>\",\"Content-Length\":\"151522\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:443957a7-513b-4b87-9d13-22aed058d06f>\",\"WARC-Concurrent-To\":\"<urn:uuid:dcc6501a-82d6-487d-a446-330705cf54e5>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://datascience.stackexchange.com/questions/67624/how-to-check-for-statistical-significance-of-categorical-feature-in-black-box\",\"WARC-Payload-Digest\":\"sha1:WJPSN5FGDJJQUBPCTNNGLYNSK5W7GCWK\",\"WARC-Block-Digest\":\"sha1:KJVHB4MOGHJZSMP25NENPNSQ2Z2I4QS5\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141672314.55_warc_CC-MAIN-20201201074047-20201201104047-00006.warc.gz\"}"}