Trong phần này, chúng ta sẽ tạo Data Asset trong Azure ML Studio để đăng ký dữ liệu ecommerce đã upload vào Azure Storage. Data Asset sẽ cung cấp versioning, metadata tracking, và seamless integration với Azure ML training jobs. Đây là bước quan trọng để chuẩn bị dữ liệu cho quá trình training và đảm bảo reproducibility trong ML pipeline.
✅ Tạo Data Asset với URI folder trỏ tới data/raw/ecommerce/
✅ Cấu hình proper metadata và versioning
✅ Đảm bảo Data Asset sẵn sàng cho training jobs
✅ Verify accessibility từ Azure ML workspace
Required Components:
retailforecastdev với ADLS Gen2 enabled (từ Task 3: Data Upload)data/raw/ecommerce/ container (từ Task 3: Data Upload)retail-dev-rg với proper RBAC (từ Task 2: Resource Group)1. Asset Type:
retail_data1 (auto-incrementing)Retail e-commerce dataset 2019 - Raw CSV files2. Storage Reference:
dataraw/ecommerce/Step 1: Navigate to Azure ML Studio
Azure ML Studio → Data → +Create → Data asset
Step 2: Asset Configuration
retail_dataRetail e-commerce dataset 2019 - Raw CSV files for trainingStep 3: Data Source Configuration
retailforecastdevdataraw/ecommerce/Step 4: Advanced Settings
Environment: developmentDataset: ecommerceYear: 2019Basic Information:
retail_data1Storage Details:
retailforecastdevdataraw/ecommerce/Data Schema:
Advantages: User-friendly, visual interface, immediate validation Best for: Interactive setup, validation, testing
Detailed Steps:
Navigate to Data Assets
Azure ML Studio → Data → Data assets → +Create
Configure Basic Information
retail_dataRetail e-commerce dataset 2019 - Raw CSV files for trainingConfigure Data Source
retailforecastdevdataraw/ecommerce/Authentication Settings
Review & Create
# Create data asset using Azure CLI
az ml data create \
--name retail_data \
--version 1 \
--type uri_folder \
--path "azureml://datastores/workspaceblobstore/paths/raw/ecommerce/" \
--description "Retail e-commerce dataset 2019 - Raw CSV files for training" \
--tags Environment=development Dataset=ecommerce Year=2019
Verify Data Asset Creation:
# List data assets
az ml data list --name retail_data --output table
# Show specific asset details
az ml data show --name retail_data --version 1
# Verify asset creation
az ml data show --name retail_data --version 1 --query "{name:name, version:version, type:type, path:path}"
# Check asset size and file count
az ml data show --name retail_data --version 1 --query "{size:size, fileCount:fileCount}"
# Python script to test data asset accessibility
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Data
from azure.identity import DefaultAzureCredential
import os
def test_data_asset():
# Initialize ML client
credential = DefaultAzureCredential()
ml_client = MLClient(
credential=credential,
subscription_id="your-subscription-id",
resource_group_name="retail-dev-rg",
workspace_name="retail-ml-workspace"
)
# Get data asset
data_asset = ml_client.data.get(name="retail_data", version="1")
print(f"📊 Data Asset Information:")
print(f" Name: {data_asset.name}")
print(f" Version: {data_asset.version}")
print(f" Type: {data_asset.type}")
print(f" Path: {data_asset.path}")
print(f" Size: {data_asset.size} bytes")
# Test data access
try:
# List files in the asset
files = ml_client.data.list(name="retail_data", version="1")
print(f"\n📁 Files in dataset:")
for file in files:
print(f" ✅ {file.name}")
print(f"\n✅ Data asset is accessible and ready for training jobs!")
except Exception as e:
print(f"❌ Error accessing data asset: {e}")
if __name__ == "__main__":
test_data_asset()
# Test data asset in training job context
from azure.ai.ml import MLClient, command
from azure.ai.ml.entities import Data
from azure.identity import DefaultAzureCredential
def create_test_job():
credential = DefaultAzureCredential()
ml_client = MLClient(
credential=credential,
subscription_id="your-subscription-id",
resource_group_name="retail-dev-rg",
workspace_name="retail-ml-workspace"
)
# Create test training job using the data asset
job = command(
code="./src",
command="python train.py --data ${{inputs.retail_data}}",
inputs={
"retail_data": Data(
type="uri_folder",
path="azureml://datastores/workspaceblobstore/paths/raw/ecommerce/"
)
},
environment="azureml://registries/azureml/environments/sklearn-1.0/labels/latest",
compute="cpu-cluster",
display_name="test-retail-data-access"
)
print("✅ Training job created successfully with data asset reference!")
return job
if __name__ == "__main__":
create_test_job()
retail_dataretail_data:1raw/ecommerce/retail_data:1 selected as inputretail_data:1 registered in Azure ML Studiodata/raw/ecommerce/ folderretailforecastdev storage account#!/bin/bash
# create-data-asset.sh
# Configuration
SUBSCRIPTION_ID="your-subscription-id"
RESOURCE_GROUP="retail-dev-rg"
WORKSPACE_NAME="retail-ml-workspace"
ASSET_NAME="retail_data"
ASSET_VERSION="1"
STORAGE_ACCOUNT="retailforecastdev"
CONTAINER="data"
FOLDER_PATH="raw/ecommerce"
echo "🚀 Creating Data Asset in Azure ML Studio..."
# Login to Azure
az login
# Set subscription
az account set --subscription $SUBSCRIPTION_ID
# Create data asset
az ml data create \
--name $ASSET_NAME \
--version $ASSET_VERSION \
--type uri_folder \
--path "azureml://datastores/workspaceblobstore/paths/$FOLDER_PATH/" \
--description "Retail e-commerce dataset 2019 - Raw CSV files for training" \
--tags Environment=development Dataset=ecommerce Year=2019
# Verify creation
echo "✅ Verifying data asset creation..."
az ml data show --name $ASSET_NAME --version $ASSET_VERSION --output table
echo "📊 Data Asset Information:"
az ml data show --name $ASSET_NAME --version $ASSET_VERSION --query "{name:name, version:version, type:type, path:path, size:size}"
echo "✅ Data asset created successfully!"
# create_data_asset.py
from azure.ai.ml import MLClient
from azure.ai.ml.entities import Data
from azure.identity import DefaultAzureCredential
import os
def create_data_asset():
# Configuration
subscription_id = "your-subscription-id"
resource_group = "retail-dev-rg"
workspace_name = "retail-ml-workspace"
# Initialize ML client
credential = DefaultAzureCredential()
ml_client = MLClient(
credential=credential,
subscription_id=subscription_id,
resource_group_name=resource_group,
workspace_name=workspace_name
)
# Create data asset
data_asset = Data(
name="retail_data",
version="1",
type="uri_folder",
path="azureml://datastores/workspaceblobstore/paths/raw/ecommerce/",
description="Retail e-commerce dataset 2019 - Raw CSV files for training",
tags={
"Environment": "development",
"Dataset": "ecommerce",
"Year": "2019"
}
)
# Register the asset
ml_client.data.create_or_update(data_asset)
print("✅ Data asset created successfully!")
# Verify creation
created_asset = ml_client.data.get(name="retail_data", version="1")
print(f"📊 Asset Details:")
print(f" Name: {created_asset.name}")
print(f" Version: {created_asset.version}")
print(f" Type: {created_asset.type}")
print(f" Path: {created_asset.path}")
if __name__ == "__main__":
create_data_asset()
Issue 1: “Data asset not found”
# Verify asset exists
az ml data list --name retail_data
# Check workspace context
az ml workspace show --name retail-ml-workspace --resource-group retail-dev-rg
Issue 2: “Access denied to storage”
# Check Managed Identity permissions
az role assignment list --assignee <ml-workspace-mi-id> --scope /subscriptions/<sub-id>/resourceGroups/retail-dev-rg/providers/Microsoft.Storage/storageAccounts/retailforecastdev
Issue 3: “Invalid data path”
# Verify storage account and container
az storage container show --name data --account-name retailforecastdev
# Check folder path exists
az storage blob list --container-name data --prefix "raw/ecommerce/" --account-name retailforecastdev
Best Practice: Always test data asset accessibility before using in training jobs. Use the validation scripts provided to ensure proper integration.
Security Note: Ensure Managed Identity has proper permissions to access the storage account. Verify RBAC assignments before creating data assets.
Data Asset registration hoàn tất! 🎉 Asset đã sẵn sàng cho Task 5: Training Job Configuration.