Machine Learning News Hubb
Advertisement Banner
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us
Machine Learning News Hubb
No Result
View All Result
Home Machine Learning

Azure ML SDK V2 sample for forecasting a time series | by Balamurugan Balakreshnan | Sep, 2022

admin by admin
September 10, 2022
in Machine Learning


  • Azure Account
  • Azure Machine learning resource
  • Default AML storage
  • Create Training, Test and Validation folder
  • MLTable Config for above folders
  • Install preview features
  • Remember print version for preview is only available using _version.VERSION
import azure.ai.ml
print(azure.ai.ml._version.VERSION)
# import required libraries
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Workspace
from azure.identity import DefaultAzureCredential
  • now specificy the workspace name and subscription id
# Enter details of your AML workspace
subscription_id = "xxxxxxxxxxxxxxxxxxxxxxxxx"
resource_group = "rgname"
workspace = "workspacename"
# get a handle to the workspace
ml_client = MLClient(
DefaultAzureCredential(), subscription_id, resource_group, workspace
)
  • Import the necessary libraries
# Import required libraries
from azure.ai.ml import MLClient
  • Get Default Authentication
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredentialtry:
credential = DefaultAzureCredential()
# Check if given credential can get token successfully.
credential.get_token("https://management.azure.com/.default")
except Exception as ex:
# Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
# This will open a browser page for
credential = InteractiveBrowserCredential()
try:
ml_client = MLClient.from_config(credential=credential)
except Exception as ex:
# NOTE: Update following workspace information if not correctly configure before
client_config = {
"subscription_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
"resource_group": "rgname",
"workspace_name": "workspacename",
}
if client_config["subscription_id"].startswith("<"):
print(
"please update your in notebook cell"
)
raise ex
else: # write and reload from config file
import json, os
config_path = "../.azureml/config.json"
os.makedirs(os.path.dirname(config_path), exist_ok=True)
with open(config_path, "w") as fo:
fo.write(json.dumps(client_config))
ml_client = MLClient.from_config(credential=credential, path=config_path)
print(ml_client)
  • Now create the compute target
from azure.ai.ml.entities import AmlCompute# specify aml compute name.
cpu_compute_target = "cpu-cluster"
try:
ml_client.compute.get(cpu_compute_target)
except Exception:
print("Creating a new cpu compute target...")
compute = AmlCompute(
name=cpu_compute_target, size="STANDARD_D2_V2", min_instances=0, max_instances=4
)
ml_client.compute.begin_create_or_update(compute)
  • lets include other libraries
# import required libraries
from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential
from azure.ai.ml import MLClient, Input, command, Output
from azure.ai.ml.dsl import pipeline
from azure.ai.ml.automl import forecasting
from azure.ai.ml.entities._job.automl.tabular.forecasting_settings import ForecastingSettings
# add environment variable to enable private preview feature
import os
os.environ["AZURE_ML_CLI_PRIVATE_FEATURES_ENABLED"] = "true"
try:
credential = DefaultAzureCredential()
# Check if given credential can get token successfully.
credential.get_token("https://management.azure.com/.default")
except Exception as ex:
# Fall back to InteractiveBrowserCredential in case DefaultAzureCredential not work
credential = InteractiveBrowserCredential()
# Get a handle to workspace
ml_client = MLClient.from_config(credential=credential)
# Retrieve an already attached Azure Machine Learning Compute.
cluster_name = "cpu-cluster"
print(ml_client.compute.get(cluster_name))
# Define pipeline
@pipeline(
description="AutoML Forecasting Pipeline",
)
def automl_forecasting(
forecasting_train_data,
):
# define forecasting settings
forecasting_settings = ForecastingSettings(time_column_name="timeStamp", forecast_horizon=12, frequency="H", target_lags=[ 12 ], target_rolling_window_size=4)

# define the automl forecasting task with automl function
forecasting_node = forecasting(
training_data=forecasting_train_data,
target_column_name="demand",
primary_metric="normalized_root_mean_squared_error",
n_cross_validations=2,
forecasting_settings=forecasting_settings,
# currently need to specify outputs "mlflow_model" explictly to reference it in following nodes
outputs={"best_model": Output(type="mlflow_model")},
)

forecasting_node.set_limits(timeout_minutes=180)

command_func = command(
inputs=dict(
automl_output=Input(type="mlflow_model")
),
command="ls ${{inputs.automl_output}}",
environment="AzureML-sklearn-0.24-ubuntu18.04-py37-cpu:1"
)
show_output = command_func(automl_output=forecasting_node.outputs.best_model)
data_folder = "./data"
pipeline = automl_forecasting(
forecasting_train_data=Input(path=f"{data_folder}/training-mltable-folder/", type="mltable"),
)
# set pipeline level compute
pipeline.settings.default_compute="cpu-cluster"
# submit the pipeline job
pipeline_job = ml_client.jobs.create_or_update(
pipeline, experiment_name="pipeline_samples"
)
pipeline_job
  • Now get the URL to watch the pipeline job execute
# Wait until the job completes
ml_client.jobs.stream(pipeline_job.name)
  • Wait for it to complete
  • Monitor the job status



Source link

Previous Post

Pose Detector using Google ML Kit in Flutter & GetX | by Inzimam Bhatti | Sep, 2022

Next Post

Books for Data Science (Free) that You Must Read to Master Data Science | by Avinaba Mukherjee | Sep, 2022

Next Post

Books for Data Science (Free) that You Must Read to Master Data Science | by Avinaba Mukherjee | Sep, 2022

[ML]在不使用package的情況下撰寫決策樹程式碼 – Feederboy – Medium

[ML]在不使用package的情況下撰寫決策樹程式碼 - Feederboy - Medium

Autodidact’s path to AI/Machine Learning (part 1) | by Marios Kokmotos | Sep, 2022

Related Post

Artificial Intelligence

Dates and Subqueries in SQL. Working with dates in SQL | by Michael Grogan | Jan, 2023

by admin
January 27, 2023
Machine Learning

ChatGPT Is Here To Stay For A Long Time | by Jack Martin | Jan, 2023

by admin
January 27, 2023
Machine Learning

5 steps to organize digital files effectively

by admin
January 27, 2023
Artificial Intelligence

Explain text classification model predictions using Amazon SageMaker Clarify

by admin
January 27, 2023
Artificial Intelligence

Human Resource Management Challenges and The Role of Artificial Intelligence in 2023 | by Ghulam Mustafa Shoaib | Jan, 2023

by admin
January 27, 2023
Deep Learning

Training Neural Nets: a Hacker’s Perspective

by admin
January 27, 2023

© 2023 Machine Learning News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy and Terms & Conditions.

Navigate Site

  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us

Newsletter Sign Up.

No Result
View All Result
  • Home
  • Machine Learning
  • Artificial Intelligence
  • Big Data
  • Deep Learning
  • Edge AI
  • Neural Network
  • Contact Us

© 2023 JNews - Premium WordPress news & magazine theme by Jegtheme.