Skip to content

Commit b055f8a

Browse files
Merge pull request #106142 from PeterCLu/plu-designer-python
Plu designer python
2 parents 3489b6f + f37a300 commit b055f8a

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: Python
3+
titleSuffix: Azure Machine Learning
4+
description: Learn how to use Python in Azure Machine Learning designer to transform data.
5+
services: machine-learning
6+
ms.service: machine-learning
7+
ms.subservice: core
8+
ms.topic: how-to
9+
10+
author: peterclu
11+
ms.author: peterlu
12+
ms.date: 02/28/2020
13+
---
14+
15+
# Execute Python code in Azure Machine Learning designer
16+
17+
In this article, you learn how to use the [Execute Python Script](algorithm-module-reference/execute-python-script.md) module to add custom logic to Azure Machine Learning designer. In the following how-to, you use the Pandas library to do simple feature engineering.
18+
19+
You can use the in-built code editor to quickly add simple Python logic. If you want to add more complex code or upload additional Python libraries, you should use the zip file method.
20+
21+
The default execution environment uses the Anacondas distribution of Python. For a complete list of pre-installed packages, see the [Execute Python Script module reference](algorithm-module-reference/execute-python-script.md) page.
22+
23+
![Execute Python input map](media/how-to-designer-python/execute-python-map.png)
24+
25+
## Execute Python written in the designer
26+
27+
### Add the Execute Python Script module
28+
29+
1. Find the **Execute Python Script** module in the designer palette. It can be found in the **Python Language** section.
30+
31+
1. Drag and drop the module onto the pipeline canvas.
32+
33+
### Connect input datasets
34+
35+
This article uses the sample dataset, **Automobile price data (Raw)**.
36+
37+
1. Drag and drop your dataset to the pipeline canvas.
38+
39+
1. Connect the output port of the dataset to the top-left input port of the **Execute Python Script** module. The designer exposes the input as a parameter to the entry point script.
40+
41+
The right input port is reserved for zipped python libraries.
42+
43+
![Connect datasets](media/how-to-designer-python/connect-dataset.png)
44+
45+
46+
1. Take note of which input port you use. The designer assigns the left input port to the variable `dataset1` and the middle input port to `dataset2`.
47+
48+
Input modules are optional since you can generate or import data directly in the **Execute Python Script** module.
49+
50+
### Write your Python code
51+
52+
The designer provides an initial entry point script for you to edit and enter your own Python code.
53+
54+
In this example, you use Pandas to combine two columns found in the automobile dataset, **Price** and **Horsepower**, to create a new column, **Dollars per horsepower**. This column represents how much you pay for each horsepower, which could be a useful feature to decide if a car is a good deal for the money.
55+
56+
1. Select the **Execute Python Script** module.
57+
58+
1. In the pane that appears to the right of the canvas, select the **Python script** text box.
59+
60+
1. Copy and paste the following code into the text box.
61+
62+
```python
63+
import pandas as pd
64+
65+
def azureml_main(dataframe1 = None, dataframe2 = None):
66+
dataframe1['Dollar/HP'] = dataframe1.price / dataframe1.horsepower
67+
return dataframe1
68+
```
69+
Your pipeline should look the following image:
70+
71+
![Execute Python pipeline](media/how-to-designer-python/execute-python-pipeline.png)
72+
73+
The entry point script must contain the function `azureml_main`. There are two function parameters that map to the two input ports for the **Execute Python Script** module.
74+
75+
The return value must be a Pandas Dataframe. You can return up to two dataframes as module outputs.
76+
77+
1. Run the pipeline.
78+
79+
Now, you have a dataset with the new feature **Dollars/HP**, which could be useful in training a car recommender. This is an example of feature extraction and dimensionality reduction.
80+
81+
## Next steps
82+
83+
Learn how to [import your own data](how-to-designer-import-data.md) in Azure Machine Learning designer.
15.4 KB
Loading
22.3 KB
Loading
68.9 KB
Loading

articles/machine-learning/toc.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,18 +367,21 @@
367367
- name: 'Azure Pipelines for CI/CD'
368368
displayName: continuous, integration, delivery
369369
href: /azure/devops/pipelines/targets/azure-machine-learning?context=azure/machine-learning/service/context/ml-context
370-
- name: 'Designer: Retrain using published pipelines'
370+
- name: 'Designer retrain using published pipelines'
371371
displayName: retrain, designer, published pipeline
372372
href: how-to-retrain-designer.md
373+
- name: Designer batch predictions
374+
displayName: score scoring asynchronous consume pipeline parallelrunstep inference designer
375+
href: how-to-run-batch-predictions-designer.md
376+
- name: Designer execute Python code
377+
displayName: feature extraction, feature engineering
378+
href: how-to-designer-python.md
373379
- name: Use parallel run step
374380
displayName: score scoring batch consume pipeline parallelrunstep inference
375381
href: how-to-use-parallel-run-step.md
376382
- name: Debug & troubleshoot parallel run step
377383
displayName: debug_batch consume pipeline parallelrunstep inference
378384
href: how-to-debug-parallel-run-step.md
379-
- name: Designer batch predictions
380-
displayName: score scoring asynchronous consume pipeline parallelrunstep inference designer
381-
href: how-to-run-batch-predictions-designer.md
382385
- name: Manage resource quotas
383386
displayName: limits
384387
href: how-to-manage-quotas.md

0 commit comments

Comments
 (0)