{ "cells": [ { "cell_type": "markdown", "id": "07f18fcf-04de-4405-9c15-224becc96b24", "metadata": { "tags": [] }, "source": [ "# AutoGluon Environment Validation\n", "\n", "[![Open in SageMaker Studio Lab](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/aws/studio-lab-examples/blob/main/custom-environments/AutoGluon/env_validation.ipynb)\n", "\n", "AutoML is a technology that aims to automate the process of applying machine learning to real-world problems, or to automate the process of building machine learning models from data. [AutoGluon](https://github.com/awslabs/autogluon) enables easy-to-use and easy-to-extend AutoML with a focus on automated stack ensembling, deep learning, and real-world applications spanning text, image, and tabular data.\n", "\n", "In this notebook, we will set up AutoGluon in [Amazon SageMaker Studio Lab](https://studiolab.sagemaker.aws/), a free machine learning development environment, and train machine learning models using AutoGluon on a sample dataset.\n", "\n", "Run the following cell to generate a YAML file for creating the Anaconda virtual environment." ] }, { "cell_type": "code", "execution_count": null, "id": "34ecced8-486e-4f77-b912-6dc95dd0ec62", "metadata": {}, "outputs": [], "source": [ "%%writefile autogluon_cpu.yml\n", "# run in terminal: conda env create --file autogluon_cpu.yml\n", "# note: This command creates an environment that is larger than 4GB.\n", "name: autogluon_cpu\n", "dependencies:\n", " - python=3.9\n", " - conda\n", " - pip\n", " - ipykernel\n", " - nodejs\n", " - pip:\n", " - ipywidgets\n", " - setuptools\n", " - wheel\n", " - autogluon\n", " - jupyter_bokeh" ] }, { "cell_type": "markdown", "id": "d27d5c92-6601-4d8d-bd7a-7e69a85e8000", "metadata": {}, "source": [ "After `autogluon_cpu.yml` is generated, run `conda env create -f autogluon_cpu.yml` in your system terminal to create a virtual environment for Anaconda with AutoGluon set up.\n", "\n", "If the installation is successful, you should be able to select `autogluon_cpu:Python` in the popup that appears when you click the kernel name in the upper right corner of the screen. Switch to the `autogluon_cpu:Python` kernel. You should now be able to use AutoGluon." ] }, { "cell_type": "markdown", "id": "f6306047-ab5c-491a-aa07-1a436fd39efb", "metadata": {}, "source": [ "## Import Packages" ] }, { "cell_type": "code", "execution_count": null, "id": "13885941-3217-4b72-baf7-ed140ebffabc", "metadata": {}, "outputs": [], "source": [ "from autogluon.tabular import TabularDataset, TabularPredictor\n", "from IPython.display import HTML" ] }, { "cell_type": "markdown", "id": "4248d97f-a540-4e33-a112-d569860c52a6", "metadata": {}, "source": [ "## Train on Sample Dataset" ] }, { "cell_type": "code", "execution_count": null, "id": "0caa3a29-f341-4e6f-ab27-c8bb6cc6dfe6", "metadata": { "scrolled": true, "tags": [] }, "outputs": [], "source": [ "train_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/train.csv')\n", "test_data = TabularDataset('https://autogluon.s3.amazonaws.com/datasets/Inc/test.csv')\n", "predictor = TabularPredictor(label='class', path='ag-default').fit(train_data, time_limit=120) # Fit models for 120s" ] }, { "cell_type": "markdown", "id": "35954ea3-14b2-4a3f-b47a-fb4e57507493", "metadata": {}, "source": [ "## Check Models Summary" ] }, { "cell_type": "code", "execution_count": null, "id": "627eab9c-8073-4c88-aec5-48ca3656f510", "metadata": {}, "outputs": [], "source": [ "leaderboard = predictor.leaderboard(test_data)" ] }, { "cell_type": "code", "execution_count": null, "id": "888d191e-5dc9-4015-b7da-0f409f2d581c", "metadata": {}, "outputs": [], "source": [ "results = predictor.fit_summary()" ] }, { "cell_type": "code", "execution_count": null, "id": "e8acc5ec-92e3-4bfe-8b02-413439b7d1c3", "metadata": {}, "outputs": [], "source": [ "HTML(filename='ag-default/SummaryOfModels.html')" ] } ], "metadata": { "kernelspec": { "display_name": "autogluon_cpu:Python", "language": "python", "name": "conda-env-autogluon_cpu-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.12" } }, "nbformat": 4, "nbformat_minor": 5 }