User Tools

Site Tools


wiki:ai:notebook-collectibles-deployment

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

wiki:ai:notebook-collectibles-deployment [2025/06/05 12:16] – created ddehamerwiki:ai:notebook-collectibles-deployment [2025/06/05 12:23] (current) ddehamer
Line 2: Line 2:
  
 ===== Process ===== ===== Process =====
-  +
 I exported my home MySQL database of collectibles to a csv file using: I exported my home MySQL database of collectibles to a csv file using:
-<code>+ 
 +<code ->
 mysql -u root -p -e "SELECT * FROM collectibles.inventory;" | sed 's/\t/","/g;s/^/"/;s/$/"/' > collectibles.csv mysql -u root -p -e "SELECT * FROM collectibles.inventory;" | sed 's/\t/","/g;s/^/"/;s/$/"/' > collectibles.csv
 </code> </code>
  
 That gave me a file that looked like this: That gave me a file that looked like this:
-<code>+ 
 +<code ->
 "id","character","figure_name","property","type","manufacturer","location","quantity","list_price","total_cost","approximate_value" "id","character","figure_name","property","type","manufacturer","location","quantity","list_price","total_cost","approximate_value"
 "1","Aang","Nendroid with Momo","Avatar the Last Airbender","Action Figure","Good Smile Co","Collectible Room","1","40.00","40.00","53.20" "1","Aang","Nendroid with Momo","Avatar the Last Airbender","Action Figure","Good Smile Co","Collectible Room","1","40.00","40.00","53.20"
Line 30: Line 32:
  
 ===== Final Working Code ===== ===== Final Working Code =====
- 
  
 ==== Step 1: Upload CSV to Azure ML Notebooks ==== ==== Step 1: Upload CSV to Azure ML Notebooks ====
  
 +Upload your local 'collectibles.csv' to the Azure ML Notebooks file system using the file upload icon.
  
-Upload your local 'collectibles.csv' to the Azure ML Notebooks file system using the file upload icon.+**Purpose**:\\ Upload and register the local ''collectibles.csv'' file into your Azure ML workspace as a named, versioned dataset so it can be used for training and analysis.
  
 ==== Step 2: Initialize MLClient ==== ==== Step 2: Initialize MLClient ====
  
-<code>+<code ->
 from azure.ai.ml import MLClient from azure.ai.ml import MLClient
 from azure.identity import DefaultAzureCredential from azure.identity import DefaultAzureCredential
Line 50: Line 52:
 ) )
 </code> </code>
 +
 +**Purpose**:\\ Authenticate and initialize the Azure ML client (''ml_client'') using your subscription, resource group, and workspace, enabling programmatic access to Azure ML resources.
  
 ==== Step 3: Load CSV and Train Model ==== ==== Step 3: Load CSV and Train Model ====
  
-<code>+<code ->
 import pandas as pd import pandas as pd
 from sklearn.ensemble import RandomForestRegressor from sklearn.ensemble import RandomForestRegressor
Line 78: Line 82:
 model.fit(X, y) model.fit(X, y)
 joblib.dump(model, "model.joblib") joblib.dump(model, "model.joblib")
- 
 </code> </code>
 +
 +**Purpose**:\\ Read the registered dataset into a Pandas DataFrame to validate its structure, inspect values, and ensure the data is suitable for training. Create and train a machine learning model based on the dataset, then serialize and register that model in Azure ML so it can be deployed later.
  
 ==== Step 4: Create score.py ==== ==== Step 4: Create score.py ====
  
-<code>+<code ->
 # score.py # score.py
 import joblib import joblib
Line 102: Line 107:
     except Exception as e:     except Exception as e:
         return {"error": str(e)}         return {"error": str(e)}
- 
 </code> </code>
  
-===== Step 5: Register Model =====+**Purpose**:\\ Develop a scoring script (''score.py'') that defines how the model will be loaded and how inference requests will be processed and responded to during deployment. 
 + 
 +==== Step 5: Register Model ====
  
-<code>+<code ->
 from azure.ai.ml.entities import Model from azure.ai.ml.entities import Model
  
Line 118: Line 124:
     )     )
 ) )
- 
 </code> </code>
 +
 +**Purpose**:\\ Deploy the registered model to a managed online endpoint so it can serve inference requests in real time via REST API.
  
 ==== Step 6: Create and Deploy Endpoint ==== ==== Step 6: Create and Deploy Endpoint ====
  
-<code>+<code ->
 from azure.ai.ml.entities import ManagedOnlineEndpoint, ManagedOnlineDeployment from azure.ai.ml.entities import ManagedOnlineEndpoint, ManagedOnlineDeployment
 import uuid import uuid
Line 149: Line 156:
     update_parameters={"defaults": {"deployment_name": "blue"}}     update_parameters={"defaults": {"deployment_name": "blue"}}
 ).result() ).result()
- 
 </code> </code>
 +
 +**Purpose**:\\ Designate the deployed model (e.g., "blue" deployment) as the default handler for all requests sent to the online endpoint.
  
 ==== Step 7: Query the Endpoint ==== ==== Step 7: Query the Endpoint ====
  
-<code>+<code ->
 import requests import requests
 import json import json
Line 175: Line 183:
 print("🔁 Status Code:", response.status_code) print("🔁 Status Code:", response.status_code)
 print("🔁 Response:", response.text) print("🔁 Response:", response.text)
- 
 </code> </code>
 +
 +**Purpose**:\\ Send a test HTTP POST request with a query term (e.g., a character or location name) and verify the endpoint returns correct analytics: count and average value of matches.
  
 [[ai_knowledge|AI Knowledge]] [[ai_knowledge|AI Knowledge]]
 +
 +
wiki/ai/notebook-collectibles-deployment.1749125807.txt.gz · Last modified: by ddehamer