You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/machine-learning/algorithm-module-reference/create-python-model.md
+17-2Lines changed: 17 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,14 +26,22 @@ After you create the model, you can use [Train Model](train-model.md) to train t
26
26
## Configure the module
27
27
28
28
Use of this module requires intermediate or expert knowledge of Python. The module supports use of any learner that's included in the Python packages already installed in Azure Machine Learning. See the preinstalled Python package list in [Execute Python Script](execute-python-script.md).
29
-
30
29
30
+
> [!NOTE]
31
+
> Please be very careful when writing your script and makes sure there is no syntax error, such as using a un-declared object or a un-imported module.
32
+
33
+
> [!NOTE]
34
+
Also pay extra attentions to the pre-installed modules list in [Execute Python Script](execute-python-script.md). Only import pre-installed modules. Please do not install extra packages such as "pip install xgboost" in this script, otherwise errors will be raised when reading models in down-stream modules.
35
+
31
36
This article shows how to use **Create Python Model** with a simple pipeline. Here's a diagram of the pipeline:
32
37
33
38

34
39
35
40
1. Select **Create Python Model**, and edit the script to implement your modeling or data management process. You can base the model on any learner that's included in a Python package in the Azure Machine Learning environment.
36
41
42
+
> [!NOTE]
43
+
> Please pay extra attention to the comments in sample code of the script and make sure your script strictly follows the requirement, including the class name, methods as well as method signature. Violation will lead to exceptions.
44
+
37
45
The following sample code of the two-class Naive Bayes classifier uses the popular *sklearn* package:
38
46
39
47
```Python
@@ -45,7 +53,9 @@ This article shows how to use **Create Python Model** with a simple pipeline. He
45
53
# predict: which generates prediction result, the input argument and the prediction result MUST be pandas DataFrame.
46
54
# The signatures (method names and argument names) of all these methods MUST be exactly the same as the following example.
47
55
48
-
56
+
# Please do not install extra packages such as "pip install xgboost" in this script,
57
+
# otherwise errors will be raised when reading models in down-stream modules.
58
+
49
59
import pandas as pd
50
60
from sklearn.naive_bayes import GaussianNB
51
61
@@ -56,10 +66,15 @@ This article shows how to use **Create Python Model** with a simple pipeline. He
56
66
self.feature_column_names =list()
57
67
58
68
deftrain(self, df_train, df_label):
69
+
# self.feature_column_names records the column names used for training.
70
+
# It is recommended to set this attribute before training so that the
71
+
# feature columns used in predict and train methods have the same names.
0 commit comments