此篇文章在闡述“解釋模型”,想想如果在醫療採用了機器學習的方式來診斷,而最後你問醫生,為何會這樣判斷呢?醫生若只回答:喔,因為模型跑出來就是這樣!這樣的答案一般來說是無法被接受的,同樣在判斷其他業務行為也無法說服老闆,
Oracle Data Science Model Explanations. Machine learning explainability (MLX) is the process of explaining and interpreting machine learning and deep learning models.
- Explainability: (可解釋性)The ability to explain the reasons behind a machine learning model’s prediction.
- Interpretability: (可理解性)The level at which a human can understand the explanation.
- Model-Agnostic Explanations: (模型無關解釋)Explanations treat the machine learning model and feature preprocessing as a black box, instead of using properties from the model to guide the explanation. 不論是什麼模型,可視模型為一個黑盒子
Oracle Data Science Model Explanations Types
- Global explanation: Explains the general behavior of a machine learning model as a whole. 解釋模型的標準答案的樣子
- Local explanation: Explains why the machine learning made a specific prediction. 為什麼模型會這樣判斷出預測結果?
- WhatIf Explanation: Analyzes how changes in the value of features affects the model’s prediction.分析特徵改變對預測的影響
Global Explainers
All three are model-agnostic methods.
- Feature Permutation Importance Explanations: Estimates and ranks feature importance based on the impact a feature has on the model’s predictions
- Feature Dependence Explanations: Evaluates the relationship between feature values and model target predictions
- Accumulated Local Effects: Highlights effects that specific features have on predictions of the model by partially isolating effects of other features
Feature Permutation Importance Explanations
Feature permutation importance measures the predictive value of a feature for any black box estimator, classifier, or regressor. It does this by evaluating how the prediction error increases when a feature is not available. Any scoring metric can be used to measure the prediction error. For example, F1 for classification or R2 for regression. To avoid actually removing features and retraining the estimator for each feature, the algorithm randomly shuffles the feature values effectively adding noise to the feature. Then, the prediction error of the new dataset is compared with the prediction error of the original dataset. If the model heavily relies on the column being shuffled to accurately predict the target variable, this random re-ordering causes less accurate predictions. If the model does not rely on the feature for its predictions, the prediction error remains unchanged.
Model explanation in ADS produces three types of visualizations for feature permutation importance explanations.
- Bar chart (‘bar’): The bar chart shows the model’s view of the relative feature importance.
importances.show_in_notebook()
- Box plot (‘box_plot’): The detailed box plot shows the feature importance values across the iterations of the algorithm.
importances.show_in_notebook('box_plot')
- Detailed scatter plot (‘detailed’): The detailed bar chart shows the feature importance values for each iteration of the algorithm.
importances.show_in_notebook('detailed')
Feature Dependence Explanations
Feature Dependence Explanations are model-agnostic global explanation methods that evaluate the relationship between feature values and model target predictions.
There are two explanation methods in ADS for feature dependence.
PDP
Types of PDP (Partial Dependence Plot):顯示每一個自變數的變化是如何影響預測表現
- One Feature – Continuous or discrete numerical feature: The x-axis shows the selected feature values and the y-axis shows the average predicted target value. For classification tasks, predicted value is the prediction probability. For regression, it is the raw predicted values
- One Feature – Categorical feature: Bar chart with each bar representing the average prediction from the model, the x-axis shows the different values for the selected feature.
- Two features: Heat map, x-axis, and y-axis are the selected values of the two features. Heat map color represents the average prediction from the model across all samples in the provided data set.
ICE
Types of Individual Conditional Expectation (ICE) plots:
- Continuous or discrete numerical feature – Line graphs: ICE plots every sample from the data set (when the selected feature is replaced with the given value) separately. The x-axis shows the selected feature values and the y-axis shows the predicted target. (For classification tasks, the predicted value is the prediction probability. For regression, it is the raw predicted values.) The median value can be plotted to highlight the trend.
- Categorical feature – Violin plot: The x-axis shows the different values for the selected feature and the y-axis shows the predicted target.
Accumulated Local Effects (ALE)
與部分依賴圖 (PDP) 類似,累積局部效應 (ALE) 是一種與模型無關的全局解釋方法,用於評估特徵值和目標變量之間的關係。但是,如果特徵高度相關,PDP 可能會在平均預測計算中包含不太可能的特徵值組合,因為對邊緣分佈的特徵值進行獨立操作。當特徵具有強相關性時,這會降低對 PDP 解釋的信任度。與 PDP 不同,ALE 通過對條件分佈中的預測差異進行平均和累積來處理特徵相關性,從而隔離特定特徵的影響。
- Evaluates the relationship between feature values and target variables
- More robust against correlated features than PDP
Accumulated Local Effects (ALE) Plot
- Categorical features: Visualized as vertical bar charts可視化為折線圖. Each bar represents the change in the model prediction when the selected feature has the given value compared to the average prediction. The interpretation of the value of the bar is similar to continuous features. The x-axis shows the different categorical values for the selected feature and the y-axis shows the change in the predicted value relative to the average prediction.
- Continuous or discrete numerical features: Visualized as line graphs可視化為垂直條形圖. Each line represents the change in the model prediction when the selected feature has the given value compared to the average prediction
Local Explainers
Local Interpretable Model-Agnostic explanations (LIME):
- They provide insights into why a machine learning model made a specific prediction.
- LIME tries to approximate the local behavior of the complex machine learning model with a simple, more easily interpretable surrogate model such as a linear model.
ADS LIME has three sections.
- Model
- information about the machine learning model and the model’s prediction such as the true label/value for the selected sample to explain, the predicted value from the black box model, and the prediction probabilities (classification) or prediction values (regression).
- displays the sample to explain. For tabular datasets, this is a table showing the feature names and corresponding values for this sample. For text datasets, this shows the text sample to explain.
- Explainer
- such as the underlying local explanation algorithm used (for example, LIME), the type of surrogate model (for example, linear), the number of randomly generated local samples (for example, 5000) to train the local surrogate model (Nt), whether continuous features were discretized or not.
- a legend describing how to interpret the model explanations.
- Explanations
- Feature Importance:Presents the actual local explanation
- Explanation Quality: Presents the quality by evaluating sample distance distributions and using evaluation metrics
WhatIf Explainer
The WhatIf explainer tool helps to understand how changes in an observation affect a model’s prediction. Methods include:
- Explore Sample
- explore_sample method
- Modify the values in an observation and see how the prediction changes.
- Explore Predictions
- explore_predictions method
- Explore the relationship between feature values and the model predictions.