# Model Explainer

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*&#x20;

* Only **Sklearn** models will be supported in the latest version.

* Training dataset type for Data Science Lab models should be: **NumPy Array**, **Pandas Dataframe** or **Python List**.
  {% endhint %}

* Navigate to the ***Notebook*** tab.

* Open an existing Notebook or Create new Notebook.

* Write a code to create a model.

* Run the code.

<figure><img src="/files/7JVXmp4yCpt29wtFHmm7" alt=""><figcaption></figcaption></figure>

* Insert a new code cell below.
* Click the Save Model option for this newly added cell.
* A pre-defined code gets generated in the code cell to save the model.
* Save the Data Science Model by defining a name and specifying the **X**, **y** and **estimator\_type.**&#x20;
* Run the Cell after defining the required information.

<figure><img src="/files/PPaFgajTQllZgJE3TDjR" alt=""><figcaption></figcaption></figure>

* Open the ***Models*** tab option.
* Click the Ellipsis icon provided for a model.
* Click the ***Model Explainer*** option.

<figure><img src="/files/a0x3Stq3fxM2A0iczCVV" alt=""><figcaption></figcaption></figure>

* The ***Model Explainer*** page opens explaining the selected **Data Science Lab** model. The selected model in this case is of Regression type, so the Model Explainer displays Regression Explainer.
* This page displays the various tabs to explain the model.

<figure><img src="/files/Zd6xx8NrZZBZw5PP268n" alt=""><figcaption></figcaption></figure>

* The ***Feature Importance*** tab opens by default.

<figure><img src="/files/0jZTzT2CgkGLWsnKNfSz" alt=""><figcaption></figcaption></figure>

* **Feature Importance**
  * This table shows the contribution each feature has had on the prediction for a specific     observation. The contributions (starting from the population average) add up to the final prediction. This allows you to explain exactly how each prediction has been built up from all the individual ingredients in the model.
* **Individual Predictions**
  * **Select Index:** The user can select a record directly by choosing it from the dropdown or hit the *Random Index* option to randomly select a record that fits the constraints. For example, the user can select a record where the observed target value is negative but the predicted probability of the target being positive is very high. This allows the user to sample only false positives or only false negatives.
  * **Prediction:** It displays the predicted probability for each target label.
  * **Contributions Plot**: This plot shows the contribution that each feature has provided to the prediction for a specific observation. The contributions (starting from the population average) add up to the final prediction. This helps to explain exactly how each prediction has been built up from all the individual ingredients in the model.
  * **Partial Dependence Plot:** The PDP plot shows how the model prediction would change if you change one particular feature. the plot shows you a sample of observations and how these observations would change with this feature (gridlines). The average effect is shown in grey. The effect of changing the feature for a single record is shown in blue. The user can adjust how many observations to sample for the average, how many gridlines to show, and how many points along the x-axis to calculate model predictions for (grid points).
* **Individual Predictions**
  * This table shows the contribution each feature has had on the prediction for a specific observation. The contributions (starting from the population average) add up to the final prediction. This allows you to explain exactly how each prediction has been built up from all the individual ingredients in the model.
* **Feature Dependence**
  * Shap Summary: The *Shap Summary* summarizes the Shap values per feature. The user can either select an aggregate display that shows the mean absolute Shap value per feature or get a more detailed look at the spread of Shap values per feature and how they co-relate the feature value (red is high).
  * Shap Dependence: This plot displays the relation between feature values and Shap values. This allows you to investigate the general relationship between feature value and impact on the prediction. The users can check whether the model uses features in line with their intuitions, or use the plots to learn about the relationships that the model has learned between the input features and the predicted outcome.

## Classification Explainer

{% hint style="success" %}
*Check out the given walk-through to understand the Model Explainer dashboard for the Classification models.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Figrg2b2URgwMO5YmejDu%2Fuploads%2FLnR3Ca1cCIskolRJ0upJ%2FClassification_Latest.mp4?alt=media&token=4a31f3e0-be6e-456c-8b0b-d9a8f5953930>" %}

## Regression Explainer

{% hint style="success" %}
*Check out the given walk-through to understand the Model Explainer Dashboard for the Regression models.*
{% endhint %}

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Figrg2b2URgwMO5YmejDu%2Fuploads%2FkWrnJUCCTIVEjSEgTz4Z%2FDS%20Lab%20model%20-%20Regression.mp4?alt=media&token=ec577bf8-fba3-4498-b8d9-067b5cb291f3>" %}
Data Science Lab Regression Model
{% endembed %}

**Model Summary**: The user can find a number of regression performance metrics in this table that describes how well the model is able to predict the target column.

**Predicted Vs Actual Plots:** This plot shows the observed value of the target column and the predicted value of the target column. A perfect model would have all the points on the diagonal (predicted matches observed). The further away points are from the diagonal the worse the model is in predicting the target column.

#### Residuals & Plot Vs Features

Residuals: The residuals are the difference between the observed target column value and the predicted target column value. in this plot, one can check if the residuals are higher or lower for higher /lower actual /predicted outcomes. So, one can check if the model works better or worse for different target value levels.

Plot vs Features: This plot displays either residuals (difference between observed target value and predicted target value) plotted against the values of different features or the observed or predicted target value. This allows one to inspect whether the model is more inappropriate for a particular range of feature values than others.

## Forecasting Explainer

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FBLGYLEkBUnc8nVEBAuEI%2Fuploads%2F8AUcpyawkmgudnwZUmJI%2FForecasting%20Model%20Explainer.mp4?alt=media&token=96a738db-7c80-49c8-b3b7-55daf054f2db>" %}
Data Science Lab Forecasting Model
{% endembed %}

The forecasting model stats get displayed through the Timeseries visualization that presents values generated over based on the selected time.

#### Predictions

This chart will display predicted values generated by the timeseries model over a specific time period.

<figure><img src="/files/8zA94Pg3E3la0ay2dJJW" alt=""><figcaption></figcaption></figure>

#### Predicted Vs Actual

This chart displays a comparison of the predicted values with the actual obsereved vlaues over a specific period of time.

<figure><img src="/files/X5aIXOLRrCxaN2V0tiFe" alt=""><figcaption></figcaption></figure>

#### Residual

It depicts difference between the predicted and actual (residuals) values over a period of time.&#x20;

<figure><img src="/files/Fy9uW147jg6BtGd8CL3F" alt=""><figcaption></figcaption></figure>

#### Predicted Vs Actual Scatter Plot

A Scatter Plot chart is displayed depicting how well the predicted values align with the actual values.

<figure><img src="/files/Pq95gkVTDeJrMoyc0FZd" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
*<mark style="color:green;">Please Note:</mark>*&#x20;

* *The **Regression Stats tab** only differs from the **Classification Stats Tab,** All the other Tabs of the model explainer dashboard remain the same as those given for the Classification Model.*
* *Refer the*[ ***Data Science Lab Quick Start Flow***](https://docs.bdb.ai/data-science-lab-4/data-science-lab-quick-start-flow) *page to get an overview of the **Data Science Lab** module in nutshell.*&#x20;
  {% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.bdb.ai/data-science-lab-4/project/tabs-for-a-data-science-lab-project/tabs-for-tensorflow-and-pytorch-environment/notebook/notebook-page/notebook-operations/models/model-explainer.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
