Think Lab 2124 : Build & Deploy AI/ML Models w Multiple Datasets w AutoAI - Tutorial A
Published: 2021-05-18 17:39:08

##AutoAI Overview

AutoAI in Cloud Pak for Data automates ETL(Extract, Transform, and Load) and feature engineering process for relational data, saves data scientists months of manual data prep time and acheives results comparable to top performing data scientists.

The AutoAI graphical tool in Watson Studio automatically analyzes your data and generates candidate model pipelines customized for your predictive modeling problem.  These model pipelines are created iteratively as AutoAI analyzes your dataset and discovers data transformations, algorithms, and parameter settings that work best for your problem setting.  Results are displayed on a leaderboard, showing the automatically generated model pipelines ranked according to your problem optimization objective.

Collect your input data in a CSV file or files. Where possible, AutoAI will transform the data and impute missing values.

**Notes:**
* Your data source must contain a minimum of 100 records (rows).
* You can use the IBM Watson Studio Data Refinery tool to prepare and shape your data.
* Data can be a file added as connected data from a networked file system (NFS). Follow the instructions for adding a data connection of the type Mounted Volume. Choose the CSV file to add to the project so you can select it for training data.

##AutoAI Process

Using AutoAI, you can build and deploy a machine learning model with sophisticated training features and no coding. The tool does most of the work for you.

AutoAI automatically runs the following tasks to build and evaluate candidate model pipelines:
* Data pre-processing
* Automated model selection
* Automated feature engineering
* Hyperparameter optimization

In this Think Lab, you will see how to join several data sources and then build an AutoAI experiment from the joined data. The scenario we’ll explore in Part A of the Lab is for an outdoor company that wants to project sales for each product in multiple retails stores. You will learn how to join several data sources related to a fictional outdoor store named Go, then build an experiment that uses the data to train a machine learning experiment. You will then deploy the resulting model and use it to predict daily sales for each product Go sells.

##Project Requirements
[IBM Cloud (Free) Lite Tier Account](https://ibm.biz/think-2021)

##Project Setup Steps
1. [Create an IBM Cloud Lite Tier Account](https://ibm.biz/think-2021)
2. Create a Watson Studio Instance
3. Provision Watson Machine Learning & Cloud Object Storage Instances
4. Create a New Project
5. Download the Go Sample Dataset from the Gallery
6. Unzip the Go Sample Dataset's .zip File
7. Add the Go Sample Datasets to the Project

##Project Setup
###1. [Create an IBM Cloud Lite Tier Account](https://ibm.biz/think-2021)

###2. Create a Watson Studio Instance
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zb8hcl0pmwak80d8et1e.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rbkgpk798s3zvvwsiu3f.png)

###3. Provision Watson Machine Learning & Cloud Object Storage Instances
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7fkz6jwkqzofa45m9sad.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jevgeecxtyyju6tc1u44.png)

###4. Create a New Project
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2owaa2lr5vfidaghh5b2.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5phnlg3t0d8nfn54e35p.png)

###5. Download the Go Sample Dataset from the Gallery
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0erxiom2druj0lvxj45.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lpwxmnxgl5vfxt4j5ey4.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfgr6qsbmhusmw9c23iy.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9vkidltsku9rubqvhk5p.png)

###6. Unzip the Go Sample Dataset's .zip File
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q51w8ffwlgurhx7u2gwd.png)

###7. Add the Go Sample Datasets to the Project
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjfuqpmzwroq7883e624.png)

In Tutorial A of this **Think Lab**, you will learn how to join several data sources related to a fictional outdoor store named Go, then build an experiment that uses the data to train a machine learning experiment. You will then deploy the resulting model and use it to predict daily sales for each product Go sells.

Joining data also allows for a specialized set of feature transformations and advanced data aggregators. After building the pipelines, you can explore the factors that produced each pipeline.

##About the Data

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tlph1tlofh0a8nla4o4l.png)

The data you will join contains the following information:
* **Daily_sale**: the GO company has many retailers selling its outdoor products, the daily sale table is a timeseries of sale records where the DATE and QUANTITY column indicate the sale quantity and the sale date for each product in a retail store.
* **Products**: this table keeps product information such as product type and product names.
* **Retailers**: this table keeps retailer infor mation such as retailer names and address.
* **Methods**: this table keeps order methods such as Via Telephone, Online or Email
* **Go**: the GO company is interested using this data to predict its daily sale for every product in its retail stores. The prediction target column is QUANTITY in the go table and DATE column indicates the cutoff time when prediction should be made.

##Steps Overview
This tutorial presents the basic steps for joining data sets then training a machine learning model using AutoAI:
* Add and join the data
* Train the experiment
* Deploy the trained model
* Test the deployed model

##Think Lab - Tutorial A Steps
1. Create a New AutoAI Experiment
2. Build the Data Join Schema
3. Update the AutoAI Experiment Settings
4. Run the AutoAI Experiment
5. Explore the Holdout & Training Data Insights
6. Deploy the Trained Model
7. Score the Model
8. View the Prediction Results

##Think Lab - Tutorial A: Build & Deploy a Data Join Experiment 
###1. Create a New AutoAI Experiment

####Add a New AutoAI Experiment to the Project
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8xq45cprsd139iqemye2.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pjveg2rgjly6wgf2l0g.png)

####Associate a Machine Learning Service Instance
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzqf34wrkejlls0tey0n.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98krw1o0wsv4lp455159.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aej9wehlnt5znl0a5ern.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/puye2u4zduzplnloup5x.png)

####Select the Go Sample Datasets
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r2u756q4k8tywk0m2p2k.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/90g6dpc8svcoac6ebuju.png)

###2. Build the Data Join Schema

The main source contains the prediction target for the experiment. Select **go_1k.csv** as the main source, then click **Configure join**.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nj09omr1ri7teouudkz5.png)

In the data join canvas you will create a left join that connects all of the data sources to the main source.

####Use the Data Join Table to Build the Schema
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jk0nu8uuzol6n8e7v0ac.png)

Drag from the node on one end of the **go_1k.csv** box to the node on the end of **go_products.csv**.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cofujbjiz3y2n33d8hvu.png)

In the panel for configuring the join, click **(+)** to add the suggested key **product_number** as the join key.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/joy4vw8qy0bjimv6199r.png)

Repeat the data join process until you have joined all the data tables.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q5egu6n4y0ug6glzw6wz.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hgsd76y284g0eetrkncz.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qv7nx3tqgoc3n089dnx.png)

####The Completed Data Join Schema Should Look Like This:
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0qv7nx3tqgoc3n089dnx.png)

Choose **Quantity** as the column to predict.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2nvgorlehnjdrjoj1opm.png)
AutoAI analyzes your data and determines that the Quanity column contains a wide range of numeric information, making this data suitable for a regression model. The default metric for a regression model is **Root Mean Squared Error (RMSE)**.

**Note**: 
* Based on analyzing a subset of the data set, AutoAI chooses a default model type: binary classification, multiclass classification, or regression. Binary is selected if the target column has two possible values, multiclass if it has a discrete set of 3 or more values, and regression if the target column is a continuous numeric variable. You can override this selection.
* AutoAI chooses a default metric for optimizing. For example, the default metric for a binary classification model is Accuracy.
* By default, ten percent of the training data is held out to test the performance of the model.

###3. Update the AutoAI Experiment Settings
####Click **Experiment settings**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/huqg3jqvqwg0yp8e97q3.png)
####Click the **Join** Tab on the **Data sources** Page

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/edxp33mqunotpyp3zrjd.png)
####Enable the **Timestamp Threshold**

In the main data table, **go_1k.csv**, choose **Date** as the Cutoff time column and enter **dd/MM/yyyy** as the date format. No data after the date in the cutoff column will be considered for training the pipelines. **Note**: the data format must exactly match the data or an error results.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8bovebmgjznma1kvoj4.png)
In the data table **go_daily_sales.csv**, choose **Date** as a timestamp column so that AutoAI can enhance the set of features with timeseries related features. Enter **dd/MM/yyyy** as the date format. **Note**: The data format must exactly match the format in the data source or you will get an error running the experiment.

####Specify the **Runtime Settings**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p5d9ycn72l7ziol1n3px.png)
After defining the experiment, you can allocate the resources for training the pipelines. Click **Runtime** to switch to the Runtime tab. Increase the number of executors to **10**. Click **Save settings** to save the configuration changes.

###4. Run the AutoAI Experiment
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h3b1wee4hlovs7hijm14.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s6xsopv1y0ntpjybwjty.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/531qq7sjkwlcu8xo89ye.png)

###5. Explore the Holdout & Training Data Insights
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylk75lq6h88he0gexbve.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/txqnjlof45cu0gc85zdi.png)

###6. Deploy the Trained Model
####Click **Save as** and Select **Model**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqzvykt9kv76xf89csz5.png)

####Click **Create**
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4b4iv53ez0tlpa3ua8ml.png)

####Create a New Deployment Space
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7my93k0h7jci9ytvh7ho.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u0sz213kee06ivn21bbk.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p65p2iiwbg8u4qe1hftz.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqiw2pz38kr9dyeoycyz.png)

####Add the Go Sample Datasets to the Deployment Space
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38w5z2rl2ot4atgsfi7i.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sybjhpxkp6vo371ifs5j.png)

####Promote the Trained Model to the Deployment Space
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ij5cct0exrstys2vxbyi.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3l4hx8y2pse0i0fb0619.png)

####Associate a Machine Learning Service Instance w the Deployment Space
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k7dbjclh9ykjpdjrksjm.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7y0kg44xdqbkaqkmud2s.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82cvlj345w4gatp8wxrc.png)

####Deploy the Trained Model
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/abpppa518id5exm7o2nt.png)

####Create a New Batch Deployment
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14au2lfg27c6qqbv2i16.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/98nqj9pdok4tj1a3w66y.png)

###7. Score the Model
To score the model, you create a batch job that will pass new data to the model for processing, then output the predictions to a file. **Note**: For this tutorial, you will submit the training files as the scoring files as a way to demonstrate the process and view results.

####Create a New Batch Job
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tklhk0enixh2oriwq0m5.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2zw78cz98lgwln8h9f80.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/04i13czdb004ie1em8hl.png)
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhfb3qlifroo5072zcdc.png)

####Add the Scoring Files
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4hb0o2fcktiyafnqncgl.png)

You will see the training files listed. For each training file, click the **Edit** icon and choose the corresponding scoring file.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xaovpx11t9lim39szus6.png)

**WARNING** : Schema mismatch. The column types in this data asset do not match the column types in the Model Schema. Click **Continue** to select anyway.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kqdy55rkny4komnx6vrj.png)

Add **go-sales-predictions.csv** as the Ouput file name.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2t5z2o9lby84n65v3o2u.png)

####Run the Batch Job
When the uploads are complete, click **Create** to run the job.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zhsmmmksk057o4sn8wln.png)

####View the Batch Job
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8l2o4y26xrploq3soumh.png)

####Wait for the Batch Job to Complete
Starting...
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ioizhhxz23r4cmejvx3h.png)

Running...
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5qateouu7dl0kyzh1uqw.png)

Completed
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n15s36apejnp8vgovj0u.png)

###8. View the Prediction Results
Download **go-sales-predictions.csv** to view the prediction results.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4aoyiungag3ghigmo15b.png)

View the **go-sales-predictions.csv** prediction results in Excel.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmva2k41f6zchna9ym06.png)


###Tune in Next Week for **Tutorial B: AutoAI Data Join Multi-Classification**
In Tutorial B of this **Think Lab**, you will use IBM AutoAI to automate data analysis for a dataset collected from a fictional call center. The objective of the analysis is to gain more insight into factors that impact customer experience so that the company can improve customer service. The data consists of historical information about customer interaction with call agents, call type, customer wireless plans, and call type resolution.