Code to Predict Products

  1. Create a Dictionary object and populate it with information on the current user.

    Dim dCurrentCase
    Set dCurrentCase = Server.CreateObject("Commerce.Dictionary") 
    
    dCurrentCase("UserID") = "someone@microsoft.com"
    dCurrentCase("Age") = ""
    dCurrentCase("Gender") = "F"
    dCurrentCase("ZipCode") = "98052"
    dCurrentCase("Education") = ""
    
  2. Assume a data table represents the products in the shopping basket of the user. The PivotColumn in this table is named "SKU", the AggregateColumn is named "QTY", and the user has two bottles of a product with an SKU equal to "wine_fine_us_zin_202" in his or her basket. Set this information into the current case for the user. The following naming convention is used for sparse properties only (they appear in Type 1 tables). For more information about the properties and tables, see Predictor Schema.

    dCurrentCase("QTY(wine_fine_us_zin_202)") = 2
    
  3. Assume a different table represents the advertisements the user has clicked on. The PivotColumn in this table is named "URL", the AggregateColumn is named "HitCount", and the user clicked on the indicated URL once. Set this information into the current case for the user.

    dCurrentCase("HitCount(www.roguecellars.com/ad_md)") = 1
    
  4. Create a SimpleList object and populate it with the properties to predict.

    Dim slPropertiesToPredict
    Set slPropertiesToPredict = Server.CreateObject("Commerce.SimpleList")
    
    slPropertiesToPredict.Add("SKU")
    
  5. Create Variant Safearrays to store the predicted properties and values.

    Dim vsavPredictedProps
    Dim vsavPredictedValues
    
  6. Using the PredictorClient object, oPredictorClient, created in Code to Load a Model and Set Default Properties, and the Purchase1 model loaded in the same section, make a maximum of five predictions.

    oPredictorClient.Predict dCurrentCase, slPropertiesToPredict _
     vsavPredictedProps, vsavPredictedValues, 5
    
  7. Iterate through the returned predictions.

    Dim i
    For i = LBound(vsavPredictedProps) To UBound(vsavPredictedProps)
    Response.Write vsavPredictedProps(i) & " = " _
     & vsavPredictedValues(i) & "<BR>"
    Next
    
  8. Release the objects.

    Set dCurrentCase = Nothing
    Set slPropertiesToPredict = Nothing
    

Copyright © 2005 Microsoft Corporation.
All rights reserved.