{ "cells": [ { "cell_type": "markdown", "source": [ "# क्लाउडमा डाटा साइन्स: \"Azure ML SDK\" तरिका\n", "\n", "## परिचय\n", "\n", "यस नोटबुकमा, हामी Azure ML SDK प्रयोग गरेर कसरी मोडेललाई प्रशिक्षण, परिनियोजन, र उपभोग गर्ने भन्ने कुरा सिक्नेछौं।\n", "\n", "पूर्व-आवश्यकताहरू:\n", "1. तपाईंले Azure ML कार्यक्षेत्र (Workspace) सिर्जना गर्नुभएको छ।\n", "2. तपाईंले [Heart Failure dataset](https://www.kaggle.com/andrewmvd/heart-failure-clinical-data) Azure ML मा लोड गर्नुभएको छ।\n", "3. तपाईंले यो नोटबुक Azure ML स्टुडियोमा अपलोड गर्नुभएको छ।\n", "\n", "अर्को चरणहरू:\n", "\n", "1. अवस्थित कार्यक्षेत्रमा एउटा प्रयोग (Experiment) सिर्जना गर्नुहोस्।\n", "2. एउटा कम्प्युट क्लस्टर सिर्जना गर्नुहोस्।\n", "3. डाटासेट लोड गर्नुहोस्।\n", "4. AutoMLConfig प्रयोग गरेर AutoML कन्फिगर गर्नुहोस्।\n", "5. AutoML प्रयोग परीक्षण (Experiment) चलाउनुहोस्।\n", "6. नतिजाहरू अन्वेषण गर्नुहोस् र उत्कृष्ट मोडेल प्राप्त गर्नुहोस्।\n", "7. उत्कृष्ट मोडेल दर्ता गर्नुहोस्।\n", "8. उत्कृष्ट मोडेल परिनियोजन गर्नुहोस्।\n", "9. अन्त बिन्दु (Endpoint) उपभोग गर्नुहोस्।\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 प्रयोग गरेर एउटा प्रयोग (Experiment) बनाउनुहोस्\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:37:37+00:00", "source_file": "5-Data-Science-In-Cloud/19-Azure/notebook.ipynb", "language_code": "ne" } }, "nbformat": 4, "nbformat_minor": 2 }