
Creating an OLAP Data Mining Model
The following code example creates an OLAP data mining model, following the steps outlined earlier in this topic, that attempts to predict the salary range of a customer in the Sales cube of the FoodMart 2000 database based on gender, marital status and education.
Unlike the process of creating a relational data mining model, the column structure is directly drawn from the source cube specified in the SourceCube property of the mining model object. To determine which columns are to be processed by the data mining model, the column objects stored in the Columns collection of the mining model object can be changed. The IsDisabled property determines which columns are to be used as part of the analysis, while the IsInput and IsPredictive properties of each column object can be set to determine the behavior of the column, including whether it will serve as an input, predictive, or input and predictive column in the data mining model.
Because the structure of the OLAP data mining model is drawn from the structure of the source cube, all source OLAP objects used by the mining model must be visible to the mining model. The following requirements must be met:
-
The source cube must be visible.
-
The case dimension must be visible.
-
The SourceOlapObject property for each data mining column must contain a visible source OLAP object.
This code example creates and processes an OLAP data mining model named CustSalesModelOLAP, based on the Sales cube of the FoodMart 2000 database, that analyzes salaries for customers based on gender, marital status and education:
Public Sub CreateOLAPMiningModel()
Dim dsoServer As New DSO.Server
Dim dsoDB As DSO.MDStore
Dim dsoDMM As DSO.MiningModel
Dim dsoColumn As DSO.Column
Dim dsoRole As DSO.Role
' Constants used for DataType property
' of the DSO.Column object.
' Note that these constants are identical to
' those used in ADO in the DataTypeEnum enumeration.
Const adInteger = 3
Const adWChar = 130
' Connect to the server on this computer.
dsoServer.Connect "LocalHost"
' Select the FoodMart 2000 database.
Set dsoDB = dsoServer.MDStores("FoodMart 2000")
' Check for the existence of the model on this computer.
If Not dsoDB.MiningModels("CustSalesModelOLAP") Is Nothing Then
' If this model exists, delete it.
dsoDB.MiningModels.Remove "CustSalesModelOLAP"
End If
' Create a new OLAP mining model
' called CustSalesModelOLAP.
Set dsoDMM = dsoDB.MiningModels.AddNew("CustSalesModelOLAP", _
sbclsOlap)
' Create a new mining model role called All Users
Set dsoRole = dsoDMM.Roles.AddNew("All Users")
' Set the needed properties for the new mining model.
With dsoDMM
.DataSources.AddNew "FoodMart", sbclsRegular
' Set the description of the model.
.Description = "Analyzes the salaries " & _
"of customers"
' Select the algorithm provider for the model.
.MiningAlgorithm = "Microsoft_Decision_Trees"
' Set the source cube for the model to the Sales cube.
.SourceCube = "Sales"
' Set the case dimension for the model to the
' Customers shared dimension.
.CaseDimension = "Customers"
' Let DSO define the training query.
.TrainingQuery = ""
' Let DSO add the cube structure to the
' data mining model structure, automatically
' creating needed data mining model columns.
.Update
End With
' Set the column properties pertinent to the new model.
' Note that, when columns are automatically added to
' the model in this fashion, the are disabled. You
' must choose which columns are to be enabled
' before you can process the
' model, and at least one column must be enabled,
' or an error will result.
' Enable the Name column. As this column is the
' lowest enabled level on the Customers case dimension,
' it becomes the case level for the data mining model.
Set dsoColumn = dsoDMM.Columns("Name")
dsoColumn.IsDisabled = False
' Enable the Gender column as an input column.
Set dsoColumn = dsoDMM.Columns("Gender")
dsoColumn.IsInput = True
dsoColumn.IsDisabled = False
' Enable the Marital Status column as an input column.
Set dsoColumn = dsoDMM.Columns("Marital Status")
dsoColumn.IsInput = True
dsoColumn.IsDisabled = False
' Enable the Education column as an input column.
Set dsoColumn = dsoDMM.Columns("Education")
dsoColumn.IsInput = True
dsoColumn.IsDisabled = False
' Enable the Unit Sales column as a predictable column.
Set dsoColumn = dsoDMM.Columns("Yearly Income")
dsoColumn.IsPredictable = True
dsoColumn.IsDisabled = False
' Save the data mining model.
With dsoDMM
' Set the LastUpdated property of the new mining model
' to the present date and time.
.LastUpdated = Now
' Save the model definition.
.Update
End With
' Process the data mining model.
With dsoDMM
' Lock the mining model for processing
.LockObject olapLockProcess, _
"Processing the data mining model in sample code"
' Fully process the new mining model.
' This may take up to several minutes.
.Process processFull
' Unlock the model after processing is complete.
.UnlockObject
End With
' Clean up objects and close server connection
Set dsoRole = Nothing
Set dsoColumn = Nothing
Set dsoDMM = Nothing
dsoServer.CloseServer
Set dsoServer = Nothing
End Sub