Quickly build Explainable AI dashboards in Python (explainerdashboard library)

Creating a Classification Dashboard with Python and Heroku

Let's start by creating our own classification dashboard using Python and Heroku. To do this, we'll first go back to the show code page and copy the code from the example dashboard. We'll then create a new file called "classification_app" in our Atom IDE and paste the copied code into it. After saving the file, we'll run the app by typing "python classification_app.py" in our terminal.

When we run the app, we can see that the model was being trained and various plots were being calculated. This is because Heroku's dynos are running the calculations in the background, and they're not displayed directly on the dashboard. However, once the model has finished training, the dashboard is now available at the URL provided.

Our dashboard includes a variety of interactive features, such as feature importance, classification stats, individual predictions, and what-if analysis. The feature importance tab allows us to see the relative importance of each feature on the model's performance. The classification stats tab is very interactive and allows us to adjust thresholds and see how they affect the data.

The individual predictions tab allows us to scroll down and view the contributions of each passenger to the prediction, as well as the aggregate value of each feature. This gives us a detailed view of how each feature contributes to the model's performance. The what-if feature dependence plot shows the relationship between feature values and class values, with the option to remove outliers.

Another interactive feature is the feature interactions tab, which displays the interaction between features sets and passenger class. We can also add specific passengers to see how they affect the interaction plots. Finally, the decision trees tab allows us to view the individual decision tree inside the random forest, giving us insight into how each tree contributes to the model's performance.

The classification explainer dashboard is a powerful tool that provides detailed insights into our machine learning models. By creating and customizing our own dashboards using Python and Heroku, we can gain a deeper understanding of our data science projects and improve our predictive modeling skills. If you find value in this tutorial, please give it a like, subscribe to our channel, and hit the notification bell so you'll be notified of future videos.

Classification Stats

The classification stats tab is very interactive and allows us to adjust thresholds and see how they affect the data. We can also view the confusion matrix, precision plot, classification plot, prauc plot, rlc auc plot, lift curve, cumulative position plot, and description of each plot. The plots are all interactive, allowing us to zoom in and see detailed information.

Here is a description of each plot:

* Confusion Matrix: This plot shows the true positives, false positives, true negatives, and false negatives.

* Precision Plot: This plot shows the precision at different thresholds.

* Classification Plot: This plot shows the classification results at different thresholds.

* PRAUC Plot: This plot shows the precision-recall AUC at different thresholds.

* RLC AUC Plot: This plot shows the receiver operating characteristic AUC at different thresholds.

* Lift Curve: This plot shows the lift of different predictions at different thresholds.

* Cumulative Position Plot: This plot shows the cumulative position of different predictions at different thresholds.

All of these plots provide valuable insights into our machine learning model's performance and can help us improve our predictive modeling skills. By using these interactive features, we can gain a deeper understanding of our data science projects and make more informed decisions.

Individual Predictions

The individual predictions tab allows us to scroll down and view the contributions of each passenger to the prediction. We can also see how each feature contributes to the prediction for each passenger. This gives us a detailed view of how each feature affects the model's performance for each specific passenger.

Here is an example of what we can see in this tab:

* Passenger ID: This shows the unique identifier for each passenger.

* Predicted Class: This shows the predicted class for each passenger.

* Feature Contributions: This shows the contribution of each feature to the prediction for each passenger.

* Relative Percent Effect: This shows the relative percent effect of each feature on the model's performance.

By viewing this information, we can gain a deeper understanding of how our machine learning models are making predictions and identify areas where we can improve their performance.

Feature Interactions

The feature interactions tab allows us to display the interaction between features sets and passenger class. We can also add specific passengers to see how they affect the interaction plots. This gives us insight into how the interactions between features affect the model's performance for different passengers.

Here is an example of what we can see in this tab:

* Feature Sets: This shows the feature sets used in the plot.

* Passenger Class: This shows the passenger class used in the plot.

* Interaction Plot: This shows the interaction between the feature set and passenger class.

By viewing this information, we can gain a deeper understanding of how our machine learning models are making predictions and identify areas where we can improve their performance.

Decision Trees

The decision trees tab allows us to view the individual decision tree inside the random forest. This gives us insight into how each tree contributes to the model's performance and how they're used to make predictions.

Here is an example of what we can see in this tab:

* Tree ID: This shows the unique identifier for each tree.

* Decision Rule: This shows the decision rule used by each tree.

* Node Values: This shows the node values used by each tree.

* Leaf Class: This shows the leaf class used by each tree.

By viewing this information, we can gain a deeper understanding of how our machine learning models are making predictions and identify areas where we can improve their performance.

"WEBVTTKind: captionsLanguage: enin this video i'm going to be showing you how you could quickly build an explainable ai dashboard in python and so without further ado we're starting right now so the explainable ai dashboard that we're going to be building today will be based on the explainer dashboard python library and so you could go ahead and go to the github page where more details will be provided about this python library here you can see an animated image of what the web application will look like but before going there let's first start by installing it so you could either install it using pip or conda and so i have already installed this on my computer and let's have a look at what this explainer dashboard is all about and so if you're using algorithms built using one of these python libraries then you could also make use of the explainer dashboard for quickly deploying a dashboard web application let's have a look so this is generally what the web application will look like so i'll provide you the link to this github page as well and some of the plots that will support the explainable ai are provided here so as you may know shap is a popular library in python that provides you a glimpse of the underlying mechanism on how features contribute to the model's prediction performance and so you could get a glimpse on the contribution of the features toward the prediction and other plots that you could also create using this dashboard includes the permutation importance meaning that if you shuffle a feature well the model performance deteriorates and so i've actually made a prior video about permutation and how that could be used to judge whether your model is robust or arise from chance prediction so you could also check that video out and i'll provide you a link to it another plot is the partial dependence plot and as mentioned here you could evaluate the contribution of the individual features on the model's performance and other plots that will allow you to observe the contribution of features would be the shaft interaction values so it essentially decomposes the shot value into the direct effect and interaction has and aside from that you could also show the model performance plots for classification models you could display the model performance via precision plots confusion matrix roc auc plot pr auc plot etc and for regression models you could show the goodness of fit plots the residual plots etc let's have a look further and so here are some of the example code that you could use to build your dashboard app and this is for the classification and this is for the regression okay so you could check out the full details of this github which provides a lot of in-depth explanation on how you could implement this explainer dashboard and so let me take you to the documentation of this library so the documentation is also another great resource that you can have a look and it explains very well how you could implement the various functions provided by the explainer dashboard as you can see here and they do provide some code that you could just copy and paste into your script files and run and so let me show you this explainer dashboard heroku app and this provides a very well laid out high level overview of what of some of the possible dashboards that you can create and so this includes the classifier dashboard the regression dashboard the multi-class dashboard and also the custom dashboard and so the great thing about this website is that you could click on the example so that you could see the web app in action or you could click on show code and this will provide you with the code that you could just copy and paste and you could modify to implement your explainer dashboard web application okay and this is the custom one and the custom one is a bit more sophisticated because you can customize the layout and the look of the dashboard web application and it also provides you with information on how you could just install the library all right so let's have a look at the example dashboard and this is the classification model let me reload it so in this website i'm not sure why the plots are not displayed it's probably running in the background or it might take some time to load okay so it's already loaded up so probably the model was being trained and so nothing was shown and now that the model has finished training it is now displayed here okay so why don't we create our own let me go back go to show code and let's copy this and i'll go to the atom ide create a new file i'll call it app or actually i'll call it classification app i'll paste it there save it go to terminal i'll first activate my contact environment and so feel free to activate your own content environments let's see let's explain our dashboard all right and so i'm going to run this by typing in python classification app.py enter you can see here that the model was being trained and the various plots was being calculated and so the heroku app was probably running all of these calculations all right so now the dashboard is finished and it is now available at the url provided here or here you could go to either one so let me just copy the first one then all right and so this is the web application that is run locally on my own computer so you can see the feature importance tab the classification stats tab individual predictions tab what if feature dependence feature interactions and also the decision tree and you could also have a look at the positive class the survived or the non-survived okay and so the shaft values and the permutation importance so you see here the relative importance of each features on the model's performance let's have a look at the classification stats so here is very interactive and you could adjust the various thresholds and the data will be accordingly updated okay and this is the confusion matrix same here you could access the threshold this is the precision plot this is the classification plot and also very interactive the prauc plot and also the rlc auc plot so a great thing is that they also provide you with a description of the plot so here they describe that rlc auc plot is a trade-off between the false positive and false negative while the pr auc plot is a trade-off between position and recall they also have the lift curve the cumulative position and as always you could also adjust the threshold okay let's have a look at the individual predictions so you could scroll down here in the drop down and have a look at the individual passengers and you could have look at which features contributed to the prediction of each of these passengers and if you change the passenger then the contribution will also change okay this is the contribution of each feature on the model contributions table how each feature contributes to the prediction and you can get a relative percent on the effect of each feature on the model prediction okay and this is what if this is feature dependence and you can have a look at the aggregate value of the shaft and so essentially it looks just identical to the typical feature importance plot that you get from the genie index when using the random forest and so this is the aggregate view so you can zoom in and have a look at the detailed view and you can see the positive and the negative contributions of each feature on the model's performance and when you add it up together in an aggregated view it looks like the random forest genie index and here on the shop dependence you can see the relationship between feature values and chat value if you hover on it it provides you with some more detail as you can see here and you could also have this function of removing outliers you click on it and outliers are removed okay so very interactive let's have a look at the feature interactions so you could display the interaction between features sets and passenger class and then this is what you see or if you change and then you also see the interactions of these two features you could also add a particular passenger and you get the updated interaction plot okay let's have a look at the decision trees all right and so here you can see the individual decision tree inside the random forest so this is something that typically you wouldn't see when you built a random forest model using psychic learn so you'll probably just see the end outcome but with this dashboard you can actually see how each of the trees are contributing to the model performance and so here you see the baseline of the pooled results from decision trees inside the random forest all right and so this is the classification explainer dashboard and you could do the same for the regression dashboard and also you could play around with the multi-class dashboard as well as customizing your own dashboard here and so if you find value in this video please give it a like subscribe if you haven't already and make sure to hit on the notification bell so that you will be notified of the next video and as always the best way to learn data science is to do data science and please enjoy the journeyin this video i'm going to be showing you how you could quickly build an explainable ai dashboard in python and so without further ado we're starting right now so the explainable ai dashboard that we're going to be building today will be based on the explainer dashboard python library and so you could go ahead and go to the github page where more details will be provided about this python library here you can see an animated image of what the web application will look like but before going there let's first start by installing it so you could either install it using pip or conda and so i have already installed this on my computer and let's have a look at what this explainer dashboard is all about and so if you're using algorithms built using one of these python libraries then you could also make use of the explainer dashboard for quickly deploying a dashboard web application let's have a look so this is generally what the web application will look like so i'll provide you the link to this github page as well and some of the plots that will support the explainable ai are provided here so as you may know shap is a popular library in python that provides you a glimpse of the underlying mechanism on how features contribute to the model's prediction performance and so you could get a glimpse on the contribution of the features toward the prediction and other plots that you could also create using this dashboard includes the permutation importance meaning that if you shuffle a feature well the model performance deteriorates and so i've actually made a prior video about permutation and how that could be used to judge whether your model is robust or arise from chance prediction so you could also check that video out and i'll provide you a link to it another plot is the partial dependence plot and as mentioned here you could evaluate the contribution of the individual features on the model's performance and other plots that will allow you to observe the contribution of features would be the shaft interaction values so it essentially decomposes the shot value into the direct effect and interaction has and aside from that you could also show the model performance plots for classification models you could display the model performance via precision plots confusion matrix roc auc plot pr auc plot etc and for regression models you could show the goodness of fit plots the residual plots etc let's have a look further and so here are some of the example code that you could use to build your dashboard app and this is for the classification and this is for the regression okay so you could check out the full details of this github which provides a lot of in-depth explanation on how you could implement this explainer dashboard and so let me take you to the documentation of this library so the documentation is also another great resource that you can have a look and it explains very well how you could implement the various functions provided by the explainer dashboard as you can see here and they do provide some code that you could just copy and paste into your script files and run and so let me show you this explainer dashboard heroku app and this provides a very well laid out high level overview of what of some of the possible dashboards that you can create and so this includes the classifier dashboard the regression dashboard the multi-class dashboard and also the custom dashboard and so the great thing about this website is that you could click on the example so that you could see the web app in action or you could click on show code and this will provide you with the code that you could just copy and paste and you could modify to implement your explainer dashboard web application okay and this is the custom one and the custom one is a bit more sophisticated because you can customize the layout and the look of the dashboard web application and it also provides you with information on how you could just install the library all right so let's have a look at the example dashboard and this is the classification model let me reload it so in this website i'm not sure why the plots are not displayed it's probably running in the background or it might take some time to load okay so it's already loaded up so probably the model was being trained and so nothing was shown and now that the model has finished training it is now displayed here okay so why don't we create our own let me go back go to show code and let's copy this and i'll go to the atom ide create a new file i'll call it app or actually i'll call it classification app i'll paste it there save it go to terminal i'll first activate my contact environment and so feel free to activate your own content environments let's see let's explain our dashboard all right and so i'm going to run this by typing in python classification app.py enter you can see here that the model was being trained and the various plots was being calculated and so the heroku app was probably running all of these calculations all right so now the dashboard is finished and it is now available at the url provided here or here you could go to either one so let me just copy the first one then all right and so this is the web application that is run locally on my own computer so you can see the feature importance tab the classification stats tab individual predictions tab what if feature dependence feature interactions and also the decision tree and you could also have a look at the positive class the survived or the non-survived okay and so the shaft values and the permutation importance so you see here the relative importance of each features on the model's performance let's have a look at the classification stats so here is very interactive and you could adjust the various thresholds and the data will be accordingly updated okay and this is the confusion matrix same here you could access the threshold this is the precision plot this is the classification plot and also very interactive the prauc plot and also the rlc auc plot so a great thing is that they also provide you with a description of the plot so here they describe that rlc auc plot is a trade-off between the false positive and false negative while the pr auc plot is a trade-off between position and recall they also have the lift curve the cumulative position and as always you could also adjust the threshold okay let's have a look at the individual predictions so you could scroll down here in the drop down and have a look at the individual passengers and you could have look at which features contributed to the prediction of each of these passengers and if you change the passenger then the contribution will also change okay this is the contribution of each feature on the model contributions table how each feature contributes to the prediction and you can get a relative percent on the effect of each feature on the model prediction okay and this is what if this is feature dependence and you can have a look at the aggregate value of the shaft and so essentially it looks just identical to the typical feature importance plot that you get from the genie index when using the random forest and so this is the aggregate view so you can zoom in and have a look at the detailed view and you can see the positive and the negative contributions of each feature on the model's performance and when you add it up together in an aggregated view it looks like the random forest genie index and here on the shop dependence you can see the relationship between feature values and chat value if you hover on it it provides you with some more detail as you can see here and you could also have this function of removing outliers you click on it and outliers are removed okay so very interactive let's have a look at the feature interactions so you could display the interaction between features sets and passenger class and then this is what you see or if you change and then you also see the interactions of these two features you could also add a particular passenger and you get the updated interaction plot okay let's have a look at the decision trees all right and so here you can see the individual decision tree inside the random forest so this is something that typically you wouldn't see when you built a random forest model using psychic learn so you'll probably just see the end outcome but with this dashboard you can actually see how each of the trees are contributing to the model performance and so here you see the baseline of the pooled results from decision trees inside the random forest all right and so this is the classification explainer dashboard and you could do the same for the regression dashboard and also you could play around with the multi-class dashboard as well as customizing your own dashboard here and so if you find value in this video please give it a like subscribe if you haven't already and make sure to hit on the notification bell so that you will be notified of the next video and as always the best way to learn data science is to do data science and please enjoy the journey\n"