在 Python 中針對自動化 ML 實驗進行疑難排解
在本指南中,您將了解如何使用 Azure Machine Learning SDK 來識別和解決自動化機器學習實驗的問題。
版本相依性
AutoML
對較新封裝版本的相依性中斷相容性。 在 SDK 1.13.0 版之後,因為先前 AutoML
套件中的舊版本與目前的新版本不相容,所以不會在舊版 SDK 中載入模型。
可能的錯誤如下:
找不到模組錯誤,例如,
No module named 'sklearn.decomposition._truncated_svd'
匯入錯誤,例如,
ImportError: cannot import name 'RollingOriginValidator'
,屬性錯誤,例如,
AttributeError: 'SimpleImputer' object has no attribute 'add_indicator'
解決方案取決於 AutoML
SDK 定型版本:
如果
AutoML
SDK 定型版本大於 1.13.0,則您需要pandas == 0.25.1
和scikit-learn==0.22.1
。如果版本不符,請使用下列命令,將 scikit-learn 和 (或) pandas 升級到正確版本,
pip install --upgrade pandas==0.25.1 pip install --upgrade scikit-learn==0.22.1
如果
AutoML
SDK 定型版本小於或等於 1.12.0,則您需要pandas == 0.23.4
和sckit-learn==0.20.3
。如果版本不符,請使用下列命令,將 scikit-learn 和 (或) pandas 降級到正確的版本,
pip install --upgrade pandas==0.23.4 pip install --upgrade scikit-learn==0.20.3
安裝程式
自 1.0.76 版以來的 AutoML
封裝變更都規定先解除安裝舊版本,才能更新為新版本。
ImportError: cannot import name AutoMLConfig
從 v1.0.76 以前的 SDK 版本升級至 v1.0.76 或更新版本之後,如果您遇到此錯誤,請執行下列命令來解決錯誤:
pip uninstall azureml-train automl
,然後pip install azureml-train-automl
。 automl_setup.cmd 指令碼會自動執行此動作。automl_setup 失敗
在 Windows 上,從 Anaconda Prompt 執行 automl_setup。 安裝 Miniconda。
確定已安裝 conda 64 位元 4.4.10 版或更新版本。 您可以使用
conda info
命令來檢查位元。platform
應該為win-64
(Windows) 或osx-64
(Mac)。 若要檢查版本,請使用conda -V
命令。 如果已安裝舊版本,您可以使用此命令來更新:conda update conda
。 若要檢查 32 位元,請執行確定已安裝 conda。
Linux -
gcc: error trying to exec 'cc1plus'
如果發生
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
錯誤,請為您的 Linux 發行版本安裝 GCC 組建工具。 例如,在 Ubuntu 上,使用sudo apt-get install build-essential
命令。傳遞新名稱做為 automl_setup 的第一個參數,以建立新的 conda 環境。 使用
conda env list
來檢視現有的 conda 環境,使用conda env remove -n <environmentname>
來移除環境。
automl_setup_linux.sh 失敗:如果 automl_setup_linus sh 在 Ubuntu linux 上失敗,並出現錯誤:
unable to execute 'gcc': No such file or directory
- 確定已啟用輸出連接埠 53 和 80。 在 Azure 虛擬機器上,您可以從 Azure 入口網站選取 VM,並按一下 [網路] 來檢查。
- 執行命令:
sudo apt-get update
- 執行命令:
sudo apt-get install build-essential --fix-missing
- 再次執行
automl_setup_linux.sh
configuration.ipynb 失敗:
- 若為本機 conda,請先確定
automl_setup
已成功執行。 - 確定 subscription_id 正確。 在 Azure 入口網站中,選取 [所有服務],然後選取 [訂用帳戶],以找出 subscription_id。 subscription_id 值不應該包含 "<" 和 ">" 字元。 例如,
subscription_id = "12345678-90ab-1234-5678-1234567890abcd"
為有效格式。 - 確定具有訂用帳戶的參與者或擁有者存取權。
- 檢查區域是否為其中一個支援的區域:
eastus2
、eastus
、westcentralus
、southeastasia
、westeurope
、australiaeast
、westus2
、southcentralus
。 - 確定可使用 Azure 入口網站存取區域。
- 若為本機 conda,請先確定
workspace.from_config 失敗:
如果
ws = Workspace.from_config()
呼叫失敗:- 確定 configuration.ipynb 筆記本已成功執行。
- 如果執行筆記本的資料夾不是在已執行
configuration.ipynb
的資料夾下,請將 aml_config 資料夾及其包含的 config.json 檔案複製到新資料夾。 Workspace.from_config 會讀取筆記本資料夾或其父資料夾的 config.json。 - 如果使用新的訂用帳戶、資源群組、工作區或區域,請務必再次執行
configuration.ipynb
筆記本。 只有當工作區已存在於指定訂用帳戶下的指定資源群組中,才能直接變更 config.json。 - 如果要變更區域,請變更工作區、資源群組或訂用帳戶。 如果工作區已存在,即使指定的區域不同,
Workspace.create
也不會建立或更新工作區。
TensorFlow
從 SDK 1.5.0 版開始,自動化機器學習預設不會安裝 TensorFlow 模型。 若要安裝 TensorFlow,並用於自動化 ML 實驗,請透過 CondaDependencies
安裝 tensorflow==1.12.0
。
from azureml.core.runconfig import RunConfiguration
from azureml.core.conda_dependencies import CondaDependencies
run_config = RunConfiguration()
run_config.environment.python.conda_dependencies = CondaDependencies.create(conda_packages=['tensorflow==1.12.0'])
Numpy 失敗
import numpy
在 Windows 中失敗:某些 Windows 環境在使用最新的 Python 3.6.8 版載入 numpy 時會發生錯誤。 如果您看到此問題,請嘗試使用 Python 3.6.7 版。import numpy
失敗:檢查自動化 ml conda 環境中的 TensorFlow 版本。 支援的版本 < 1.13。 如果版本 >= 1.13,請從環境解除安裝 TensorFlow。
您可以檢查 TensorFlow 的版本並解除安裝,如下所示:
- 啟動命令殼層,並啟用已安裝自動化 ml 封裝的 conda 環境。
- 輸入
pip freeze
並尋找tensorflow
,如果找到,則列出的版本應為 < 1.13 - 如果列出的版本不是支援的版本,請在命令殼層中執行
pip uninstall tensorflow
,並輸入 y 以確認。
jwt.exceptions.DecodeError
確切的錯誤訊息:jwt.exceptions.DecodeError: It is required that you pass in a value for the "algorithms" argument when calling decode()
。
如果 SDK 版本 <= 1.17.0,安裝可能產生不支援的 PyJWT 版本。 請檢查自動化 ml conda 環境中的 PyJWT 版本是否為支援的版本。 也就是 PyJWT 版本 < 2.0.0。
您可以如下所示檢查 PyJWT 的版本:
啟動命令殼層,並啟用已安裝自動化 ML 封裝的 conda 環境。
輸入
pip freeze
並尋找PyJWT
,如果找到,則列出的版本應為 < 2.0.0
如果列出的版本不是支援的版本:
請考慮升級至 AutoML SDK 的最新版本:
pip install -U azureml-sdk[automl]
如果這不可行,請從環境解除安裝 PyJWT,並安裝正確的版本,如下所示:
- 在命令殼層中執行
pip uninstall PyJWT
,並輸入y
以確認。 - 使用
pip install 'PyJWT<2.0.0'
來安裝。
- 在命令殼層中執行
資料存取
針對自動化 ML 作業,您必須確保連線到 AzureFile 儲存體的檔案資料存放區具有適當的驗證認證。 否則會出現下列訊息。 了解如何更新您的資料存取驗證認證。
錯誤訊息:Could not create a connection to the AzureFileService due to missing credentials. Either an Account Key or SAS token needs to be linked the default workspace blob store.
資料結構描述
當您嘗試透過 Azure Machine Learning 工作室中的 [編輯並提交] 按鈕建立新的自動化 ML 實驗時,新實驗的資料結構描述必須符合原始實驗中使用的資料結構描述。 否則,您會看到類似下列結果的錯誤訊息。 深入了解如何從工作室 UI 編輯並提交實驗。
錯誤訊息非視覺實驗: Schema mismatch error: (an) additional column(s): "Column1: String, Column2: String, Column3: String", (a) missing column(s)
視覺資料集的錯誤訊息:Schema mismatch error: (an) additional column(s): "dataType: String, dataSubtype: String, dateTime: Date, category: String, subcategory: String, status: String, address: String, latitude: Decimal, longitude: Decimal, source: String, extendedProperties: String", (a) missing column(s): "image_url: Stream, image_details: DataRow, label: List" Vision dataset error(s): Vision dataset should have a target column with name 'label'. Vision dataset should have labelingProjectType tag with value as 'Object Identification (Bounding Box)'.
Databricks
請參閱 如何使用 Databricks (Azure Machine Learning SDK v1) 設定自動化 ML 實驗 。
預測 R2 分數永遠是零
此問題起因於在提供的定型資料中,時間序列最後的 n_cv_splits
+ forecasting_horizon
資料點都是相同的值。
如果您的時間序列已預料到此模式,您可以將主要計量切換至標準化均方根誤差。
部署失敗
如果 SDK 版本 <= 1.18.0,則為部署建立的基礎映像可能失敗,並出現下列錯誤:ImportError: cannot import name cached_property from werkzeug
。
下列步驟可以解決此問題:
- 下載模型封裝
- 解壓縮封裝
- 使用解壓縮的資產來部署
Azure Functions 應用程式
自動化 ML 目前不支援 Azure Functions 應用程式。
範例筆記本失敗
如果範例筆記本失敗,並出現錯誤表示屬性、方法或程式庫不存在:
請確定已在 Jupyter Notebook 中選取正確的核心。 核心顯示在筆記本頁面的右上方。 預設為 azure_automl。 核心儲存為筆記本的一部分。 如果您切換至新的 conda 環境,則必須在筆記本中選取新的核心。
- 針對 Azure Notebooks,應該為 Python 3.6。
- 針對本機 conda 環境,應該為您在 automl_setup 中指定的 conda 環境名稱。
若要確定筆記本適用於您使用的 SDK 版本,
- 在 Jupyter Notebook 儲存格中執行
azureml.core.VERSION
,以檢查 SDK 版本。 - 您可以使用下列步驟,從 GitHub 下載前一版的範例筆記本:
- 選取 [
Branch
] 按鈕 - 瀏覽至 [
Tags
] 索引標籤 - 選取版本
- 選取 [
- 在 Jupyter Notebook 儲存格中執行
實驗節流
如果您有超過 100 個自動化 ML 實驗,這可能導致新的自動化 ML 實驗執行很久。
VNet 防火牆設定下載失敗
如果您處於虛擬網路 (VNet) 下,當您使用 AutoML NLP 時可能會遇到模型下載失敗的情形。 這是因為網路流量遭到封鎖,無法從 Azure CDN 下載模型和權杖化工具。 若要解除封鎖,請在 VNet 防火牆原則的 [應用程式規則] 設定中,允許列出下列 URL:
如需在 VNet 下設定工作區的指示,請參閱這裡。
後續步驟
深入了解模型部署的方式和位置。