Previous in Contents Next in Contents

Predictor Example: Microsoft Press Product.asp

The Product.asp page in the Microsoft Press starter site is generated when the visitor clicks a book title in a list of titles. The page displays information about the particular book. Using the Predictor, this page also displays other books that this customer might be interested in.

Whereas the prediction in the Basket.asp page is based on the customer's shopping basket, the prediction on the Product.asp page is based primarily on the book being displayed. The assumption is that if the customer is interested in this book, he or she may have a preference for certain other books. The customer's shopping basket may be empty at this point. However, if the shopping basket does contain items, the logic of this page also takes those items into account in generating the suggestions, and prevents any items already ordered from appearing in the list of suggestions.

The following script accomplishes this logic by building a customer interest list containing both the book currently displayed on this page as well as any items in the shopping basket, but with the Quantity property for the current book artificially set to 100. This weighting causes the Predictor to place the greatest emphasis on the current book, while still considering any books already in the basket. In this way, none of the suggestions will duplicate the contents of the basket.

Specifically, the following script creates a SimpleList object called thisitems to serve as the customer interest list. The script then adds the current book to this list, in the form of a Dictionary object that contains the SKU of the current book and the Quantity of 100.

Next, the script iterates through the customer's order form and copies each item from the order form to the customer interest list, using the actual quantities ordered (orderitem is defined as the item list in the shopping basket by the statement set orderitem = mscsOrderForm.items, which appears in Order_bar.asp):

Finally, the generated customer interest list is passed to the Predictor's GetPredictions method. The remainder of the page displays the list of suggestions in the same manner as the Microsoft Press Basket.asp page:

set predictor = Application("MSCSPredictor")
set interestList = Server.CreateObject("Commerce.SimpleList")

set thisitem = Server.CreateObject("Commerce.Dictionary")
thisitem.sku = CStr(sku)
thisitem.quantity = 100
interestList.add(thisitem)

for i = 0 to orderitem.Count - 1
    set thisitem = Server.CreateObject("Commerce.Dictionary")
    thisitem.quantity = orderitem(i).quantity
    thisitem.sku = orderitem(i).sku
    interestList.add(thisitem)
next

set products = predictor.GetPredictions(interestList, 3, 0.1, 2)

The parameters passed to GetPredictions are the list of current items and quantities (thisitems), the desired number of suggestions to return (3), the PopularItemFilter (the value of 0.1 indicates that GetPredictions should include popular products in the suggestion list if they are relevant), and the RequiredMatches (the value of 2 in this example ensures that the returned list will be a composite of purchases of at least two similar customers).


© 1997-2000 Microsoft Corporation. All rights reserved.