mirror of
https://github.com/Azure/MachineLearningNotebooks.git
synced 2025-12-20 17:45:10 -05:00
update samples from Release-89 as a part of 1.30.0 SDK stable release
This commit is contained in:
@@ -17,12 +17,9 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"# Quickstart: Learn how to get started with Azure ML Job Submission\n",
|
||||
"# Quickstart: Learn how to submit batch jobs with the Azure Machine Learning Python SDK\n",
|
||||
"\n",
|
||||
"In this quickstart, you train a machine learning model by submitting a Job to a compute target. \n",
|
||||
"When training, it is common to start on your local computer, and then later scale out to a cloud-based cluster. \n",
|
||||
"\n",
|
||||
"All you need to do is define the environment for each compute target within a script run configuration. Then, when you want to run your training experiment on a different compute target, specify the run configuration for that compute.\n",
|
||||
"In this quickstart, you learn how to submit a batch training job using the Python SDK. In this example, we submit the job to the 'local' machine (the compute instance you are running this notebook on). However, you can use exactly the same method to submit the job to different compute targets (for example, AKS, Azure Machine Learning Compute Cluster, Synapse, etc) by changing a single line of code. A full list of support compute targets can be viewed [here](https://docs.microsoft.com/en-us/azure/machine-learning/concept-compute-target). \n",
|
||||
"\n",
|
||||
"This quickstart trains a simple logistic regression using the [MNIST](https://azure.microsoft.com/services/open-datasets/catalog/mnist/) dataset and [scikit-learn](http://scikit-learn.org) with Azure Machine Learning. MNIST is a popular dataset consisting of 70,000 grayscale images. Each image is a handwritten digit of 28x28 pixels, representing a number from 0 to 9. The goal is to create a multi-class classifier to identify the digit a given image represents. \n",
|
||||
"\n",
|
||||
@@ -30,6 +27,7 @@
|
||||
"\n",
|
||||
"> * Download a dataset and look at the data\n",
|
||||
"> * Train an image classification model by submitting a batch job to a compute resource\n",
|
||||
"> * Use MLflow autologging to track model metrics and log the model artefact\n",
|
||||
"> * Review training results, find and register the best model"
|
||||
]
|
||||
},
|
||||
@@ -67,16 +65,14 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np\r\n",
|
||||
"import matplotlib.pyplot as plt\r\n",
|
||||
"\r\n",
|
||||
"from azureml.core import Workspace\r\n",
|
||||
"from azureml.core import Experiment\r\n",
|
||||
"\r\n",
|
||||
"# connect to your workspace\r\n",
|
||||
"ws = Workspace.from_config()\r\n",
|
||||
"\r\n",
|
||||
"experiment_name = \"get-started-with-jobsubmission-tutorial\"\r\n",
|
||||
"\n",
|
||||
"from azureml.core import Workspace\n",
|
||||
"from azureml.core import Experiment\n",
|
||||
"\n",
|
||||
"# connect to your workspace\n",
|
||||
"ws = Workspace.from_config()\n",
|
||||
"\n",
|
||||
"experiment_name = \"get-started-with-jobsubmission-tutorial\"\n",
|
||||
"exp = Experiment(workspace=ws, name=experiment_name)"
|
||||
]
|
||||
},
|
||||
@@ -90,14 +86,7 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Import Data\n",
|
||||
"\n",
|
||||
"Before you train a model, you need to understand the data that you are using to train it. In this section you will:\n",
|
||||
"\n",
|
||||
"* Download the MNIST dataset\n",
|
||||
"* Display some sample images\n",
|
||||
"\n",
|
||||
"### Download the MNIST dataset\n",
|
||||
"### The MNIST dataset\n",
|
||||
"\n",
|
||||
"Use Azure Open Datasets to get the raw MNIST data files. [Azure Open Datasets](https://docs.microsoft.com/azure/open-datasets/overview-what-are-open-datasets) are curated public datasets that you can use to add scenario-specific features to machine learning solutions for more accurate models. Each dataset has a corresponding class, `MNIST` in this case, to retrieve the data in different ways.\n",
|
||||
"\n",
|
||||
@@ -123,215 +112,16 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"from azureml.core import Dataset\n",
|
||||
"from azureml.opendatasets import MNIST\n",
|
||||
"\n",
|
||||
"data_folder = os.path.join(os.getcwd(), \"data\")\n",
|
||||
"os.makedirs(data_folder, exist_ok=True)\n",
|
||||
"\n",
|
||||
"mnist_file_dataset = MNIST.get_file_dataset()\n",
|
||||
"mnist_file_dataset.download(data_folder, overwrite=True)\n",
|
||||
"\n",
|
||||
"mnist_file_dataset = mnist_file_dataset.register(\n",
|
||||
" workspace=ws,\n",
|
||||
" name=\"mnist_opendataset\",\n",
|
||||
" description=\"training and test dataset\",\n",
|
||||
" create_new_version=True,\n",
|
||||
")"
|
||||
"mnist_file_dataset = MNIST.get_file_dataset()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Take a look at the data\n",
|
||||
"You will load the compressed files into `numpy` arrays. Then use `matplotlib` to plot 30 random images from the dataset with their labels above them. Note this step requires a `load_data` function that's included in an `utils.py` file. This file is placed in the same folder as this notebook. The `load_data` function simply parses the compressed files into numpy arrays. \n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612965857960
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# make sure utils.py is in the same directory as this code\r\n",
|
||||
"from src.utils import load_data\r\n",
|
||||
"import glob\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"# note we also shrink the intensity values (X) from 0-255 to 0-1. This helps the model converge faster.\r\n",
|
||||
"X_train = (\r\n",
|
||||
" load_data(\r\n",
|
||||
" glob.glob(\r\n",
|
||||
" os.path.join(data_folder, \"**/train-images-idx3-ubyte.gz\"), recursive=True\r\n",
|
||||
" )[0],\r\n",
|
||||
" False,\r\n",
|
||||
" )\r\n",
|
||||
" / 255.0\r\n",
|
||||
")\r\n",
|
||||
"X_test = (\r\n",
|
||||
" load_data(\r\n",
|
||||
" glob.glob(\r\n",
|
||||
" os.path.join(data_folder, \"**/t10k-images-idx3-ubyte.gz\"), recursive=True\r\n",
|
||||
" )[0],\r\n",
|
||||
" False,\r\n",
|
||||
" )\r\n",
|
||||
" / 255.0\r\n",
|
||||
")\r\n",
|
||||
"y_train = load_data(\r\n",
|
||||
" glob.glob(\r\n",
|
||||
" os.path.join(data_folder, \"**/train-labels-idx1-ubyte.gz\"), recursive=True\r\n",
|
||||
" )[0],\r\n",
|
||||
" True,\r\n",
|
||||
").reshape(-1)\r\n",
|
||||
"y_test = load_data(\r\n",
|
||||
" glob.glob(\r\n",
|
||||
" os.path.join(data_folder, \"**/t10k-labels-idx1-ubyte.gz\"), recursive=True\r\n",
|
||||
" )[0],\r\n",
|
||||
" True,\r\n",
|
||||
").reshape(-1)\r\n",
|
||||
"\r\n",
|
||||
"\r\n",
|
||||
"# now let's show some randomly chosen images from the training set.\r\n",
|
||||
"count = 0\r\n",
|
||||
"sample_size = 30\r\n",
|
||||
"plt.figure(figsize=(16, 6))\r\n",
|
||||
"for i in np.random.permutation(X_train.shape[0])[:sample_size]:\r\n",
|
||||
" count = count + 1\r\n",
|
||||
" plt.subplot(1, sample_size, count)\r\n",
|
||||
" plt.axhline(\"\")\r\n",
|
||||
" plt.axvline(\"\")\r\n",
|
||||
" plt.text(x=10, y=-10, s=y_train[i], fontsize=18)\r\n",
|
||||
" plt.imshow(X_train[i].reshape(28, 28), cmap=plt.cm.Greys)\r\n",
|
||||
"plt.show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## Submit your training job\n",
|
||||
"\n",
|
||||
"In this quickstart you submit a job to run on the local compute, but you can use the same code to submit this training job to other compute targets. With Azure Machine Learning, you can run your script on various compute targets without having to change your training script. \n",
|
||||
"\n",
|
||||
"To submit a job you need:\n",
|
||||
"* A directory\n",
|
||||
"* A training script\n",
|
||||
"* Create a script run configuration\n",
|
||||
"* Submit the job \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"### Directory and training script \n",
|
||||
"\n",
|
||||
"You need a directory to deliver the necessary code from your computer to the remote resource. A directory with a training script has been created for you and can be found in the same folder as this notebook.\n",
|
||||
"\n",
|
||||
"Take a few minutes to examine the training script."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612965865707
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"with open(\"./src/train.py\", \"r\") as f:\n",
|
||||
" print(f.read())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"Notice how the script gets data and saves models:\n",
|
||||
"\n",
|
||||
"+ The training script reads an argument to find the directory containing the data. When you submit the job later, you point to the dataset for this argument:\n",
|
||||
"`parser.add_argument('--data-folder', type=str, dest='data_folder', help='data directory mounting point')`\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"+ The training script saves your model into a directory named outputs. <br/>\n",
|
||||
"`joblib.dump(value=clf, filename='outputs/sklearn_mnist_model.pkl')`<br/>\n",
|
||||
"Anything written in this directory is automatically uploaded into your workspace. You'll access your model from this directory later in the tutorial.\n",
|
||||
"\n",
|
||||
"The file `utils.py` is referenced from the training script to load the dataset correctly. This script is also copied into the script folder so that it can be accessed along with the training script."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Configure the training job\n",
|
||||
"\n",
|
||||
"Create a [ScriptRunConfig]() object to specify the configuration details of your training job, including your training script, environment to use, and the compute target to run on. Configure the ScriptRunConfig by specifying:\n",
|
||||
"\n",
|
||||
"* The directory that contains your scripts. All the files in this directory are uploaded into the cluster nodes for execution. \n",
|
||||
"* The compute target. In this case you will point to local compute\n",
|
||||
"* The training script name, train.py\n",
|
||||
"* An environment that contains the libraries needed to run the script\n",
|
||||
"* Arguments required from the training script. \n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Define the Environment\n",
|
||||
"An Environment defines Python packages, environment variables, and Docker settings that are used in machine learning experiments. Here you will be using a curated environment that has already been made available through the workspace. \n",
|
||||
"\n",
|
||||
"Read [this article](https://docs.microsoft.com/azure/machine-learning/how-to-use-environments) if you want to learn more about Environments and how to use them."
|
||||
@@ -357,11 +147,12 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azureml.core.environment import Environment\n",
|
||||
"from azureml.core.conda_dependencies import CondaDependencies\n",
|
||||
"\n",
|
||||
"# use a curated environment that has already been built for you\n",
|
||||
"\n",
|
||||
"env = Environment.get(workspace=ws, name=\"AzureML-Scikit-learn-0.20.3\")"
|
||||
"env = Environment.get(workspace=ws, \n",
|
||||
" name=\"AzureML-Scikit-learn0.24-Cuda11-OpenMpi4.1.0-py36\", \n",
|
||||
" version=1)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -374,9 +165,17 @@
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"Create a [ScriptRunConfig](https://docs.microsoft.com/python/api/azureml-core/azureml.core.scriptrunconfig?preserve-view=true&view=azure-ml-py) object to specify the configuration details of your training job, including your training script, environment to use, and the compute target to run on. A script run configuration is used to configure the information necessary for submitting a training run as part of an experiment. In this case we will run this on a 'local' compute target, which is the compute instance you are running this notebook on.\r\n",
|
||||
"\r\n",
|
||||
"Read more about configuring and submitting training runs [here](https://docs.microsoft.com/azure/machine-learning/how-to-set-up-training-targets). "
|
||||
"### Configure the training job\n",
|
||||
"\n",
|
||||
"Create a [ScriptRunConfig](https://docs.microsoft.com/python/api/azureml-core/azureml.core.script_run_config.scriptrunconfig?view=azure-ml-py) object to specify the configuration details of your training job, including your training script, environment to use, and the compute target to run on. Configure the ScriptRunConfig by specifying:\n",
|
||||
"\n",
|
||||
"* The directory that contains your scripts. All the files in this directory are uploaded into the cluster nodes for execution. \n",
|
||||
"* The compute target. In this case you will point to local compute\n",
|
||||
"* The training script name, train.py\n",
|
||||
"* An environment that contains the libraries needed to run the script\n",
|
||||
"* Arguments required from the training script. \n",
|
||||
"\n",
|
||||
"In this run we will be submitting to \"local\", which is the compute instance you are running this notebook. If you have another compute target (for example: AKS, Azure ML Compute Cluster, Azure Databricks, etc) then you just need to change the `compute_target` argument below. You can learn more about other compute targets [here](https://docs.microsoft.com/azure/machine-learning/how-to-set-up-training-targets). "
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -423,7 +222,7 @@
|
||||
"source": [
|
||||
"### Submit the job\n",
|
||||
"\n",
|
||||
"Run the experiment by submitting the ScriptRunConfig object. After this there are many options for monitoring your run. You can either navigate to the experiment \"get-started-with-jobsubmission-tutorial\" in the left menu item Experiments to monitor the run (quick link to the run details page in the cell output below), or you can monitor the run inline in this notebook by using the Jupyter widget activated below."
|
||||
"Run the experiment by submitting the ScriptRunConfig object. After this there are many options for monitoring your run. Once submitted, you can either navigate to the experiment \"get-started-with-jobsubmission-tutorial\" in the left menu item __Experiments__ to monitor the run, or you can monitor the run inline as the `run.wait_for_completion(show_output=True)` will stream the logs of the run. You will see that the environment is built for you to ensure reproducibility - this adds a couple of minutes to the run time. On subsequent runs, the environment is re-used making the runtime shorter."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -446,137 +245,9 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"run = exp.submit(config=src)\n",
|
||||
"run"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Jupyter widget\n",
|
||||
"\n",
|
||||
"Watch the progress of the run with a Jupyter widget. Like the run submission, the widget is asynchronous and provides live updates every 10-15 seconds until the job completes.\n",
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612966026710
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from azureml.widgets import RunDetails\n",
|
||||
"\n",
|
||||
"RunDetails(run).show()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"if you want to cancel a run, you can follow [these instructions](https://aka.ms/aml-docs-cancel-run)."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Get log results upon completion\n",
|
||||
"\n",
|
||||
"Model training happens in the background. You can use `wait_for_completion` to block and wait until the model has completed training before running more code. "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612966045110
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# specify show_output to True for a verbose log\n",
|
||||
"run.wait_for_completion(show_output=True)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"### Display run results\n",
|
||||
"\n",
|
||||
"You now have a trained model. Retrieve all the metrics logged during the run, including the accuracy of the model:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612966059052
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(run.get_metrics())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -589,42 +260,11 @@
|
||||
"source": [
|
||||
"## Register model\n",
|
||||
"\n",
|
||||
"The last step in the training script wrote the file `outputs/sklearn_mnist_model.pkl` in a directory named `outputs` on the compute where the job is executed. `outputs` is a special directory in that all content in this directory is automatically uploaded to your workspace. This content appears in the run record in the experiment under your workspace. Hence, the model file is now also available in your workspace."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"gather": {
|
||||
"logged": 1612966064041
|
||||
},
|
||||
"jupyter": {
|
||||
"outputs_hidden": false,
|
||||
"source_hidden": false
|
||||
},
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"print(run.get_file_names())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"nteract": {
|
||||
"transient": {
|
||||
"deleting": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"Register the model in the workspace so that you (or your team members with access to the workspace) can later query, examine, and deploy this model."
|
||||
"The training script used the MLflow autologging feature and therefore the model was captured and stored on your behalf. Below we register the model into the Azure Machine Learning Model registry, which lets you keep track of all the models in your Azure Machine Learning workspace.\n",
|
||||
"\n",
|
||||
"Models are identified by name and version. Each time you register a model with the same name as an existing one, the registry assumes that it's a new version. The version is incremented, and the new model is registered under the same name.\n",
|
||||
"\n",
|
||||
"When you register the model, you can provide additional metadata tags and then use the tags when you search for models."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -648,11 +288,18 @@
|
||||
"source": [
|
||||
"# register model\n",
|
||||
"model = run.register_model(\n",
|
||||
" model_name=\"sklearn_mnist\", model_path=\"outputs/sklearn_mnist_model.pkl\"\n",
|
||||
" model_name=\"sklearn_mnist\", model_path=\"model/model.pkl\"\n",
|
||||
")\n",
|
||||
"print(model.name, model.id, model.version, sep=\"\\t\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"You will now be able to see the model in the regsitry by selecting __Models__ in the left-hand menu of the Azure Machine Learning Studio."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
|
||||
@@ -2,11 +2,10 @@ import argparse
|
||||
import os
|
||||
import numpy as np
|
||||
import glob
|
||||
import joblib
|
||||
import mlflow
|
||||
|
||||
from sklearn.linear_model import LogisticRegression
|
||||
import joblib
|
||||
|
||||
from azureml.core import Run
|
||||
from utils import load_data
|
||||
|
||||
# let user feed in 2 parameters, the dataset to mount or download,
|
||||
@@ -58,8 +57,8 @@ y_test = load_data(
|
||||
|
||||
print(X_train.shape, y_train.shape, X_test.shape, y_test.shape, sep="\n")
|
||||
|
||||
# get hold of the current run
|
||||
run = Run.get_context()
|
||||
# use mlflow autologging
|
||||
mlflow.autolog()
|
||||
|
||||
print("Train a logistic regression model with regularization rate of", args.reg)
|
||||
clf = LogisticRegression(
|
||||
@@ -73,10 +72,3 @@ y_hat = clf.predict(X_test)
|
||||
# calculate accuracy on the prediction
|
||||
acc = np.average(y_hat == y_test)
|
||||
print("Accuracy is", acc)
|
||||
|
||||
run.log("regularization rate", np.float(args.reg))
|
||||
run.log("accuracy", np.float(acc))
|
||||
|
||||
os.makedirs("outputs", exist_ok=True)
|
||||
# note file saved in the outputs folder is automatically uploaded into experiment record
|
||||
joblib.dump(value=clf, filename="outputs/sklearn_mnist_model.pkl")
|
||||
|
||||
Reference in New Issue
Block a user