iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 24
0
Everything on Azure

Azure Machine Learning Studio系列 第 24

Azure Machine Learning Studio 使用 Python - Execute Python Script

  • 分享至 

  • xImage
  •  

Python 有許多數據分析的套件,包含:

  • NumPy (Numerical Python):
    支援高階大量的維度陣列與矩陣運算,此外也針對陣列運算提供大量的數學函式函式庫
  • Pandas:
    提供用於結構化數據集的強大數據處理能力,重塑(resharp)、分片(slice)、分塊(dice)、聚合(aggreation)、篩選(filter)
  • SciPy:
    提供豐富的數學統計函數
  • Sciki-learn:
    提供大量機器學習能力,包含分類(Classification)、回歸(Regression)、分群(Clustering)、維度縮減(dimensionality reduction)、模型選擇和資料前處理功能
  • matplotlib:
    可以輕易生成圖表及可視化結果

在 Azure Machine Learning 中,可以使用 Execute Python Script,透過 Rython 語言擴充功能,和 Execute R Script 的用法類似,直接將程式碼貼至 Python Script 區域就可以執行,下圖為預設的 Python 程式碼內容,若執行成功會看到 Execute Python Script 出現綠勾勾,若失敗則會顯示紅驚嘆號,失敗原因可以從屬性下方的 View output log 查看

https://ithelp.ithome.com.tw/upload/images/20181106/20111935MMVGYm063t.png

https://ithelp.ithome.com.tw/upload/images/20181106/20111935buVZd0sN7B.png

使用 Python Pandas 的 scatter_matrix( ) 函式來建立鳶尾花資料的散佈圖矩陣

  1. 新增 Iris Two Class Data 鳶尾花分類資料集
    https://ithelp.ithome.com.tw/upload/images/20181106/20111935nB1uZtKOi1.png

  2. 新增 Execute Python Script,將資料集輸出接至 Execute Python Script 的第一個輸入,Python Script 區域輸入以下 Python 語言:

    # The script MUST contain a function named azureml_main
    # which is the entry point for this module.
    
    # imports up here can be used to 
    
    # The entry point function can contain up to two input arguments:
    #   Param<dataframe1>: a pandas.DataFrame
    #   Param<dataframe2>: a pandas.DataFrame
    def azureml_main(dataframe1):
    
        # Execution logic goes here
        import matplotlib
        matplotlib.use("agg")
    
        from pandas.tools.plotting import scatter_matrix
        import matplotlib.pyplot as plt
    
        fig = plt.figure();
        ax= fig.gca()
        scatter_matrix(dataframe1,ax=ax)
    
        # If a zip file is connected to the third input port is connected,
        # it is unzipped under ".\Script Bundle". This directory is added
        # to sys.path. Therefore, if your zip file contains a Python file
        # mymodule.py you can import it using:
        # import mymodule
    
        # Return value must be of a sequence of pandas.DataFrame
        fig.savefig("scatter.png")
        return dataframe1,
    

    https://ithelp.ithome.com.tw/upload/images/20181106/20111935g0ekOzTAVZ.png

  3. 執行完成後,滑鼠右鍵點選 Python Device 的 Visualize 檢視結果
    https://ithelp.ithome.com.tw/upload/images/20181106/20111935w08pDYdaBr.png

  4. 可以看到以下所有欄位的散佈圖矩陣:
    https://ithelp.ithome.com.tw/upload/images/20181106/20111935HiAFvlzA8k.png

參考文章:在 Azure Machine Learning Studio 中執行 Python 機器學習服務指令碼


上一篇
Azure Machine Learning Studio 迴歸 Regression
下一篇
Azure Machine Learning Studio 推薦模型 Train Matchbox Recommender
系列文
Azure Machine Learning Studio30
.

尚未有邦友留言

立即登入留言