開始使用免費開始

解釋情感分析的預測結果

提供給你一個 model,用來將商品評論分類為正向或負向情緒。你的任務是使用 LIME,找出在指定的 text_instance 中,哪些字詞最影響模型的預測。

用於處理輸入文字的 model_predict 函式已為你預先載入。

本練習屬於課程

Python 的 Explainable AI

檢視課程

練習說明

  • 建立一個名為 explainer 的 LIME 文字 explainer。
  • 針對給定的 text_instance,產生模型預測的解釋,並著重於前五個特徵。
  • 顯示影響模型決策的最高貢獻字詞及其權重。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

from lime.lime_text import LimeTextExplainer

text_instance = "Amazing battery life and the camera quality is perfect! I highly recommend this smartphone."

# Create a LIME text explainer
explainer = ____()

# Generate the explanation
exp = explainer.____(____, model_predict, num_features=____)

# Display the explanation
exp.____()
plt.show()
編輯並執行程式碼