Publish predictive dashboards in Amazon QuickSight using ML predictions from Amazon SageMaker Canvas

Understanding business trends, customer behavior, sales revenue, increase in demand, and buyer propensity all start with data. Exploring, analyzing, interpreting, and finding trends in data is essential for businesses to achieve successful outcomes.

Business analysts play a pivotal role in facilitating data-driven business decisions through activities such as the visualization of business metrics and the prediction of future events. Quick iteration and faster time-to-value can be achieved by providing these analysts with a visual business intelligence (BI) tool for simple analysis, supported by technologies like machine learning (ML).

Amazon QuickSight is a fully managed, cloud-native BI service that makes it easy to connect to your data, create interactive dashboards and reports, and share these with tens of thousands of users, either within QuickSight or embedded in your application or website. Amazon SageMaker Canvas is a visual interface that enables business analysts to generate accurate ML predictions on their own, without requiring any ML experience or having to write a single line of code.

In this post, we show how you can publish predictive dashboards in QuickSight using ML-based predictions from Canvas, without explicitly downloading predictions and importing into QuickSight. This solution will help you send predictions from Canvas to QuickSight, enabling you with accelerated decision-making using ML to achieve effective business outcomes.

Solution overview

In the following sections, we discuss steps that will help administrators configure the right permissions to seamlessly redirect users from Canvas to QuickSight. Then we detail how to build a model and run predictions, and demonstrate the business analyst experience.

Prerequisites

The following prerequisites are needed to implement this solution:

Make sure to use the same QuickSight Region as Canvas. You can change the Region by navigating from the profile icon on the QuickSight console.

Administrator setup

In this section, we detail the steps to set up IAM resources, prepare the data, train the data with the training dataset, and infer the validation dataset. Thereafter, we send the data to QuickSight for further analysis.

Create a new IAM policy for QuickSight access

To create an IAM policy, complete the following steps:

  1. On the IAM console, choose Policies in the navigation pane.
  2. Choose Create policy.
  3. On the JSON tab, enter the following permissions policy into the editor:

{     “Version”: “2012-10-17”,     “Statement”: [         {             “Effect”: “Allow”,             “Action”: [                 “quicksight:CreateDataSet”,                 “quicksight:ListNamespaces”,                 “quicksight:CreateDataSource”,                 “quicksight:PassDataSet”,                 “quicksight:PassDataSource”             ],             “Resource”:[                 “arn:aws:quicksight:*::datasource/*”, #replace account id                 “arn:aws:quicksight:*::user/*”, #replace account id                 “arn:aws:quicksight:*::namespace/*”, #replace account id                 “arn:aws:quicksight:*::dataset/*” #replace account id             ]         }     ] }

For details about the IAM policy language, see IAM JSON policy reference.

  1. Choose Next: Tags.
  2. You can add metadata to the policy by attaching tags as key-value pairs, then choose Next: Review.

For more information about using tags in IAM, see Tagging IAM resources.

  1. On the Review policy page, enter a name (for example, canvas-quicksight-access-policy) and an optional description of the policy.
  2. Review the Summary section to see the permissions that are granted by your policy.
  3. Choose Create policy to save your work.

After you create a policy, you can attach it to your execution role that grants your users the necessary permissions to send batch predictions to users in QuickSight.

Attach the policy to your Studio execution role

To attach the policy to your Studio execution role, complete the following steps:

  1. On the SageMaker console, choose Domains in the navigation pane.
  2. Choose your domain.
  3. Choose Domain settings.
  4. Copy the role name under Execution role.

  1. On the IAM console, choose Roles in the navigation pane.
  2. In the search bar, enter the execution role you copied, then choose the role.

  1. On the page for the user’s role, navigate to the Permissions policies section.
  2. On the Add permissions menu, choose Attach policies.
  3. Search for the previously created policy (canvas-quicksight-access-policy), select it, and choose Add permissions.

Now you have an IAM policy attached to your execution role that grants your users the necessary permissions to send batch predictions to users in QuickSight.

Download the datasets

Let’s download the datasets that we use to train the model and make the predictions:

Build a model and run predictions

In this section, we cover how we can build a model and run predictions on the loan dataset. Then we send the data to the QuickSight dashboard to get business insights.

Launch Canvas

To launch Canvas, complete the following steps:

  1. On the SageMaker console, choose Domains in the navigation pane.
  2. Choose your domain.
  3. On the Launch menu, choose Canvas.

Upload training and validation datasets

Complete the following steps to upload your datasets to Canvas:

  1. On the Canvas home page, choose Datasets.
  2. Choose Import data, then upload lending_club_loan_data_train.csv and lending_club_loan_data_test.csv.
  3. Choose Save & Close, then choose Import data.

Now let’s create new model.

  1. Choose My models in the navigation pane.
  2. Choose New model.
  3. Enter a name to your model (Loan_Prediction) and choose Create.

If this is the first time creating a Canvas model, you will be welcomed by an informative pop-up about how to build your first model in four simple steps. You can read this through, then come back to this guide.

  1. In the model view, on the Select tab, select the lending_club_loan_data_train dataset.

This dataset has 18 columns and 32,000 rows.

  1. Choose Select dataset.

  1. On the Build tab, choose the target column, in our case loan_status.

Canvas will automatically detect that this is a 3+ category prediction problem (also known as multi-class classification).

  1. If another model type is detected, change it manually by choosing Change type.

  1. Choose Quick build, and select Start quick build from the pop-up.

You can also choose Standard build, which goes through the complete AutoML cycle, generating multiple models before recommending the best model.

Now your model is being built. Quick build usually takes 2–15 minutes.

After the model is built, you can find the model status on the Analyze tab.

Make predictions with the model

After we build and train the model, we can generate predictions on this model.

  1. Choose Predict on the Analyze tab, or choose the Predict tab.
  2. Run a single prediction by choosing Single prediction and providing entries.

You will see the loan_status prediction on the right side of the page. You can copy the prediction by choosing Copy, or download it by choosing Download prediction. This is ideal for generating what-if scenarios and testing how different columns impact the predictions of our model.

  1. To run batch predictions, choose Batch prediction.

This is best when you’d like to make predictions for an entire dataset. You should make predictions with a dataset that matches your input dataset.

For each prediction or set of predictions, Canvas returns the predicted values and the probability of the predicted value being correct.

Let’s make predictions from the trained model using the validation dataset.

  1. Choose Select the dataset.
  2. Select lending_club_loan_data_test and choose Generate predictions.

When your predictions are ready, you can find them in the Dataset section. You can preview the prediction, download it to a local machine, delete it, or send it to QuickSight.

Send predictions to QuickSight

You can now share predictions from these ML models as QuickSight datasets that will serve as a new source for enterprise-wide dashboards. You can analyze trends, risks, and business opportunities. Through this capability, ML becomes more accessible to business teams so they can accelerate data-driven decision-making. Sharing data with QuickSight users grants them owner permissions on the dataset. Multiple inferred datasets can be sent at once to QuickSight.

Note that you can only send predictions to users in the default namespace of the QuickSight account, and the user must have the Author or Admin role in QuickSight. Predictions sent to QuickSight are available in the same Region as Canvas.

  1. Select the inferred batch dataset and choose Send to Amazon QuickSight.

  1. Enter one or multiple QuickSight user names to share the dataset with and press Enter.
  2. Choose Send to share data.

After you send your batch predictions, the QuickSight field for the datasets you sent shows as Sent.

  1. In the confirmation box, you can choose Open Amazon QuickSight to open your QuickSight application.
  2. If you’re done using Canvas, log out of the Canvas application.

You can send batch predictions to QuickSight for numeric, categorical prediction, and time series forecasting models. You can also send predictions generated with the bring your own model (BYOM) method. Single-label image prediction and multi-category text prediction models are excluded.

The QuickSight users that you’ve sent datasets to can open their QuickSight console and view the Canvas datasets that have been shared with them. Then they can create predictive dashboards with the data. For more information, see Getting started with Amazon QuickSight data analysis.

By default, all the users to whom you send predictions have owner permissions for the dataset in QuickSight. Owners are able to create analyses, refresh, edit, delete, and reshare datasets. The changes that owners make to a dataset change the dataset for all users with access. To change the permissions, go to the dataset in QuickSight and manage its permissions. For more information, see Viewing and editing the permissions users that a dataset is shared with.

Business analysts experience

With QuickSight, you can visualize your data to better understand it. We start by getting some high-level information.

  1. On the QuickSight console, choose Datasets in the navigation pane.
  2. Create an analysis on the batch prediction dataset shared from Canvas by choosing Create analysis on the drop-down options menu (three vertical dots).

  1. On the analysis page, choose the sheet name and rename to it Loan Data Analysis.

Let’s create a visual to show the count by loan status.

  1. For Visual types, choose Donut chart.
  2. Use the loan_status field for Group/Color.

We can see that 99% are fully paid, 1% are current, and 0% are charged off.

Now we add a second visual to show the amount of loans by status.

  1. On the top-left corner, choose the plus sign and choose Add visual.
  2. For Visual types, choose Waterfall chart.
  3. Use the loan_status field for Category.
  4. Use the loan_amount field for Value.

We can see that the total loan amount is around $88 million, with around $221,000 charged off.

Let’s try to detect some risk drivers for defaulting on loans.

  1. Choose the plus sign and choose Add visual.
  2. For Visual types, choose Horizontal bar chart.
  3. Use the loan_status field for Y axis.
  4. Use the loan_amount field for Value.
  5. Modify the Value field aggregation from Sum to Average.

We can see that on average, the loan amount was around $3,500 lower for the fully paid loans compared to the current loans, and around $3,500 lower for the fully paid loans compared to the charged off loans. There seems to be a correlation between the loan amount and the credit risk.

  1. To duplicate the visual, choose the options menu (three dots), choose Duplicate visual to, and choose This sheet.
  2. Choose the duplicated visual to modify its configuration.
  3. For Visual types, choose Horizontal bar chart.
  4. Use the loan_status field for Y axis.
  5. Use the loan_amount field for Value.
  6. Modify the Value field aggregation from Sum to Average.

You can create additional visuals to check for additional risk drivers. For example:

  • Loan term
  • Open credit lines
  • Revolving line utilization rate
  • Total credit lines
  1. After you add the visuals, publish the dashboard using the Share option on the analyses page and share the dashboard with the business stakeholders.

Clean up

To avoid incurring future charges, delete or shut down the resources you created while following this post. Refer to Logging out of Amazon SageMaker Canvas for more details.

Conclusion

In this post, we trained an ML model using Canvas without writing a single line of code thanks to its user-friendly interfaces and clear visualizations. We then generated single and batch predictions for this model in Canvas. To assess the trends, risks, and business opportunities across the enterprise, we sent the predictions of this ML model to QuickSight. As business analysts, we created various visualizations to assess the trends in QuickSight.

This capability is available in all Regions where Canvas is now supported. You can learn more on the Canvas product page and documentation.

About the Authors

Ajjay Govindaram is a Senior Solutions Architect at AWS. He works with strategic customers who are using AI/ML to solve complex business problems. His experience lies in providing technical direction as well as design assistance for modest to large-scale AI/ML application deployments. His knowledge ranges from application architecture to big data, analytics, and machine learning. He enjoys listening to music while resting, experiencing the outdoors, and spending time with his loved ones.

Varun Mehta is a Solutions Architect at AWS. He is passionate about helping customers build enterprise-scale well-architected solutions on the AWS Cloud. He works with strategic customers who are using AI/ML to solve complex business problems.

Shyam Srinivasan is a Principal Product Manager on the AWS AI/ML team, leading product management for Amazon SageMaker Canvas. Shyam cares about making the world a better place through technology and is passionate about how AI and ML can be a catalyst in this journey.



Source