Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
316 changes: 316 additions & 0 deletions Getting_Started/Teradataml_Widgets/AutoML_Tutorial.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "371d27f5",
"metadata": {},
"source": [
"<header>\n",
" <p style='font-size:36px;font-family:Arial; color:#F0F0F0; background-color: #00233c; padding-left: 20pt; padding-top: 20pt;padding-bottom: 10pt; padding-right: 20pt;'>\n",
" AutoML with Teradatamlwidgets\n",
" <br>\n",
" <img id=\"teradata-logo\" src=\"https://storage.googleapis.com/clearscape_analytics_demo_data/DEMO_Logo/teradata.svg\" alt=\"Teradata\" style=\"width: 125px; height: auto; margin-top: 20pt;\">\n",
" </p>\n",
"</header>"
]
},
{
"cell_type": "markdown",
"id": "56d7d758",
"metadata": {},
"source": [
"<p style = 'font-size:20px;font-family:Arial;color:#00233C'><b>Introduction</b></p>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'>The Teradataml Widgets (teradatamlwidgets) enhances teradataml’s built-in interaction capabilities with the Teradata Vantage™ Data and Analytics Platform. This provides visual components for scaled, in-Database Analytics with data that you keep in the Teradata Vantage Analytics Database within a notebook.</p>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial;color:#00233C'>With these components, in this notebook you will be able to:</p>\n",
"\n",
"<ul style = 'font-size:16px;font-family:Arial;color:#00233C'>\n",
" <li>Apply the AutoML function</li>\n",
"</ul>"
]
},
{
"cell_type": "markdown",
"id": "6a011d3f",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">\n",
"\n",
"##### For ClearScape:\n",
"<p style = 'font-size:16px;font-family:Arial;color:#E37C4D'><b>Install/update packages - Do this the first time running this (or Tutorial) Notebook ONLY.</b></p>\n",
" <p style = 'font-size:16px;font-family:Arial;color:#E37C4D'><b>NOTE: You will have to SHUTDOWN (file->shutdown) and reopen to run Demo.</b></p> "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4cd01e2e",
"metadata": {},
"outputs": [],
"source": [
"#pip install teradatamlwidgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2ca12836",
"metadata": {},
"outputs": [],
"source": [
"#from teradataml import create_context, get_context, remove_context\n",
"#%run -i ../../UseCases/startup.ipynb\n",
"#eng = create_context(host = 'host.docker.internal', username='demo_user', password = password)\n",
"#print(eng)"
]
},
{
"cell_type": "markdown",
"id": "175ba860",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">"
]
},
{
"cell_type": "markdown",
"id": "801b06ad",
"metadata": {},
"source": [
"After running the notebook cell below, a login screen shows. This login screen has a place for the Host, Username and Password.\n",
"\n",
"Once you type in this information, click Login."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6eb48ee4",
"metadata": {},
"outputs": [],
"source": [
"from teradatamlwidgets import login\n",
"ui = login.Ui()"
]
},
{
"cell_type": "markdown",
"id": "84f2ea00",
"metadata": {},
"source": [
"## Setting up the test train data\n",
"\n",
"### Load Data and DataFrame Objects\n",
"\n",
"In this example we will load some tables using teradataml. As we have already logged in, we can call teradataml load functions:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d9e67adf",
"metadata": {},
"outputs": [],
"source": [
"from teradataml import load_example_data\n",
"from teradataml import DataFrame\n",
"load_example_data(\"teradataml\", \"iris_input\")\n",
"iris = DataFrame.from_table(\"iris_input\")\n",
"iris.head()"
]
},
{
"cell_type": "markdown",
"id": "ae6c0466",
"metadata": {},
"source": [
"### Test Train Split"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fc773e0",
"metadata": {},
"outputs": [],
"source": [
"iris_sample = iris.sample(frac = [0.8, 0.2])\n",
"# Fetching train and test data\n",
"iris_train= iris_sample[iris_sample['sampleid'] == 1].drop('sampleid', axis=1)\n",
"iris_test = iris_sample[iris_sample['sampleid'] == 2].drop('sampleid', axis=1)\n",
"from teradataml import copy_to_sql\n",
"copy_to_sql(df = iris_train, table_name = \"iris_train\", if_exists=\"replace\")\n",
"copy_to_sql(df = iris_test, table_name = \"iris_test\", if_exists=\"replace\")"
]
},
{
"cell_type": "markdown",
"id": "e38b8ba4",
"metadata": {},
"source": [
"#### Code Explanation\n",
"Below is the basic set up of the notebook with the mandatory parameters\n",
"\n",
"Import the notebook using the code :\n",
"\n",
"`from teradatamlwidgets import auto_ml`\n"
]
},
{
"cell_type": "markdown",
"id": "92193dc4",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">\n",
"\n",
"## Example: AutoML Classification Standalone\n",
"\n",
"Run the cell and in the UI do the following:\n",
"\n",
"1. In Initialize tab, set Target Column to species and click Fit\n",
"2. After Fit has completed, click on the Leaderboard to see the top leaders\n",
"3. In the Prediction tab, click Execute and see the resulting predicted output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9076b46b",
"metadata": {},
"outputs": [],
"source": [
"from teradatamlwidgets import auto_ml\n",
"\n",
"ui = auto_ml.Ui(\n",
" task=\"Classification\", \n",
" training_table=iris_train, \n",
" predict_table='iris_input',\n",
" algorithms=['xgboost', 'knn'],\n",
" verbose=0,\n",
" max_runtime_secs=300,\n",
" max_models=5)"
]
},
{
"cell_type": "markdown",
"id": "36a451b3",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">\n",
"\n",
"## Predict Dataframe\n",
"In order to access the predicted output table, run the below command:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "80e0cb77",
"metadata": {},
"outputs": [],
"source": [
"ui.get_prediction_dataframe()"
]
},
{
"cell_type": "markdown",
"id": "f6b66670",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">\n",
"\n",
"## Leaderboard\n",
"In order to access the leaderboard, run the below command:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2b62c5a3",
"metadata": {},
"outputs": [],
"source": [
"ui.get_leaderboard()"
]
},
{
"cell_type": "markdown",
"id": "617ca0b6",
"metadata": {},
"source": [
"<hr style=\"height:2px;border:none;background-color:#00233C;\">\n",
"\n",
"## AutoML instance\n",
"In order to access the AutoML instance, run the below command:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09fa057c",
"metadata": {},
"outputs": [],
"source": [
"ui.get_auto_ml()"
]
},
{
"cell_type": "markdown",
"id": "bc345b04-3c59-43db-855b-1d2ddd254883",
"metadata": {},
"source": [
"## Example: AutoML Classification Integrated Function UI"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2aea4135-db32-4731-8fee-dd3153292974",
"metadata": {},
"outputs": [],
"source": [
"from teradatamlwidgets import analytic_functions\n",
"\n",
"inputs = ['iris_train']\n",
"ui = analytic_functions.Ui(function=\"AutoML\", inputs=inputs)"
]
},
{
"cell_type": "markdown",
"id": "72c55c42-fec8-4fd3-b394-22cfc03da87c",
"metadata": {},
"source": [
"<footer style=\"padding-bottom:35px; border-bottom:3px solid #91A0Ab\">\n",
" <div style=\"float:left;margin-top:14px\">ClearScape Analytics™</div>\n",
" <div style=\"float:right;\">\n",
" <div style=\"float:left; margin-top:14px\">\n",
" Copyright © Teradata Corporation - 2025. All Rights Reserved\n",
" </div>\n",
" </div>\n",
"</footer>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"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.12.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading