{ "cells": [ { "cell_type": "markdown", "source": [ "# क्लाउड में डेटा साइंस: \"Azure ML SDK\" का तरीका\n", "\n", "## परिचय\n", "\n", "इस नोटबुक में, हम सीखेंगे कि Azure ML SDK का उपयोग करके मॉडल को ट्रेन, डिप्लॉय और कंज्यूम कैसे करें।\n", "\n", "पूर्व-आवश्यकताएँ:\n", "1. आपने एक Azure ML वर्कस्पेस बनाया है।\n", "2. आपने [हार्ट फेलियर डेटासेट](https://www.kaggle.com/andrewmvd/heart-failure-clinical-data) को Azure ML में लोड किया है।\n", "3. आपने इस नोटबुक को Azure ML स्टूडियो में अपलोड किया है।\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": [ "## Azure ML प्रयोग तैयार करें\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-01T20:07:07+00:00", "source_file": "5-Data-Science-In-Cloud/19-Azure/notebook.ipynb", "language_code": "hi" } }, "nbformat": 4, "nbformat_minor": 2 }