Code to Build a New Model

The following example shows how to build a new prediction model.

  1. Create a dictionary to contain the build parameters.

    Dim dBuildParams As Commerce.Dictionary
    Set dBuildParams = Server.CreateObject("Commerce.Dictionary")
    
  2. Insert the build parameters into the dictionary. All of these parameters have default values and do not need to be specified. The default model type is "prediction". To specify a segment model, set the ModelType to 1.

    dBuildParams("ModelType") = 0
    dBuildParams("ComplexityPenalty") = 75
    dBuildParams("InputAttributeFraction") = 0.5
    dBuildParams("MeasuredAccuracyMaxPredictions") = 10
    dBuildParams("MeasuredAccuracySampleFraction") = 0.2
    dBuildParams("MinimumCasesToSplit") = 10
    dBuildParams("OutputAttributeFraction") = .5
    dBuildParams("SampleSize") = 15,000
    
  3. Create an object to convert the dictionary into an Extensible Markup Language (XML) string containing the build parameters. The IPersistXML interface is not available through Microsoft Visual Basic Scripting Edition (VBScript).

    Dim oPersistXML As IPersistXML
    Set oPersistXML = dBuildParams
    
    Dim sXMLBuildParams As String
    sXMLBuildParams = oPersistXML.SaveXML(0)
    
    Set oPersistXML = Nothing
    Set dBuildParams = Nothing
    
  4. Create the PredModelBuilder object.

    Dim oPredModelBuilder As Commerce.PredictorModelBuilder
    Set oPredModelBuilder = _
     Server.CreateObject("Commerce.PredictorModelBuilder")
    
  5. Using the connection string, sDWConnect, retrieved in Code to Retrieve the Database Connection String, and the name of the model configuration, PurchaseCfg1, created in Predictor Schema Example, start the build for a new model named Purchase1. The value, lBuildID, returned by the Start method, is used to access the build thread while it is running or paused.

    Dim lBuildID
    lBuildID = oPredModelBuilder.Start(sDWConnect, "", _
     "PurchaseCfg1", "Purchase1", sXMLBuildParams, True)
    
  6. Release the objects.

    Set oPersistXML = Nothing
    Set dBuildParams = Nothing
    Set oPredModelBuilder = Nothing
    

Copyright © 2005 Microsoft Corporation.
All rights reserved.