Creating Awesome Cross-Platform Consumer Experiences with Flutter and SAS: Part 2 of 3

Sathish Gangichetty
May 7 · 7 min read

Note: As mentioned in the title, this is part2. I highly recommend that you start with Part1 if you haven’t already read it.

As a quick refresher, we are building an AI-first retail/telco application that

  1. Scores customer interactions using backend services that are operating in either real-time/streaming mode
  2. Takes advantage of a modern cross platform development framework — Flutter thereby allowing us to operate on iOS, Android, the Web and other form factors and platforms, if need be.
  3. Hits cloud APIs when its appropriate for quick insights in cases where we don’t need a full on ML Development Lifecycle.

If you’ve forgotten what our app does, check out the final end product here

Specifically for this post, we’ll focus on the details of how-to generate scores to predict customer churn/retention, segmentation and click propensity. The post assumes some familiarity with Dart and Flutter. But don’t worry even otherwise, I’ve deliberately kept the content somewhat light on technical details to allow most people to follow along ok.

The first two features that predict churn and segmentation will use SAS Event Stream Processing (SAS ESP) and the Click Propensity prediction will use the SAS Micro Analytic Service. We will talk to all of these “scoring services” over http(s) using REST calls. But first, if you’re wondering why SAS ESP — the reason is two-fold (for us).

a. It lets you score events as soon as they happen, allowing for low-latency, high throughput scoring that can scale to large volumes of incoming data

b. It also packs in an array of online algorithms which negate the need for any offline model development. Yes, you read that right. There is no need to run behind the mythical data scientist/MLE to get a model thats works. Sure, you might want to still engage in the traditional offline training, online scoring process where appropriate or when you know that the upshot of offline training is definitely advantageous.

In any case, since our application is demonstrating the wide array of possibilities, let’s showcase both the types of scoring models for SAS ESP. We’ll do churn scoring using an ASTORE (analytical store) binary file which compacts the ML scoring logic into a file that can be hot loaded in-memory during runtime and can be executed at high speeds via SAS ESP. It is important to remember, that in any modeling exercise, what matters first is the ability to make the model useful and then we can iterate an improve on it. This way, you have a clean pathway for deployment and your modeling use case delivers a testable result instead of us solely living in the land of hypothesis and what-ifs. The first step in the process is to build a model that is deployable to ESP. This is your standard ML training process where you engage in the champion/challenger evals and pick the best model that serves the use case while still keeping the complexity low. In our case, this is a random forest model the detects churn propensity. We need this to happen in our app as soon as we navigate off the login page by popping in the credentials and clicking the login button like shown below

Login Page — We need to score the event as soon as the login button gets tapped
Login Page — We need to score the event as soon as the login button gets tapped
Need to trigger the model as soon as the login button gets tapped
Sending requests to SASESP to collect the churn and the segmentation scores

Upon clicking login, we generate an event and spool this off to SAS ESP over http(s). The ESP project then immediately scores the incoming event for both churn and segmentation. We also do a quick db lookup for the customer ID and a little bit of the profile history before tapping ESP so that we can quickly ensure that we’ve got all the details needed to score the event. We wrap all of this inside a little ChurnService Class (see pic on the side). When we do this, we get a response from ESP like so, as seen on the dart devtools logging console.

Response to be parsed from SAS ESP

And just like that, we were able to figure out the customer’s propensity to churn and not. We’ve also figured out what segment they all into. In our demo app we present this data in a dialog when the user icon is clicked on the home page.(see gif below)

OK, let’s take a pause there and think about the kind of CX you might be able to provide for the user. Armed with info, you can open a myriad set of opportunities to personalize content for your customer — this could take the form of promos, post session follow up after/if the user bounces etc. OR offer customer support in-app if we know that the user is struggling with something knowing what type of user this is. The business possibilities are boundless and how you approach it might depend on your core business model and the type of metrics you might be after as it pertains to what you want to do with your marketing/CRM budget.

State Management Side Note: So, in our app we need to be able to preserve the results obtained from SAS ESP during the entire course of the session. We will use the awesome getx state manager to accomplish this.This means instead of calling some service every time we tap the user icon button like what’s shown in the above gif, we can use a getx to retrieve the scores from an instantiated GetxController. For our app this controller look like the following

GetXController to manage the state with a getter and a function to update the scores

Most of our state management issues for this app is handled using a similar paradigm. You can check out the entire source code for the application here.

Alright, so thats first one. The second feature has to do with click prediction. This one is handled in a slightly different manner. A realistic situation could be one where any retail organization could have a mix of items going through a markdown cadence with specific items getting featured as top saver items. Now, if we had n-items in these set of top saver items, we want to be able to sort an arrange the top N items in such a way that best increases the probability of eliciting a click from the user. To accomplish this, we could generate a click prediction score based on bucketed churn score range, the customer segment and a variety of customer profile attributes. Often in practice, this can be accomplished as an async process as soon as we have the response JSON from ESP. However, we’ll do a slight variation to this type of implementation just to showcase how we would do this with SAS MAS — the SAS Micro Analytic Service. To demonstrate this, let’s bring up a little snack bar at the bottom of the home screen with the probability of the click. What we can do to accomplish this is similar to what we did at the login page, but this time around send the request to the a SAS Micro Analytic Service Module. A SAS MAS module allows us to score a specific ML model using a REST call. In this case, we make a POST request to the MAS Module’s Scoring URI like shown below.

Make Request to MAS Module and get the scored result

Once we obtain the results from the MAS Module, we can simply inject the parsed response into the dialog, which we borrow once again from the awesome getx package. See the code snippet below which shows how we take advantage of the onTap function in the GestureDetector widget inside our “deals section”. You can see the entire code for this page here.

How the results get surfaced up to the app

Finally, when we do this, we see that we are successfully able to predict the click probability of every item listed in the My Top Savers Section like you see in the gif below. The benefit of doing this with flutter still stays and all of what we discuss on this article works both on Android and the Web.

And with that, we wrap up this article. Up next, we’ll work on collecting the geo location from where we are picking these clicks up, showcase integrations with some off the shelf AI services and wrap up with a fraud detection service for our application. Until next time, take care! 🚀

Connect with Sathish on LinkedIn

Geek Culture

Proud to geek out. Follow to join our +500K monthly readers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store