Article
· Apr 17, 2023 4m read

Create, Predict and explore ML Models by using InterSystems Cloud SQL / IntegratedML

Hi Community,
In this article, I will introduce my application iris-mlm-explainer

This web application connects to InterSystems Cloud SQL to create, train, validate, and predict ML models, make Predictions and display a dashboard of all the trained models with an explanation of the workings of a fitted machine learning model. The dashboard provides interactive plots on model performance, feature importances, feature contributions to individual predictions, partial dependence plots, SHAP (interaction) values, visualization of individual decision trees, etc.

 

Prerequisites

Getting Started

We will follow the below steps to create and view the explainer dashboard of a model :

  • Step 1 : Close/git Pull the repo
  • Step 2 : Login to InterSystems Cloud SQL Service Portal
    • Step 2.1 : Add and Manage Files
    • Step 2.2 : Import DDL and data files
    • Step 2.3 : Create Model
    • Step 2.4 : Train Model
    • Step 2.5 : Validate Model
  • Step 3 : Activate Python virtual environment
  • Step 4 : Run Web Application for prediction
  • Step 5 : Explore the Explainer dashboard

Step 1 : Close/git Pull the repo

So Let us start with the first Step

Create a folder and Clone/git pull the repo into any local directory

git clone https://github.com/mwaseem75/iris-mlm-explainer.git

 

Step 2 : Log in to InterSystems Cloud SQL Service Portal

Log in to InterSystems Cloud Service Portal
image

 

 

Select the running deployment

image

 

Step 2.1 : Add and Manage Files

Click on Add and Manage Files

image

Repo contains USA_Housing_tables_DDL.sql(DDL to create tables), USA_Housing_train.csv(training data), and USA_Housing_validate.csv(For validation) files under the datasets folder. Select the upload button to add these files.

AddFiles

 

Setp 2.2 : Import DDL and data files

Click on Import files, then click on DDL or DML statement(s) radio button, then click the next button

ImportDDL

Click on Intersystems IRIS radio button and then click on the next button

IsIRIS

Select USA_Housing_tables_DDL.sql file and then press the import files button

ImportFileDDL

Click on Import from the confirmation dialog to create the table

importconfirm

importDone

 

Click on SQL Query tools to verify that tables are created

checkTblCreated

Import data files

Click on Import files, then click on CSV data radio button, then click the next button

csv1

Select USA_Housing_train.csv file and click the next button

csv2

 

Select USA_Housing_train.csv file from the dropdown list, check import rows as a header row and Field names in header row match column names in selected table and click import files

csv3

click on import in the confirmation dialog

csv4

Make sure 4000 rows are updated

csv5

Do the same steps to import USA_Housing_validate.csv file which contains 1500 records

csv6

Setp 2.3 : Create Model

Click on IntegratedM tools and select Create Panel.

Enter USAHousingPriceModel in the Model Name field, Select usa_housing_train table and Price in the field to predict dropdown. Click on create model button to create the model

createModel

 

Setp 2.4 : Train Model

select Train Panel, Select USAHousingPriceModel from the model to train dropdownlist and enter USAHousingPriceModel_t1 in the train model name field

TRAIN1

Model will be trained once Run Status completed

TRAIN2

 

Setp 2.5 : Validate Model

Select Validate Panel, Select USAHousingPriceModel_t1 from Trained model to validate dropdownlist, select usa_houseing_validate from Table to validate model from dropdownlist and click on validate model button

image

 

Click on show validation metrics to view metrics

showValidation

 

Click on the chart icon to view the Prediction VS Actual graph

validationChart

 

Step 3 : Activate Python virtual environment

The repository already contains a python virtual environment folder (venv) along with all the required libraries.

All we need is to just activate the environment
On Unix or MacOS:

$ source venv/bin/activate

On Windows:

venv\scripts\activate


Step 4 : Set InterSystems Cloud SQL connection parameters

Repo contains config.py file. Just open and set the parameters
image
Put same values used in InterSystems Cloud SQL
image

 

Step 4 : Run Web Application for prediction

Run the below command in the virtual environment to start our main application

python app.py

image

Navigate to http://127.0.0.1:5000/ to run the application

image

Enter Age of house, No of rooms, No of bedroom and Area population to get the prediction

image

Step 5 : Explore the Explainer dashboard

Finally, run the below command in virtual environment to start our main application

python expdash.py

imageimage
image

Navigate to http://localhost:8050/ to run the application
image

Application will list all the trained models along with our USAHousingPriceModel. Navigate to "go to dashboard" hyperlink to view model explainer

Feature Importances. Which features had the biggest impact?
image

 

Quantitative metrics for model performance, How close is the predicted value to the observed?
image

 

Prediction and How has each feature contributed to the prediction?
image

 

Adjust the feature values to change the prediction
image

Shap Summary, Ordering features by shap values
image

 

Interactions Summary, Ordering features by shap interaction value
image

 

Decision Trees, Displaying individual decision trees inside Random Forest
image

 

Thanks

Discussion (6)2
Log in or sign up to continue