Try using Jupyter Notebook of Azure Machine Learning

Azure Machine Learning is a cloud-based machine learning service provided by Microsoft.

Azure Machine Learning allows you to perform various machine learning techniques using the GUI, but you can also use Jupyter.

Use Jupyter Notebook with Azure Machine Learning

You can try Azure Machine Learning for free if you have a Microsoft account. Jupyter can also be used with a free plan.

See the link below for pricing details.

Price --Machine Learning | Microsoft Azure

Create a Microsoft account

If you do not have a Microsoft account, create one from the link.

Home | Microsoft Account

Create workspace

Open the link below and click the "Get Started" button to sign in to your Microsoft account.

Microsoft Azure Machine Learning Studio

When the screen that says "Workspace Not Found" appears, open Microsoft Azure Machine Learning Studio again in your browser and press the "Get Started" button.

If successful, a free workspace has been created and a screen like the one below will open.

スクリーンショット 2015-09-06 21.28.26.png

Creating a Jupyter Notebook

Click "+ NEW" at the bottom left of the screen to open the screen below. Select the Python version from NOTEBOOK.

スクリーンショット 2015-09-06 21.32.36.png

This time I will select Python2. You will be asked for the name of the notebook, so enter it appropriately.

The created Jupyter Notebook is displayed in NOTEBOOKS, so click it to open it.

スクリーンショット 2015-09-06 21.34.39.png

An empty Notebook opens. After this, you can use it as usual.

スクリーンショット 2015-09-06 21.37.55.png

Available libraries

Jupyter for Azure Machine Learning uses Anaconda, and the packages listed below are available.

Anaconda Package List — Continuum documentation

The version of Anaconda is 2.1, which is a little old and may not be the latest depending on the package.

Integration of Azure Machine Learning and Jupyter Notebook

Azure Machine Learning's Jupyter Notebook has the Azure Machine Learning Python client installed. You can use this to operate Azure Machine Learning and exchange data.

Azure/Azure-MachineLearning-ClientLibrary-Python

Connect to workspace

First, connect to the workspace you are currently using. You can find the workspace ID and token required for the connection from SETTINGS in studio.

from azureml import Workspace
ws = Workspace(
    workspace_id="YOUR_WORKSPACE_ID", 
    authorization_token="YOUR_AUTHORIZATION_TOKEN",
    endpoint="https://studio.azureml.net"
)

Use a dataset

You can check the available datasets as follows.

ws.datasets

You can get the data by specifying the name of the dataset you want to use and convert it to a dataframe with `` `to_dataframe```.

df = ws.datasets['Bike Rental UCI dataset'].to_dataframe()

Get data from Experiment

To get the intermediate data of Experiment with Jupyter, enter the data in "Convert to CSV".

スクリーンショット 2015-09-19 15.22.39.png

Click the output port of "Convert to CSV" and select "Generate Data Access Code" to display the code for retrieving the intermediate data as a data frame. (The code for connecting to the workspace is also displayed, but I got an error if the endpoint was not set. It worked when I added the endpoint as in [above](#Connect to workspace).)

Add Jupyter data to your Azure Machine Learning dataset

You can add data that you are working with in Jupyter to your Azure Machine Learning dataset.

Use add_from_dataframe when adding to the dataset.

import pandas as pd
import numpy as np
from sklearn.datasets import load_boston

boston = load_boston()
df = pd.DataFrame(
  np.column_stack([boston.data, boston.target]),
  columns=boston.feature_names
)

dataset = ws.datasets.add_from_dataframe(
    dataframe=df,
    data_type_id='GenericCSV',
    name='boston',
    description=boston.DESCR,
)

Create a web service

You can also create a web service from Jupyter.

For example, running the following code will create a web service called add.

from azureml import services

@services.publish(ws.workspace_id, ws.authorization_token)
@services.types(a = float, b = float)
@services.returns(float)
def add(a, b):
    return a + b

Use an existing web service

You can also use an existing web service from Jupyter.

When I used a web service created with Jupyter, authentication did not pass and it did not work, so with GUI Let's create a service to add and use it from Jupyter.

スクリーンショット 2015-09-20 0.39.27.png

The contents of "Execute Python Script" are as follows.

def azureml_main(dataframe1 = None):
    dataframe1['c'] = dataframe1.a + dataframe1.b
    return dataframe1

If you deploy this as a web service, you will have a service that adds the two numbers as follows.

スクリーンショット 2015-09-20 0.42.41.png

スクリーンショット 2015-09-20 0.43.37.png

To use this web service from Notebook, define a function using a decorator as follows: The url and api_key can be obtained from the help page of REQUEST / RESPONSE, the dashboard of the created web service.

from azureml import services

url = 'WEB_SERVICE_URL'
api_key = 'WEB_SERVICE_API_KEY'
@services.service(url, api_key)
@services.types(a = float, b = float)
@services.returns(float)
def add(a, b):
    pass

You can use this function as a web service. (It will take some time to execute the first time.)

スクリーンショット 2015-09-20 0.53.04.png

Finally

There are still many things that can not be done from the client Jupyter, but I am looking forward to the cooperation function being strengthened in the future. Azure Machine Learning has many examples, so it seems interesting to take a closer look at the intermediate results and draw a graph with Jupyter.

Reference material

Recommended Posts

Try using Jupyter Notebook of Azure Machine Learning
Try using Jupyter Notebook dynamically
Application development using Azure Machine Learning
Try using conda virtual environment with Jupyter Notebook
Causal reasoning using machine learning (organization of causal reasoning methods)
Easy Machine Learning with AutoAI (Part 4) Jupyter Notebook Edition
Key points of "Machine learning with Azure ML Studio"
Using Graphviz with Jupyter Notebook
Basics of Machine Learning (Notes)
Try using Azure Logic Apps
Importance of machine learning datasets
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
[Machine learning] Start Spark with iPython Notebook and try MLlib
Try to evaluate the performance of machine learning / regression model
Machine learning with Jupyter Notebook in OCI Always Free environment (2019/12/17)
Try to evaluate the performance of machine learning / classification model
[Machine learning] Feature selection of categorical variables using chi-square test
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS with anaconda
Significance of machine learning and mini-batch learning
[Machine learning] Try studying decision trees
Machine learning beginners try linear regression
Machine learning ③ Summary of decision tree
Try machine learning with scikit-learn SVM
Run azure ML on jupyter notebook
Somehow I tried using jupyter notebook
Try starting Jupyter Notebook ~ Esper training
[Python machine learning] Recommendation of using Spyder for beginners (as of August 2020)
[Anomaly detection] Try using the latest method of deep distance learning
Learn machine learning anytime, anywhere in an on-demand Jupyter Notebook environment
How to quickly create a machine learning environment using Jupyter Notebook on macOS Sierra with anaconda
Machine learning algorithm (generalization of linear regression)
Stock price forecast using machine learning (scikit-learn)
Try to make a kernel of Jupyter
[Machine learning] LDA topic classification using scikit-learn
[Machine learning] FX prediction using decision trees
Notes on running Azure Machine Learning locally
"Python Machine Learning Programming" Summary Note (Jupyter)
2020 Recommended 20 selections of introductory machine learning books
Try deep learning of genomics with Kipoi
Machine learning
Machine learning algorithm (implementation of multi-class classification)
[Machine learning] Supervised learning using kernel density estimation
GPU check of PC on jupyter notebook
Jupyter Notebook Basics of how to use
Stock price forecast using machine learning (regression)
[Machine learning] List of frequently used packages
Let's try neural machine translation using Transformer
Judgment of igneous rock by machine learning ②
[Machine learning] Regression analysis using scikit learn
Try to predict the value of the water level gauge by machine learning using the open data of Data City Sabae
Try to write code from 1 using the machine learning framework chainer (mnist edition)
[Super Introduction] Machine learning using Python-From environment construction to implementation of simple perceptron-
Machine Learning: Image Recognition of MNIST by using PCA and Gaussian Native Bayes
A memorandum of method often used in machine learning using scikit-learn (for beginners)
Machine learning memo of a fledgling engineer Part 1
Try a state-space model (Jupyter Notebook + IR kernel)
Classification of guitar images by machine learning Part 1
A story about simple machine learning using TensorFlow
Data supply tricks using deques in machine learning
Reinforcement learning 10 Try using a trained neural network.
Try to forecast power demand by machine learning