Machine Learning in Firebase: Using Predictions

Laurence Moroney
Jan 11, 2018 · 10 min read

Getting Started with Firebase Predictions

Firebase Predictions applies machine learning to your Google Analytics for Firebase data to create groups of users based on predicted behavior. These groups are updated daily, and can be used for targeting with notifications, remote configuration and more. Out of the box, Firebase Predictions will create groups of users that are considered likely to churn, likely not to churn, likely to spend and likely not to spend. If you track conversion analytics, you can also create predictions for these events. In this article, I’ll step you through Firebase Predictions, how to set it up, how it works, and how you can create and track your own predictions.

How does it work?

Behind Firebase Predictions is TensorFlow, Google’s framework for Machine Learning. It uses supervised learning where we read the last 100 days of analytics activity for your app and use this to generate a set of features — inputs to a Machine Learning model. From these features, a model is created to predict their output (labels in ML parlance), with the four built-in labels mentioned above. So, for example, when predicting if a user will churn, Predictions will look at the behavior of all users over the last 100 days, and use this to learn about the users that did churn during that time period. The model will then help determine which users might churn in the next 7 days. See Figure 1.

Image for post
Image for post
Figure 1. Using Features and Labels in Predictions

Getting Started

Prior to using predictions, there are some pre-requisites that your app needs. You’ll go through these in this section.

compile 'com.google.firebase:firebase-core:11.6.0'
pod 'Firebase/Core'
Image for post
Image for post
Figure 2. Accessing Predictions in the Console
Image for post
Image for post
Figure 3. Opting into Firebase Predictions

Understanding Predictions

After a little time, your Predictions cards will populate. So, for example, in Figure 4 you can see the churn card for a popular app. In this case, 20% of the app’s users are predicted to churn in the next 7 days. That’s an alarming statistic, and it’s good to know about this before it happens.

Image for post
Image for post
Figure 4. A Predictions Card
Image for post
Image for post
Figure 5. Prediction Accuracy

Acting on Predictions

The users that meet the prediction are assigned a user group which updates on a daily basis. Thus, when you act on the group, you are acting on the current group, which will be updated tomorrow, and so on.

Examples of Predictions in Action

Halfbrick Studios
A great example of this is Halfbrick games who already had Firebase Remote Config implemented in their game Dan the Man and experimented with using the prediction of users that would churn to see if they could increase their retention rate. They chose to provide a gift of in-app currency to users that were predicted to two groups of users: Those that beat level 3 of their game, and those that were predicted to churn by Firebase Predictions.

Image for post
Image for post
Figure 6. In-game reward for app users
Image for post
Image for post
Image for post
Image for post
Figure 7. Non Spend Predicted users got chests first
Image for post
Image for post
Figure 8. Spend Predicted users got Crystals first

Using Notifications

If you choose to reach your user with Notifications, you’ll be taken to the Firebase notification composer screen, seen in Figure 9. Note the target settings — it’s a user segment, and then you’ll be able to use the Predict setting, and the tolerance level you want to address.

Image for post
Image for post
Figure 9. Targeting predicted users with a notification

Creating your own Prediction

Using the out-of-the box predictions for churn and spend are very useful, but you’ll also likely want to build your own predictions about what is important to you. You can predict based on conversion events, so you’ll need to define custom analytics and set them up as conversion events before you can create any.

Image for post
Image for post
Figure 10. Creating a Purchase level prediction for a custom analytic
Image for post
Image for post
Figure 11. Analyzing the user group that meets your prediction

Hints and Tips

Every app and every scenario is different, so it’s difficult to have a one-tip-fits-all strategy, but here’s a few things I’ve learned while working with predictions.

  1. If you don’t want to change anything for churners/spenders right away, you can still use these user groups to understand your audience. For example, you can set a value in Remote Config for people who are going to churn. At runtime you then read this value, and use it to determine your other analytics — for example you could track potential churners through the levels of your game (distinguishing them from everyone), to gain an insight on where churners drop out, and help you avoid that in future, instead of merely guessing what the problem might be.
  2. Combine with Firebase A/B Testing to run experiments. This was done very successfully in the games I mentioned above, where, instead of rolling a change out to every user that was predicted to churn, a dynamic group from predictions could be a tested upon
  3. Consider the custom analytics that you capture. Too few, and you won’t gain great insight. Too many, and the information may be lost in all the data. As always iterate, iterate, iterate, and don’t be afraid to try new things, while cutting out ones that aren’t working for you.

Summary

In this article you were introduced to Firebase Predictions, and saw what they’re all about, how they work, and how they apply Machine Learning technology to your analytics. You saw how you can create your own predictions from conversion events in your analytics, and also how to act on predictions — setting Remote Config variables or re-engaging your users with notifications. You can learn more about Firebase Predictions at https://firebase.google.com/products/predictions/

Laurence Moroney

Written by

Developer Advocate at Google for Artificial Intelligence. Host of YouTube Show ‘Coffee with a Googler’. Author of lots of books, comics, screenplays and more!

Laurence Moroney

Written by

Developer Advocate at Google for Artificial Intelligence. Host of YouTube Show ‘Coffee with a Googler’. Author of lots of books, comics, screenplays and more!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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