LoginSignup
1
0

More than 5 years have passed since last update.

Azure Machine Learning StudioのPython Scriptで外部パッケージを使う方法

Last updated at Posted at 2018-07-29

Azure Machine Learning StudioのPython Scriptは、通常ではAnacondaに標準で入っているパッケージしか使うことができませんが、Anacondaにない外部のパッケージを用いる方法があります。

こちらの記事を参考にしました。
https://blogs.technet.microsoft.com/machinelearning/2016/10/12/deep-neural-network-in-azure/

ローカル環境での作業

MacまたはLinux環境を想定しています。

適当な場所で、適当なディレクトリを作成。今回はbundleとします。
作成したディレクトリのlibに、使いたいパッケージをインストール。

mkdir bundle
pip install --no-deps --target=bundle/lib [package_name]

bundleのzipを作成します。

zip bundle.zip -r bundle

Azure Machine Leaning Studioでの作業

ローカルで作成したzipをdatasetsにアップロード。
フッターバーの+NEW -> DATASET -> FROM LOCAL FILE からアップロードできます。

アップロードされたら適当なexperimentを開いて、Execute Python Scriptモジュールを配置。
そして、アップロードしたzipのdatasetモジュールを配置して、2つのモジュールを結合。

Experiments_-_Microsoft_Azure_Machine_Learning_Studio.png

Execute Python Scriptを選択して、モジュールのスクリプトに以下のコードを追加。
今回はモジュールのPython VersionはAnaconda 4.0/Python 3.5を想定しています。

import os, pkg_resources

BUNDLE_DIR = os.path.join(os.getcwd(), "Script Bundle", "bundle")
LIB_DIR = os.path.join(BUNDLE_DIR, "lib")
env = pkg_resources.Environment([LIB_DIR])
packageList, errorList = pkg_resources.working_set.find_plugins(env)
for package in packageList:
    print("Adding", package)
    pkg_resources.working_set.add(package)
for error in errorList:
    print("Error", error)

このコード以下より、パッケージをimportして使うことができます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0