64 – M7L7 65 Rank Shap Solution V1

So let’s implement model SHAP importances with the starter code. First we’ll calculate the SHAP values. So if you’ll recall, let’s go back up to see how we call that function. The first step was we take the SHAP library. It has a tree explainer, we create that object passing in the model, and then from that tree explainer objects we call SHAP values, pass in the training data, and also we can set the tree limit to save time. So I’m going to copy this, so we can look at it when we work with it. So here, we can say shap.TreeExplainer, pass in the model which we have passed in here. Then, from that tree explainer object, we can call a SHAP values, pass in the data which is here, and also set the tree limit, let’s set it to five as well. Next, let’s concatenate the SHAP values that are output from it. So we can do numpy.concatenate, concatenating the SHAP values list. Then, we can take the absolute value of that SHAP values matrix, and then we can take the average of that. Can set axis equal to zero, same as the example that we saw here. So it takes an average one for each column. All right, get the indices sorted in descending order. All right. So numpy.argsort, the global importances, and that’s going to be in ascending order, so let’s just reverse it. So let’s try it out. It’s going to take a few seconds to run. But then, we can check out the result. Great. So now, we can see that we sorted in descending order by importance using SHAP values. All right, please continue with the lesson.

Dr. Serendipity에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

Continue reading