Skip to content

Commit 8e74d36

Browse files
committed
Include mlflow instructions for MM registration in example notebook
1 parent c07351d commit 8e74d36

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

examples/pzmmModelImportExampleMLFlow.ipynb

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,65 @@
1010
"SPDX-License-Identifier: Apache-2.0"
1111
]
1212
},
13+
{
14+
"cell_type": "markdown",
15+
"metadata": {},
16+
"source": [
17+
"### MLFlow Preamble"
18+
]
19+
},
20+
{
21+
"cell_type": "markdown",
22+
"metadata": {},
23+
"source": [
24+
"In order to import MLFlow models into SAS Model Manager, there are a few lines that need to be included in the MLFlow script. First of all, include the infer_signature function in the import statements:"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"from mlflow.models.signature import infer_signature"
34+
]
35+
},
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": [
40+
"Next, adjust any data columns which are not valid Python variable names:"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"metadata": {},
47+
"outputs": [],
48+
"source": [
49+
"import pandas as pd\n",
50+
"data = pd.read_csv('data.csv')\n",
51+
"data.columns = data.columns.str.replace('\\W|^(?=\\d)', '_', regex=True)"
52+
]
53+
},
54+
{
55+
"cell_type": "markdown",
56+
"metadata": {},
57+
"source": [
58+
"Include the signature inference after any paramater logging is defined and include a signature argument in the model logging:"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"metadata": {},
65+
"outputs": [],
66+
"source": [
67+
"import mlflow\n",
68+
"signature = infer_signature(data, model.predict(data))\n",
69+
"mlflow.sklearn.log_model(model, \"model\", signature=signature)"
70+
]
71+
},
1372
{
1473
"cell_type": "markdown",
1574
"metadata": {

0 commit comments

Comments
 (0)