You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
319 lines
12 KiB
319 lines
12 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"# ਕਲਾਉਡ ਵਿੱਚ ਡਾਟਾ ਸਾਇੰਸ: \"Azure ML SDK\" ਦਾ ਤਰੀਕਾ\n",
|
|
"\n",
|
|
"## ਪਰਿਚਯ\n",
|
|
"\n",
|
|
"ਇਸ ਨੋਟਬੁੱਕ ਵਿੱਚ, ਅਸੀਂ ਸਿੱਖਾਂਗੇ ਕਿ Azure ML SDK ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਮਾਡਲ ਨੂੰ ਟ੍ਰੇਨ, ਡਿਪਲੌਇ ਅਤੇ ਕਨਜ਼ਿਊਮ ਕਿਵੇਂ ਕਰਨਾ ਹੈ।\n",
|
|
"\n",
|
|
"ਪੂਰਵ-ਸ਼ਰਤਾਂ:\n",
|
|
"1. ਤੁਸੀਂ ਇੱਕ Azure ML ਵਰਕਸਪੇਸ ਬਣਾਇਆ ਹੈ।\n",
|
|
"2. ਤੁਸੀਂ [Heart Failure dataset](https://www.kaggle.com/andrewmvd/heart-failure-clinical-data) ਨੂੰ Azure ML ਵਿੱਚ ਲੋਡ ਕੀਤਾ ਹੈ।\n",
|
|
"3. ਤੁਸੀਂ ਇਸ ਨੋਟਬੁੱਕ ਨੂੰ Azure ML Studio ਵਿੱਚ ਅਪਲੋਡ ਕੀਤਾ ਹੈ।\n",
|
|
"\n",
|
|
"ਅਗਲੇ ਕਦਮ ਹਨ:\n",
|
|
"\n",
|
|
"1. ਮੌਜੂਦਾ ਵਰਕਸਪੇਸ ਵਿੱਚ ਇੱਕ ਐਕਸਪੇਰੀਮੈਂਟ ਬਣਾਓ।\n",
|
|
"2. ਇੱਕ ਕੰਪਿਊਟ ਕਲਸਟਰ ਬਣਾਓ।\n",
|
|
"3. ਡਾਟਾਸੈਟ ਲੋਡ ਕਰੋ।\n",
|
|
"4. AutoMLConfig ਦੀ ਵਰਤੋਂ ਕਰਕੇ AutoML ਨੂੰ ਕਨਫਿਗਰ ਕਰੋ।\n",
|
|
"5. AutoML ਐਕਸਪੇਰੀਮੈਂਟ ਚਲਾਓ।\n",
|
|
"6. ਨਤੀਜਿਆਂ ਦੀ ਜਾਂਚ ਕਰੋ ਅਤੇ ਸਭ ਤੋਂ ਵਧੀਆ ਮਾਡਲ ਪ੍ਰਾਪਤ ਕਰੋ।\n",
|
|
"7. ਸਭ ਤੋਂ ਵਧੀਆ ਮਾਡਲ ਨੂੰ ਰਜਿਸਟਰ ਕਰੋ।\n",
|
|
"8. ਸਭ ਤੋਂ ਵਧੀਆ ਮਾਡਲ ਨੂੰ ਡਿਪਲੌਇ ਕਰੋ।\n",
|
|
"9. ਐਂਡਪੋਇੰਟ ਨੂੰ ਕਨਜ਼ਿਊਮ ਕਰੋ।\n",
|
|
"\n",
|
|
"## Azure Machine Learning SDK-ਵਿਸ਼ੇਸ਼ ਇੰਪੋਰਟ\n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"from azureml.core import Workspace, Experiment\n",
|
|
"from azureml.core.compute import AmlCompute\n",
|
|
"from azureml.train.automl import AutoMLConfig\n",
|
|
"from azureml.widgets import RunDetails\n",
|
|
"from azureml.core.model import InferenceConfig, Model\n",
|
|
"from azureml.core.webservice import AciWebservice"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਵਰਕਸਪੇਸ ਸ਼ੁਰੂ ਕਰੋ \n",
|
|
"ਸੰਰਖਿਤ ਕਨਫਿਗਰੇਸ਼ਨ ਤੋਂ ਵਰਕਸਪੇਸ ਆਬਜੈਕਟ ਸ਼ੁਰੂ ਕਰੋ। ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਕਨਫਿਗ ਫਾਈਲ .\\config.json 'ਤੇ ਮੌਜੂਦ ਹੈ। \n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"ws = Workspace.from_config()\n",
|
|
"print(ws.name, ws.resource_group, ws.location, ws.subscription_id, sep = '\\n')"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਐਜ਼ਰ ਐਮਐਲ ਪ੍ਰਯੋਗਸ਼ਾਲਾ ਬਣਾਓ\n",
|
|
"\n",
|
|
"ਆਓ ਉਸ ਵਰਕਸਪੇਸ ਵਿੱਚ ਇੱਕ ਪ੍ਰਯੋਗਸ਼ਾਲਾ 'aml-experiment' ਨਾਮ ਦੀ ਬਣਾਈਏ ਜਿਸਨੂੰ ਅਸੀਂ ਹੁਣੇ ਸ਼ੁਰੂ ਕੀਤਾ ਹੈ।\n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"experiment_name = 'aml-experiment'\n",
|
|
"experiment = Experiment(ws, experiment_name)\n",
|
|
"experiment"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਕੰਪਿਊਟ ਕਲੱਸਟਰ ਬਣਾਓ \n",
|
|
"ਤੁਹਾਨੂੰ ਆਪਣੇ AutoML ਰਨ ਲਈ ਇੱਕ [ਕੰਪਿਊਟ ਟਾਰਗੇਟ](https://docs.microsoft.com/azure/machine-learning/concept-azure-machine-learning-architecture#compute-target) ਬਣਾਉਣ ਦੀ ਲੋੜ ਹੋਵੇਗੀ। \n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"aml_name = \"heart-f-cluster\"\n",
|
|
"try:\n",
|
|
" aml_compute = AmlCompute(ws, aml_name)\n",
|
|
" print('Found existing AML compute context.')\n",
|
|
"except:\n",
|
|
" print('Creating new AML compute context.')\n",
|
|
" aml_config = AmlCompute.provisioning_configuration(vm_size = \"Standard_D2_v2\", min_nodes=1, max_nodes=3)\n",
|
|
" aml_compute = AmlCompute.create(ws, name = aml_name, provisioning_configuration = aml_config)\n",
|
|
" aml_compute.wait_for_completion(show_output = True)\n",
|
|
"\n",
|
|
"cts = ws.compute_targets\n",
|
|
"compute_target = cts[aml_name]"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਡਾਟਾ \n",
|
|
"ਯਕੀਨੀ ਬਣਾਓ ਕਿ ਤੁਸੀਂ ਡਾਟਾਸੈੱਟ ਨੂੰ Azure ML 'ਤੇ ਅੱਪਲੋਡ ਕਰ ਦਿੱਤਾ ਹੈ ਅਤੇ ਕੁੰਜੀ ਦਾ ਨਾਮ ਡਾਟਾਸੈੱਟ ਦੇ ਨਾਮ ਨਾਲ ਇੱਕੋ ਜਿਹਾ ਹੈ। \n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"key = 'heart-failure-records'\n",
|
|
"dataset = ws.datasets[key]\n",
|
|
"df = dataset.to_pandas_dataframe()\n",
|
|
"df.describe()"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"automl_settings = {\n",
|
|
" \"experiment_timeout_minutes\": 20,\n",
|
|
" \"max_concurrent_iterations\": 3,\n",
|
|
" \"primary_metric\" : 'AUC_weighted'\n",
|
|
"}\n",
|
|
"\n",
|
|
"automl_config = AutoMLConfig(compute_target=compute_target,\n",
|
|
" task = \"classification\",\n",
|
|
" training_data=dataset,\n",
|
|
" label_column_name=\"DEATH_EVENT\",\n",
|
|
" enable_early_stopping= True,\n",
|
|
" featurization= 'auto',\n",
|
|
" debug_log = \"automl_errors.log\",\n",
|
|
" **automl_settings\n",
|
|
" )"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"remote_run = experiment.submit(automl_config)"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"RunDetails(remote_run).show()"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"best_run, fitted_model = remote_run.get_output()"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"best_run.get_properties()"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"model_name = best_run.properties['model_name']\n",
|
|
"script_file_name = 'inference/score.py'\n",
|
|
"best_run.download_file('outputs/scoring_file_v_1_0_0.py', 'inference/score.py')\n",
|
|
"description = \"aml heart failure project sdk\"\n",
|
|
"model = best_run.register_model(model_name = model_name,\n",
|
|
" description = description,\n",
|
|
" tags = None)"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਸਭ ਤੋਂ ਵਧੀਆ ਮਾਡਲ ਨੂੰ ਡਿਪਲੌਇ ਕਰੋ\n",
|
|
"\n",
|
|
"ਹੇਠਾਂ ਦਿੱਤਾ ਕੋਡ ਚਲਾਓ ਤਾਂ ਜੋ ਸਭ ਤੋਂ ਵਧੀਆ ਮਾਡਲ ਨੂੰ ਡਿਪਲੌਇ ਕੀਤਾ ਜਾ ਸਕੇ। ਤੁਸੀਂ ਡਿਪਲੌਇਮੈਂਟ ਦੀ ਸਥਿਤੀ ਨੂੰ Azure ML ਪੋਰਟਲ ਵਿੱਚ ਦੇਖ ਸਕਦੇ ਹੋ। ਇਹ ਕਦਮ ਕੁਝ ਮਿੰਟ ਲੈ ਸਕਦਾ ਹੈ।\n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"inference_config = InferenceConfig(entry_script=script_file_name, environment=best_run.get_environment())\n",
|
|
"\n",
|
|
"aciconfig = AciWebservice.deploy_configuration(cpu_cores = 1,\n",
|
|
" memory_gb = 1,\n",
|
|
" tags = {'type': \"automl-heart-failure-prediction\"},\n",
|
|
" description = 'Sample service for AutoML Heart Failure Prediction')\n",
|
|
"\n",
|
|
"aci_service_name = 'automl-hf-sdk'\n",
|
|
"aci_service = Model.deploy(ws, aci_service_name, [model], inference_config, aciconfig)\n",
|
|
"aci_service.wait_for_deployment(True)\n",
|
|
"print(aci_service.state)"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"source": [
|
|
"## ਐਂਡਪੌਇੰਟ ਨੂੰ ਵਰਤੋ \n",
|
|
"ਤੁਸੀਂ ਹੇਠਾਂ ਦਿੱਤੇ ਨਮੂਨੇ ਵਿੱਚ ਇਨਪੁਟਸ ਸ਼ਾਮਲ ਕਰ ਸਕਦੇ ਹੋ।\n"
|
|
],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"data = {\n",
|
|
" \"data\":\n",
|
|
" [\n",
|
|
" {\n",
|
|
" 'age': \"60\",\n",
|
|
" 'anaemia': \"false\",\n",
|
|
" 'creatinine_phosphokinase': \"500\",\n",
|
|
" 'diabetes': \"false\",\n",
|
|
" 'ejection_fraction': \"38\",\n",
|
|
" 'high_blood_pressure': \"false\",\n",
|
|
" 'platelets': \"260000\",\n",
|
|
" 'serum_creatinine': \"1.40\",\n",
|
|
" 'serum_sodium': \"137\",\n",
|
|
" 'sex': \"false\",\n",
|
|
" 'smoking': \"false\",\n",
|
|
" 'time': \"130\",\n",
|
|
" },\n",
|
|
" ],\n",
|
|
"}\n",
|
|
"\n",
|
|
"test_sample = str.encode(json.dumps(data))"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"source": [
|
|
"response = aci_service.run(input_data=test_sample)\n",
|
|
"response"
|
|
],
|
|
"outputs": [],
|
|
"metadata": {}
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"\n---\n\n**ਅਸਵੀਕਾਰਨਾ**: \nਇਹ ਦਸਤਾਵੇਜ਼ AI ਅਨੁਵਾਦ ਸੇਵਾ [Co-op Translator](https://github.com/Azure/co-op-translator) ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਅਨੁਵਾਦ ਕੀਤਾ ਗਿਆ ਹੈ। ਜਦੋਂ ਕਿ ਅਸੀਂ ਸਹੀ ਹੋਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਹਾਂ, ਕਿਰਪਾ ਕਰਕੇ ਧਿਆਨ ਵਿੱਚ ਰੱਖੋ ਕਿ ਸਵੈਚਾਲਿਤ ਅਨੁਵਾਦਾਂ ਵਿੱਚ ਗਲਤੀਆਂ ਜਾਂ ਅਸੁਚੱਜੇਪਣ ਹੋ ਸਕਦੇ ਹਨ। ਮੂਲ ਦਸਤਾਵੇਜ਼ ਨੂੰ ਇਸਦੀ ਮੂਲ ਭਾਸ਼ਾ ਵਿੱਚ ਅਧਿਕਾਰਤ ਸਰੋਤ ਮੰਨਿਆ ਜਾਣਾ ਚਾਹੀਦਾ ਹੈ। ਮਹੱਤਵਪੂਰਨ ਜਾਣਕਾਰੀ ਲਈ, ਪੇਸ਼ੇਵਰ ਮਨੁੱਖੀ ਅਨੁਵਾਦ ਦੀ ਸਿਫਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ। ਇਸ ਅਨੁਵਾਦ ਦੀ ਵਰਤੋਂ ਤੋਂ ਪੈਦਾ ਹੋਣ ਵਾਲੇ ਕਿਸੇ ਵੀ ਗਲਤਫਹਿਮੀ ਜਾਂ ਗਲਤ ਵਿਆਖਿਆ ਲਈ ਅਸੀਂ ਜ਼ਿੰਮੇਵਾਰ ਨਹੀਂ ਹਾਂ।\n"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"orig_nbformat": 4,
|
|
"language_info": {
|
|
"name": "python"
|
|
},
|
|
"coopTranslator": {
|
|
"original_hash": "af42669556d5dc19fc4cc3866f7d2597",
|
|
"translation_date": "2025-09-02T05:38:46+00:00",
|
|
"source_file": "5-Data-Science-In-Cloud/19-Azure/notebook.ipynb",
|
|
"language_code": "pa"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
} |