DTREG COM Library
The DTREG COM (Component Object Model) library makes it easy for production
applications to call DTREG as an “engine” to compute the predicted value
for data records using a decision tree model. You must use the GUI version
of DTREG to construct a model before you can use it with the DTREG COM library
to predict values.
Any type of model (Single Tree,
TreeBoost,
Decision Tree Forest,
Multilayer Perceptron Neural Networks
Cascade Correlation Neural Networks
Probabilistic and General Regression Neural Networks (PNN/GRNN)
Support Vector Machine (SVM),
Linear Discriminant Analysis (LDA),
or Logistic Regression)
can be used with the DTREG COM library to generate predicted values.
All of the advanced scoring features such as the
use of surrogate splitters to handle missing
predictor values are used in the DTREG COM library.
Because of the standardization of the COM interface, it is easy to call the
DTREG COM library from programs written in Visual Basic, Visual C++, VBA,
Excel, Access, ASP and other languages. The DTREG COM library is designed
to run as an in-process DLL for speed of execution.
Click here to view the manual for the DTREG COM Library
Example Visual Basic Program That Calls The DTREG COM Library
Private Sub RunTest_Click()
'
' Reference the DTREG COM library.
'
Dim dtreg As DTREGCOMLib.dtreg
Set dtreg = New DTREGCOMLib.dtreg
'
' Miscellaneous variable declarations.
'
Dim ProjectFile As String
Dim ModelType, status, index As Long
Dim NumVar, NumCat As Long
Dim VarClass, VarType As Long
Dim VarName, CatLabel As String
Dim ixSepalLength, ixSepalWidth As Long
Dim ixPetalLength, ixPetalWidth As Long
Dim ixSpecies As Long
Dim PredictedClass As String
Dim CatProb As Double
'
' Open the DTREG project file (TreeBoostIris.dtr).
'
ProjectFile = "c:\DTREG\Test\TreeBoostIris.dtr"
status = dtreg.OpenProjectFile(ProjectFile)
If (status <> 0) Then
boxStatus = "Error opening project file: " + Format(status, "#")
Stop
End If
'
' Find out what type of model this is
'
ModelType = dtreg.ModelType
'
' Find out how many variables are in the model.
'
NumVar = dtreg.NumberOfVariables
'
' Check the name and properties of each variable.
'
For index = 0 To NumVar - 1
VarName = dtreg.VariableName(index)
VarClass = dtreg.VariableClass(index)
VarType = dtreg.VariableType(index)
Next
'
' Get the index numbers of the variables variables.
'
ixSpecies = dtreg.VariableIndex("Species")
ixSepalLength = dtreg.VariableIndex("Sepal length")
ixSepalWidth = dtreg.VariableIndex("Sepal width")
ixPetalLength = dtreg.VariableIndex("Petal length")
ixPetalWidth = dtreg.VariableIndex("Petal width")
'
' Set the values of the predictors we want to score.
'
status = dtreg.SetVariableValue(ixSepalLength, 5.1)
status = dtreg.SetVariableValue(ixSepalWidth, 3.5)
status = dtreg.SetVariableValue(ixPetalLength, 1.4)
status = dtreg.SetVariableValue(ixPetalWidth, 0.2)
'
' Compute the predicted target category.
'
PredictedClass = dtreg.PredictedTargetCategory
'
' See if any error occurred during the computation.
'
status = dtreg.LastStatus
If status <> 0 Then
boxStatus = "Error computing target: " + Format(status, "#")
Stop
End If
'
' If we are using a TreeBoost model, check the probabilities
' for each of the target variable categories.
'
If ModelType = 2 Then
NumCat = dtreg.NumberOfCategories(ixSpecies)
For index = 0 To NumCat - 1
CatLabel = dtreg.CategoryLabel(ixSpecies, index)
CatProb = dtreg.TargetCategoryProbability(index)
Next
End If
End Sub
|
|