Skip to content

Commit 1af4b8c

Browse files
Emphasize do not install extra packages in sample code's comment
1 parent c0ce635 commit 1af4b8c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

articles/machine-learning/algorithm-module-reference/create-python-model.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ After you create the model, you can use [Train Model](train-model.md) to train t
2828
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).
2929

3030
> [!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. Also pay extra attentions to the pre-installed modules list in [Execute Python Script](execute-python-script.md). To import modules which are not listed, please install the corresponding packages in your script such as
32-
> ```Python
33-
> import os
34-
> os.system(f"pip install scikit-misc")
35-
> ```
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.
3635

3736
This article shows how to use **Create Python Model** with a simple pipeline. Here's a diagram of the pipeline:
3837

@@ -54,7 +53,9 @@ This article shows how to use **Create Python Model** with a simple pipeline. He
5453
# predict: which generates prediction result, the input argument and the prediction result MUST be pandas DataFrame.
5554
# The signatures (method names and argument names) of all these methods MUST be exactly the same as the following example.
5655

57-
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+
5859
import pandas as pd
5960
from sklearn.naive_bayes import GaussianNB
6061

@@ -65,10 +66,15 @@ This article shows how to use **Create Python Model** with a simple pipeline. He
6566
self.feature_column_names = list()
6667

6768
def train(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.
6872
self.feature_column_names = df_train.columns.tolist()
6973
self.model.fit(df_train, df_label)
7074

7175
def predict(self, df):
76+
# The feature columns used for prediction MUST have the same names as the ones for training.
77+
# The name of score column ("Scored Labels" in this case) MUST be different from any other columns in input data.
7278
return pd.DataFrame(
7379
{'Scored Labels': self.model.predict(df[self.feature_column_names]),
7480
'probabilities': self.model.predict_proba(df[self.feature_column_names])[:, 1]}

0 commit comments

Comments
 (0)