Data Asset Registration

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.

1. Mục tiêu

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

TASK 4 — DATA ASSET (AZURE ML STUDIO)
Mục tiêu: Tạo Data Asset (URI folder) trỏ tới data/raw/ecommerce/. UI: Studio → Data → +Create (File/Folder). Bằng chứng: Card retail_data:1 (ảnh). Done: Asset dùng được trong Jobs.

2. AZURE ML STUDIO SETUP

2.1 Prerequisites

Required Components:

  • Azure ML Workspace đã tạo (từ Task 5 - sẽ tạo trong bước tiếp theo)
  • Storage Account retailforecastdev với ADLS Gen2 enabled (từ Task 3: Data Upload)
  • Data uploaded vào data/raw/ecommerce/ container (từ Task 3: Data Upload)
  • Resource Group retail-dev-rg với proper RBAC (từ Task 2: Resource Group)
  • Managed Identity permissions cho Azure ML workspace access storage (sẽ setup trong Task 5)
🔧 Data Asset Configuration

1. Asset Type:

  • Type: URI folder (recommended cho large datasets)
  • Name: retail_data
  • Version: 1 (auto-incrementing)
  • Description: Retail e-commerce dataset 2019 - Raw CSV files

2. Storage Reference:

  • Storage Type: Azure Data Lake Storage Gen2
  • Container: data
  • Folder Path: raw/ecommerce/
  • Authentication: Managed Identity (recommended)

2.2 UI Flow (Azure ML Studio)

Step 1: Navigate to Azure ML Studio

Azure ML Studio → Data → +Create → Data asset

Step 2: Asset Configuration

  • Asset type: URI folder
  • Asset name: retail_data
  • Description: Retail e-commerce dataset 2019 - Raw CSV files for training

Step 3: Data Source Configuration

  • Data source type: Azure Data Lake Storage Gen2
  • Storage account: retailforecastdev
  • Container: data
  • Folder path: raw/ecommerce/
  • Authentication: Managed Identity

Step 4: Advanced Settings

  • Skip validation: ❌ Disabled (verify data integrity)
  • Register new version: ✅ Enabled
  • Tags:
    • Environment: development
    • Dataset: ecommerce
    • Year: 2019

2.3 Data Asset Properties

📋 Asset Metadata

Basic Information:

  • Name: retail_data
  • Version: 1
  • Type: URI folder
  • Size: ≥4GB (total dataset size)
  • File Count: 12 files (2019-*.csv.gz)

Storage Details:

  • Storage Account: retailforecastdev
  • Container: data
  • Path: raw/ecommerce/
  • Authentication: Managed Identity

Data Schema:

  • Format: CSV (compressed with gzip)
  • Encoding: UTF-8
  • Delimiter: Comma (,)
  • Headers: Present

3. DATA ASSET CREATION

Advantages: User-friendly, visual interface, immediate validation Best for: Interactive setup, validation, testing

Detailed Steps:

  1. Navigate to Data Assets

    Azure ML Studio → Data → Data assets → +Create
    
  2. Configure Basic Information

    • Asset name: retail_data
    • Asset type: URI folder
    • Description: Retail e-commerce dataset 2019 - Raw CSV files for training
  3. Configure Data Source

    • Data source type: Azure Data Lake Storage Gen2
    • Subscription: [Your subscription]
    • Storage account: retailforecastdev
    • Container: data
    • Folder path: raw/ecommerce/
  4. Authentication Settings

    • Authentication method: Managed Identity
    • Identity: System-assigned managed identity của Azure ML workspace
  5. Review & Create

    • Verify all settings
    • Click “Create” to register the asset

3.2 Method 2: Azure CLI

# 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

4. DATA ASSET VALIDATION

4.1 Asset Verification

# 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}"

4.2 Data Accessibility Test

# 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()

4.3 Training Job Integration Test

# 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()

5. BẰNG CHỨNG HOÀN THÀNH

5.1 Ảnh 1: Data Asset Creation Form

📋 Yêu cầu screenshot:
  • ✅ Azure ML Studio → Data → +Create form
  • ✅ Asset name: retail_data
  • ✅ Asset type: URI folder selected
  • ✅ Data source configuration visible
  • ✅ Storage account and path configured

5.2 Ảnh 2: Data Asset Card (retail_data:1)

📊 Yêu cầu screenshot:
  • ✅ Data assets list showing retail_data:1
  • ✅ Asset type: URI folder
  • ✅ Version: 1
  • ✅ Size and file count visible
  • ✅ Status: Active/Ready

5.3 Ảnh 3: Data Asset Details

📁 Yêu cầu screenshot:
  • ✅ Data asset details page
  • ✅ Storage path: raw/ecommerce/
  • ✅ Authentication method: Managed Identity
  • ✅ File list showing 2019-*.csv.gz files
  • ✅ Total size ≥4GB

5.4 Ảnh 4: Data Asset in Training Job

🔧 Yêu cầu screenshot:
  • ✅ Training job creation form
  • ✅ Data asset retail_data:1 selected as input
  • ✅ Asset path properly referenced
  • ✅ Job configuration showing data integration

5.5 Ảnh 5: Data Asset Validation Results

✅ Yêu cầu screenshot:
  • ✅ Python validation script output
  • ✅ Asset accessibility confirmation
  • ✅ File count and size verification
  • ✅ Ready for training jobs message

6. TIÊU CHÍ HOÀN THÀNH

6.1 Functional Requirements

  • Data Asset created: retail_data:1 registered in Azure ML Studio
  • Correct path: Points to data/raw/ecommerce/ folder
  • Asset type: URI folder configured properly
  • Versioning: Version 1 created successfully
  • Metadata: Proper description and tags applied

6.2 Data Integration Requirements

  • Storage integration: Connected to retailforecastdev storage account
  • Authentication: Managed Identity configured
  • Data accessibility: Asset accessible from training jobs
  • File validation: All 2019-*.csv.gz files recognized

6.3 Training Job Readiness

  • Job integration: Asset usable in training job inputs
  • Path resolution: Correct URI path in job configuration
  • Data loading: Training scripts can access data via asset reference
  • Version control: Asset versioning working properly

7. AUTOMATION SCRIPTS

7.1 Complete Data Asset Creation Script

#!/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!"

7.2 Python SDK Script

# 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()

8. LƯU Ý QUAN TRỌNG

8.1 Data Asset Best Practices

⚠️ Important Considerations
  • Versioning: Always use versioning for data changes
  • Metadata: Include comprehensive descriptions and tags
  • Validation: Test data accessibility before using in jobs
  • Security: Use Managed Identity for secure access
  • Performance: URI folder is optimal for large datasets

8.2 Troubleshooting Common Issues

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

8.3 Next Steps

  1. Data Asset created ← Current step
  2. 🔄 Training job configuration ← Next step
  3. 🔄 Model training execution
  4. 🔄 Model registration
  5. 🔄 Endpoint deployment

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.