Skip to content

Instantly share code, notes, and snippets.

Avatar
🧪
Teaching AI how to play One Night Ultimate Werewolf

Matt Eland IntegerMan

🧪
Teaching AI how to play One Night Ultimate Werewolf
View GitHub Profile
View Deploying.py
from azureml.core import Environment
from azureml.core.model import InferenceConfig
# Load the environment from the YAML file downloaded from the best run
env = Environment.from_conda_specification("AutoML-env", "automl-output/outputs/conda_env_v_1_0_0.yml")
# Create an inference config pointing at the files we downloaded. This configuration tells Azure how to handle requests
inference_config = InferenceConfig(environment=env,
source_directory='./automl-output/outputs',
entry_script='./scoring_file_v_2_0_0.py')
View RegisterModel.py
# Register the model in Azure
best_auto_run.register_model(
model_name='My-AutoML-Model',
model_path='outputs/model.pkl',
description='A model I trained with Python Code')
best_auto_run.download_files(output_directory='automl-output')
View RunDetails.py
# Grab the resulting model and best run
best_auto_run, automl_model = run.get_output()
# Display details about the best run
print('Best Run: ' + str(best_auto_run.id))
RunDetails(best_auto_run).show()
View start.py
from azureml.core.experiment import Experiment
from azureml.widgets import RunDetails
# Find or Create a Machine Learning Experiment in Azure Machine Learning Studio
experiment_name = 'My-Regression-Experiment'
experiment=Experiment(ws, experiment_name)
# Start running the experiment
run = experiment.submit(automl_config)
View AutoMLConfig.py
# Create the configuration for the experiment
from azureml.train.automl import AutoMLConfig
# See https://docs.microsoft.com/en-us/python/api/azureml-train-automl-client/azureml.train.automl.automlconfig.automlconfig?view=azure-ml-py for details
automl_config = AutoMLConfig(
task='regression', # regression, classification, or forecasting
training_data=ds, # The data to use to train the model
label_column_name='thingIWantToPredict', # The column we're trying to predict
n_cross_validations=3, # How many cross-validation sets to use
primary_metric='normalized_root_mean_squared_error',# The metric we use to compare model performance
View Register.py
from azureml.core import Dataset
import pandas as pd
# The default datastore is a blob storage container where datasets are stored
datastore = ws.get_default_datastore()
# Load some data into a dataframe (Note: Pandas is just one path into Azure ML)
df = pd.read_csv('my_data.csv')
# Register the dataset
View Compute.py
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException
# Now let's make sure we have a compute resource created
cluster_name = "My-Cluster" # The name of the cluster
vm_size = 'Standard_D2DS_V4' # There are many different specs available for CPU or GPU tasks.
min_nodes = 0 # This is important to prevent billing while idle
max_nodes = 4 # Azure does limit you to a certain quota, but you can get that extended
# Fetch or create the compute resource
View Workspace.py
# Load the workspace information from config.json using the Azure ML SDK
from azureml.core import Workspace
ws = Workspace.from_config()
ws.name
View delete_compute.py
from azureml.core import Workspace
from azureml.core.compute import ComputeTarget
from azureml.core.compute_target import ComputeTargetException
# Load the workspace from config.json
ws = Workspace.from_config()
# Now let's make sure we have a compute resource
instance_name = "My-Compute"
View create_compute_cluster.py
from azureml.core import Workspace
from azureml.core.compute import ComputeTarget, AmlCompute
from azureml.core.compute_target import ComputeTargetException
# Load the workspace from config.json
ws = Workspace.from_config()
# Now let's make sure we have a compute resource
cluster_name = "My-Cluster"