在工作室 (傳統) 中遷移執行 R 指令碼模組

重要

Machine Learning 工作室 (傳統) 的支援將於 2024 年 8 月 31 日結束。 建議您在該日期之前轉換成 Azure Machine Learning

自 2021 年 12 月 1 日起,您將無法建立新的 Machine Learning 工作室 (傳統) 資源 (工作區與 Web 服務方案)。 在 2024 年 8 月 31 日之前,您可以繼續使用現有的 Machine Learning 工作室 (傳統) 實驗與 Web 服務。

ML 工作室 (傳統) 文件即將淘汰,未來將不再更新。

在本文中,您將了解如何在 Azure Machine Learning 中重建工作室 (傳統) 執行 R 指令碼模組。

如需從工作室 (傳統) 移轉的詳細資訊,請參閱移轉概觀文章

執行 R 指令碼

Azure Machine Learning 設計工具現在會在 Linux 上執行。 工作室 (傳統) 可在 Windows 上執行。 由於平台變更,您必須在移轉期間調整執行 R 指令碼,否則管線將會失敗。

若要從工作室 (傳統) 移轉執行 R 指令碼模組,您必須以標準函式取代 maml.mapInputPortmaml.mapOutputPort 介面。

下表摘要說明 R 指令碼模組的變更:

功能 Studio (傳統) Azure Machine Learning 設計工具
指令碼介面 maml.mapInputPortmaml.mapOutputPort 函式介面
平台 Windows Linux
可透過網際網路存取 No Yes
記憶體 14 GB 相依於計算 SKU

如何更新 R 指令碼介面

以下是工作室 (傳統) 中的範例執行 R 指令碼模組的內容:

# Map 1-based optional input ports to variables 
dataset1 <- maml.mapInputPort(1) # class: data.frame 
dataset2 <- maml.mapInputPort(2) # class: data.frame 

# Contents of optional Zip port are in ./src/ 
# source("src/yourfile.R"); 
# load("src/yourData.rdata"); 

# Sample operation 
data.set = rbind(dataset1, dataset2); 

 
# You'll see this output in the R Device port. 
# It'll have your stdout, stderr and PNG graphics device(s). 

plot(data.set); 

# Select data.frame to be sent to the output Dataset port 
maml.mapOutputPort("data.set"); 

以下是設計工具中更新的內容。 請注意,maml.mapInputPortmaml.mapOutputPort 已由標準函式介面 azureml_main 取代。

azureml_main <- function(dataframe1, dataframe2){ 
    # Use the parameters dataframe1 and dataframe2 directly 
    dataset1 <- dataframe1 
    dataset2 <- dataframe2 

    # Contents of optional Zip port are in ./src/ 
    # source("src/yourfile.R"); 
    # load("src/yourData.rdata"); 

    # Sample operation 
    data.set = rbind(dataset1, dataset2); 


    # You'll see this output in the R Device port. 
    # It'll have your stdout, stderr and PNG graphics device(s). 
    plot(data.set); 

  # Return datasets as a Named List 

  return(list(dataset1=data.set)) 
} 

如需詳細資訊,請參閱設計工具執行 R 指令碼模組參考

從網際網路安裝 R 套件

Azure Machine Learning 設計工具可讓您直接從 CRAN 安裝套件。

這是相較於工作室 (傳統) 的改進。 由於工作室 (傳統) 會在無法存取網際網路的沙箱環境中執行,因此您必須在 zip 套件組合中上傳指令碼,才能安裝更多套件。

使用下列程式碼,在設計工具的執行 R 指令碼模組中安裝 CRAN 套件:

  if(!require(zoo)) { 
      install.packages("zoo",repos = "http://cran.us.r-project.org") 
  } 
  library(zoo) 

下一步

在本文中,您已了解如何將執行 R 指令碼模組移轉至 Azure Machine Learning。

請參閱工作室 (傳統) 移轉系列中的其他文章:

  1. 移轉概觀
  2. 移轉資料集
  3. 重建工作室 (傳統) 定型管線
  4. 重建工作室 (傳統) Web 服務
  5. 將 Machine Learning Web 服務與用戶端應用程式整合
  6. 移轉執行 R 指令碼模組