Einstein Prediction Builder has been around for a while now. In fact, the draft of this blog post has been sitting here since 2019 just waiting for me to actually do it! Prediction Builder is something that I’ve wanted to implement at work for a long time, but just haven’t yet. It’s one of those issues that just forever sits in my backlog unfortunately because there are always more pressing issues to take care of or develop. That doesn’t mean we can’t play with it for fun though! While Prediction Builder usually probably predicts sales outcomes and business related insights, I think it would be way more fun to see if Einstein can predict if my husband will help with the laundry!
Before we get started
Before we get started, let’s review the Considerations for Setting Up Einstein Prediction Builder to see if we can do this. Some things to keep in mind:
- We can make predictions on the following field types: checkbox, formula fields, numeric.
- Custom objects are supported, along with a whole slew of standard objects
- We need a minimum of 400 records
- We need a minimum of 100 per each value of a true/false value
So, I think we can do this. We might have to fudge some data to get to our 400 minimum records, but that shouldn’t be hard and probably won’t be considered cheating.
Also before we get started, I’m going to sign up for a Trailhead Playground that has Einstein Prediction Builder.
Enabling Prediction Builder
This part is easy peasy. In this Trailhead Playground, and in any org, you get your first two predictions for free. Before you can get setup, you need to review the terms of that and then agree. Once you submit the agreement, some things happen in the background and then you are redirected to the Einstein Prediction Builder setup page, with it already enabled for you.
Plan Your Prediction
Before we actually get started here, its important to plan out what we are actually predicting and how that translates into Salesforce objects and fields. I already know I need a custom object and some custom fields and we need to make sure they are created in a format that Einstein can predict.
We know from earlier that we can predict numeric fields, checkboxes and custom formula fields. I think that we want to predict a checkbox in this case because a numeric value wouldn’t really make sense unless we also wanted to predict how many socks the husband lost while maybe doing the laundry, and we don’t really have a need for a formula field right now.
I’m going to create a new custom object called Chore. I’m really sad that there’s no sock icon to use for the custom tab, but I found a chalkboard so I guess that works.
Using the Schema Builder, I’m going to add some custom fields, starting with a picklist labeled Chore Type.
We also need to determine if it was my husband who actually did the laundry. We’ll add a lookup for who the chore is assigned to, and we’ll add another lookup field for who actually completed the chore. I’m going to relate those to the Contact object since in a Trailhead Playground I’m limited on the number of users I can add and don’t like being limited. Let’s also add a checkbox that says whether or not the chore was completed by the assigned contact. I’m thinking that this is the field we want to predict. Maybe?
This is looking good, but I feel like we need more data points… I’m going to add the weather and also a picklist for mood. Then maybe we can say that if its raining, the husband won’t help with the laundry. Or something like that! For mood I will just use Positive/Negative so that we don’t have to get too specific. We should probably add other data points too – maybe day of the week? Can you think of anything else I should add? This is what our schema looks like:
With the way this is setup, we are really more predicting if the assigned person will be the person to complete the chore. But maybe I will only predict on a subset of chore records where the husband is assigned. Something like that.
Okay, good. So I think our next step here is to create our dataset, and in my case – I need to actually create data now. So I’m going to be using dataloader to load at least 400 chore records with the following columns:
- Chore Type
- Assigned to
- Completed by
- Day of Week
- Temperature Outside
You can download my dataset here if you want to follow along! I decided last minute to update my lookup fields to just be text fields, that way if anyone is following along you won’t have to change id’s out in the dataset or anything. I also decided to add an additional field for Status instead of relying on the ‘Completed by’ field to be populated in order to know it is done.
A special note on my weather data because I love discovering new data sources – I was able to download a table with historical weather data from Climate.gov.
I’m importing these new rows using the Data Import Wizard because that seemed like the fastest option. You could also use Dataloader (or create them all manually).
So now I have 851 records, which is well beyond the 400 we needed, and now we can start actually building our prediction!
We start by just clicking “New Prediction” on the Einstein Prediction Builder landing page in Setup. I’m just going to call this
We’ll choose Chore__c as our object and then I’m going to choose to define a segment because all I care about right now is Laundry.
If you remember earlier, we talked about how our prediction would actually be predicting if the person the chore was assigned to was the one who actually completed it. This will be a yes/no prediction, and we’ll select that on this next screen.
Since we didn’t create a formula field with that yes/no value already, let’s see if we can get by with setting up filters for it.
And, it looks like I can’t filter on things like field 1 = field 2, so we’ll need to go back and create that custom formula field afterall!
For my formula field, I’m just going to use
Assigned_to__c = Completed_by__c.
So, now we have to do all those previous steps again, woohoo more practice! This time we’ll say yes, we have a field already, and we’ll set that value.
This next part tells Einstein which records we want to use as examples. I was a little confused about this part at first, but after reading the help article 7 times, I think I understand. Your example set MUST include both sides of the story, in other words chores that have been completed by the husband and ones that haven’t been. I couldn’t do my formula field isn’t null, so I just did Assigned to = Wife and Assigned to = Husband and set the logic to any. No idea if this is functional or not, but there will be time to adjust later I suppose. Trail and error!
Now we need to choose which fields we should use in our prediction! I’m going to deselect Owner and Created by since I just imported all of these using the Wizard. Also deselecting last modified by because that will always be me in this dev org.
Now we get to select where we want to store our prediction. I’m just going to call the field
Prediction because I can’t think of anything else right now, and I also want to turn on the section for showing the top predictors on the record page.
Next we’re shown a summary of everything we just built. Once we choose “Build Prediction” it says it can take up to 24 hours to process everything. Since I only have like 850 records to predict, I doubt it’ll take that long, but let’s push it and see!
I started a stopwatch in Chrome after I hit the Build Prediction button, which was fun. I kept refreshing the tab and it said Pending for SO LONG. It was making me really sad. And then I realized it had only been 5 minutes so… I guess I’m super impatient. I really hope it doesn’t actually take 24 hours!
BOOM! 9 minutes, 47 seconds!
Well, it says the prediction quality is too good to be true, which I think can also be said about the husband doing laundry in the first place, right? The first suggestion is to review the fields we are using in our prediction and make sure we are excluding things that aren’t relevant. Let’s do that.
Looking at our list of fields again… the Chore Name is totally irrelevant and is just an auto-number, so let’s get rid of that. Maybe even Completed by is irrelevant since we want to predict who that will be anyway. Axing it. The due date probably also irrelevant. Also getting rid of status. So that leaves us with:
- Assigned to
- Chore Type
- Day of Week
- Temperature Outside
I’m thinking that mood and temperature aren’t great predictors because those values wouldn’t be present yet until the chore is complete anyway… but let’s just keep going.
I’m clicking Build Prediction again!
This time it only took 6 minutes, 10 seconds.
It’s saying this is still too good to be true… but its probably because of my fake data I imagine…
This is cool though, looking at the scorecard I can see the top predictors. Clearly temperature has no value… but I’m still excited that I found a way to download temperature datasets! I’m going to just enable this thing because we have so few data points to play with anyway that I don’t think there’s much we can do.
I’ve now enabled this prediction but I don’t have any prediction scores anywhere. It looks like there is a Scoring Frequency pilot program that you can join to choose from a couple different options, but I don’t see anywhere that specifies when things will be scored if you AREN’T in the pilot.
SOLVED: I needed to give myself these permissions:
- View Record Insights
- Create Record Insights
All of the predictions now show up and they seem to align with reality – if its the husband’s turn, the prediction is 0 or very low. LOL! Good to note here that even though we wanted to predict a yes/no, this number is showing us how likely it is to be yes. I had to stare at it for a minute because I was expecting a yes/no answer. Let’s jump into one of these records. In order to show the Einstein predictions component on the record, we just need to add the component to the Lightning page.
So this is interesting. I chose a record in the future. Looks like a top predictor is the day of the week. Let’s see what happens if I update the mood.
That didn’t doo much… we just got a new top predictor but the actual score didn’t change.
Prediction Builder is really cool! I can’t wait to try building a real prediction with real data. While this experiment didn’t really work out because my fake data was dumb and there’s nothing to really use to predict if my husband will or will not do the laundry, I still learned a lot. The Builder is simple to use with all clicks not code, and as long as you understand your data it seems like it would be super straight forward. It reinforces the plain and simple fact that data matters and that a well thought out use case is your golden ticket. I think I will try this again with a real use case for sure and work on actual use cases I can use at work.
I better go tell my husband its his turn to do the laundry.