Skip to main content

AI Builder prediction now supports related entities and filtering

Headshot of article author Peter Bian

We’ve updated AI Builder prediction to include support for related entities and filtering. These capabilities give users even more flexibility in model creation. In this post, we demonstrate how these features work by building an end to end scenario for how AI Builder can help to optimize delivery performance for an e-commerce company.

Related entities

We want AI Builder to work better for the data that you already have in Common Data Service. We know that all of the data that makes your business run probably isn’t in a single entity, and that there are many entities and relationships all of which may help to improve the accuracy of your prediction model.

We’ve added support for adding related entities to be used in training, similar to the way you can add related entities in a view. Currently we only support many-to-one relationships, but we are looking to add more relationship types to support later on.

Filtering

What happens when you know that there are irrelevant data within the same entity you are using to train a model? For example, if you don’t want to train on outdated records, or if you want to build region-specific AI models

We’ve added support for filtering, which is applied to both training and prediction. As an example, if I apply a filter to only look at the U.S. region, then the model will train itself on records where the outcome is known only for U.S. region. Once this model is trained, it will only make a prediction for records where the outcome is not known only for U.S. region.

More information on how to use these features can be found in our documentation.

Example

Let’s say I’m a maker in a typical e-commerce company in Brazil. My CDS database contains typical entities like Order, Product, Customer, etc. I’m noticing that there have been a lot of complaints that deliveries have been delayed specifically for Sao Paulo.

Without fundamentally changing the system, since this is an isolated issue, I want to see if I can train a model to predict whether a delivery to Sao Paulo is likely to be delayed, and automatically upgrade the shipping for the customer from regular to express.

Step 1: create output field

First, I want to create an output field to denote what constitutes a delayed delivery. In my Order entity, I have the estimated delivery date and the actual delivery date. Every record where actual delivery date is a week or more later than estimated delivery date is considered a late delivery. I will create two fields:

Delivery Delta – this is the difference in days between Delivered Date and Estimated Delivery Date.

Delivery Timeliness – this field categorizes the Delivery Delta column into Early, On time, and Late.

If an order has not been delivered, then the Delivery Timeliness value will be null, and those are the records which the model will make a prediction on, once the model is trained and published.

Step 2: create prediction model

Next, I create a new prediction model from AI Builder section of Power Apps.

I use my BC Order entity and the Delivery Timeliness field, which we created earlier. In addition, I want to predict  whether the delivery will be late, so here, I  tell the model that Late is my Yes outcome, and everything else is No.

Next, I select my related entities, Customer and Product.

Also, make sure that Delivery Date and Delivery Delta are not selected, because the model should not have information that is only known after the product has been delivered. If you do keep it selected, then the model will show that it has 100% accuracy, but it will not be able to properly predict new orders. This is known in machine learning as target leak, and you can learn more about it here.

Next, I add a filter, so the model only looks at Sao Paulo orders. The filtering experience is the same as the PowerApps view filtering experience that you may be familiar with. We want to create a filter condition on the Customer entity, since the state information is in that entity and not orders. Set the filter condition as shown here:

Once all that is done, it is time to train the model. For this model, we have an accuracy score of 91%.

Step 3: publish and use in app

Publish your model. As part of publishing, we actually create three outputs:

  • Predicted – The predicted outcome
  • Probability – The probability of the true outcome, from 0 – 1
  • Explanation – A text field in JSON that contains the record level influencers

If you select See details, you will see the output field that we created for the prediction.

You can leverage the view feature to quickly see the predicted output. Refer to this document for more info.

We’re ready to connect the prediction to our app. For this example, let’s assume we have an app that the fulfillment team looks at when they prepare the order. If the model predicts that the shipment is likely to be late, then we will automatically upgrade them to express by connecting the prediction output to the app. To do this, simply reference the prediction output fields in the app.

We’ve now added AI into your business process without any coding!

Appendix: try it yourself

If you want to walk through this example on your own, use the link below to access the solution and the data files you need.

brazilian_commerce

First, import the solution BrazilianCommerce_1_0_0_0.zip that contains the entity definitions.

In PowerApps, Click Solutions on the left menu pane, and then Import on the top menu bar.

Select the attached zip file and follow the instruction to import it.

Once the solution is imported, click the gear icon on the top right of the PowerApps screen, and select Advanced settings.

Click the carrot next to Settings and select Data Management.

Select IMPORT DATA from the top menu bar.

In the Data file name section, select customer.csv and click Next.

Keep clicking Next until you get to the Map Record Types screen.

Select BC Customer from the drop down and click Next.

Map the fields like this:

Source Field Map to
customer_id ID
customer_city City
customer_state State
customer_zip_code_prefix Zip code

Select Next, then Submit, then Finish.

Repeat the process again, but this time use product.csv and map it to BC Product.

Map the fields like this:

Source Field Map to
product_id ID
product_category_name Category
product_description_lenght Description Length
product_height_cm Height cm
product_length_cm Length cm
product_name_lenght Name Length
product_photos_qty Photos Quantity
product_weight_g Weight g
product_width_cm Width cm

Wait until both of these imports are complete before moving onto the next step.

Repeat the process again, but this time use order.csv and map it to BC Order.

Map the fields like this:

Source Field Map to
order_id ID
customer_id Customer (Lookup)
freight_value Freight Value
order_delivered_customer_date Delivered Date
order_estimated_delivery_date Estimated Delivery Date
order_purchase_timestamp Purchase Date
order_status Order Status
price Price
product_id Product (Lookup)

For the two lookup fields, you should get a popup:

Make sure that the checkbox is selected, and that the field is ID. Once that is done, you should have all the data uploaded to start walking through the scenario yourself.