clsMiningModel
Ostrzeżenie
Ta funkcja zostanie usunięta z następnej wersji programu Microsoft SQL Server. Nie należy stosować tej funkcji w nowych projektach oraz jak najszybciej należy zmodyfikować aplikacje, w których obecnie jest używana ta funkcja.
Objects of ClassType clsMiningModel contain the definitions for data mining models that are contained in the MiningModels collection of a clsServer object.Każdego modelu zawiera kolekcja o nazwie Columns zbiór kolumn wyszukiwanie danych (czyli obiekty ClassType clsColumn) odpowiadają definicji przypadek tabela dla modelu.Każdej z tych kolumn wyszukiwanie danych można z kolei zawierają własny zbiór kolumn wyszukiwanie danych w Columns kolekcja.Takie kolumny są nazywane kolumn zagnieżdżonych.Oprócz Columns kolekcja, model wyszukiwania obiektu zawiera również odwołania do Roles, DataSources i CustomProperties kolekcje, które są używane w taki sam sposób, jak ich odpowiedniki w obszarze obiektu moduł.
Uwagi
Po utworzeniu model wyszukiwania obiektu, wywołując AddNew metoda obiektu server MiningModels kolekcja, zdefiniuj strukturę model wyszukiwania.Najważniejszy krok w tym procesie jest określenie typu podklasy modelu przez ustawienie tej właściwość albo sbclsOLAP lub sbclsRelational.Modeli wyszukiwanie danych, których SubClassType jest sbclsOLAP (czyli OLAP modelami wyszukiwanie danych) są oparte na moduł OLAP.Modeli wyszukiwanie danych, których SubClassType jest sbclsRelational (czyli modeli wyszukiwania w relacyjnej bazie danych) są oparte na tabela z relacyjnej bazy danych.Wybór modelu SubClassType Określa sposób definiowania pozostałe struktury modelu.Później można określić inne elementy projektu modelu, takie jak algorytmu wyszukiwanie danych używany model i role, które będą skojarzone z modelem.
Modeli wyszukiwania danych OLAP
Ustanowienie w przypadek zestaw dla górnictwa modelu danych OLAP zestaw CaseDimension Właściwość clsMiningModel obiektu do wymiar w module; to automatycznie definiuje poziom przypadek, który zawiera przypadek kolumny klucz dla model wyszukiwania jako poziom ostatnio włączony i widoczny w wybranego wymiaru.Następnie zestaw poszczególnych kolumn w Columns kolekcja clsMiningModel obiektu do odwoływania się do wymiarów, członkowie, właściwości element członkowski i środki do moduł do wprowadzania i przewidywanych informacji.
Modeli wyszukiwania danych relacyjnych
Ustanowienie w przypadek zestaw dla modelu górnictwa w relacyjnej bazie danych, zaznacz kolumna klucz z tabela lub widoku w relacyjnej bazie danych, a następnie dodać kolumna obiektów do Columns kolekcja odwołujące się do tych kolumn klucz.Następnie dodaj kolumny, które odwołują się do innych kolumn w tabela Columns kolekcja dostarczenia informacji dane wejściowe i przewidywalny model wyszukiwania.
Przykłady
A.Ręczne tworzenie modelu OLAP górnictwo
Poniższy przykład tworzy model wyszukiwania na podstawie moduł Sprzedaż w FoodMart 2000 przykładowej bazy danych:
Public Sub CreateOlapMiningModel_1()
'------------------------------------------------------------------------
' Declarations - Identify all of the variables that will be needed to
' create the data mining model.
'------------------------------------------------------------------------
Dim dsoSvr As New DSO.Server ' Server object
Dim dsoDmm As DSO.MiningModel ' Note that because events are needed,
' this object is being invoked directly instead of through an MDStore interface..
Dim dsoColumn As DSO.Column
Dim dsoRole As DSO.Role
Dim dsoNestedCol As DSO.Column
Dim dsoCb As DSO.MDStore
Dim dsoDim As DSO.Dimension
Dim dsoLvl As DSO.Level
'------------------------------------------------------------------------
' Connect to the server and walk through the schema for the cube that the
' data mining model will be based on. Save the references to the
' subordinate objects that will be needed later in this example.
'------------------------------------------------------------------------
'Connect to the server on this computer.
dsoSvr.Connect "LocalHost"
'Select the FoodMart database.
Set dsoDb = dsoSvr.MDStores("Foodmart 2000")
'Select the Sales cube.
Set dsoCb = dsoDb.MDStores("Sales")
'Select the Customers dimensions.
Set dsoDim = dsoCb.Dimensions("Customers")
'Select the Name level of the Customers dimension.
Set dsoLvl = dsoDim.Levels("Name")
'------------------------------------------------------------------------
' Before the model is created, check for a previous incarnation of it.
' If it exists, delete it. Then create a new one.
' Give the new model a new data source, and give it a role.
' Then describe the model for browsing the schema, and declare the
' algorithm that will be used to predict with.
' Finally, set up the OLAP properties that will be needed by the model.
'------------------------------------------------------------------------
'Check for the existence of the model on this computer.
If Not dsoDb.MiningModels("CustSalesModel") Is Nothing Then
'If this model exists, delete it.
dsoDb.MiningModels.Remove "CustSalesModel"
End If
'Create a new mining model called CustSalesModel.
Set dsoDmm = dsoDb.MiningModels.AddNew("CustSalesModel", sbclsOlap)
'Designate FoodMart 2000 as the data source for this mining model.
dsoDmm.DataSources.AddNew "Foodmart 2000"
'Create a new mining model role called All Users.
Set dsoRole = dsoDmm.Roles.AddNew("All Users")
'Describe this new mining model.
dsoDmm.Description = "Analyzes the purchasing behavior of customers"
'use the Decision Trees algorithm in this model.
dsoDmm.MiningAlgorithm = "Microsoft_Decision_Trees"
'Declare that the Sales cube will be used as the source for this model.
dsoDmm.SourceCube = "Sales"
'Declare that the case dimension will be based on the Customers
'dimension from the Sales cube.
dsoDmm.CaseDimension = "Customers"
'Use the Name level of the Customers dimension for cases.
dsoDmm.CaseLevel = "Name"
'Let DSO figure out the training query by leaving this property blank.
dsoDmm.TrainingQuery = ""
'------------------------------------------------------------------------
' Add a new column, Customer Id, to the mining model
' and relate this column to the Name level of the Customers dimension.
' Describe the level's type and make it a key for the model.
'------------------------------------------------------------------------
'Add Customer Id as a new column in the model.
Set dsoColumn = dsoDmm.Columns.AddNew("Customer Id")
'Identify the level in Sales that this column is based on.
Set dsoColumn.SourceOlapObject = dsoLvl
'Identify the type of column this is.
dsoColumn.DataType = adInteger ' This enumeration is from ADO.
'Identify this column as a key.
dsoColumn.IsKey = True
'------------------------------------------------------------------------
' Add a new column to the mining model called Gender and relate this
' column to the Gender member property of the Name level of the
' Customers dimension. Declare that the data in this column is
' statistically discrete.
'------------------------------------------------------------------------
'Add another column to the model.
Set dsoColumn = dsoDmm.Columns.AddNew("Gender")
'Identify the member property of the Customers dimension
'that this column is based on.
'Set the column's description for browsers of the schema.
dsoColumn.Description = "Based on the Gender member property " & _
"of the Name level of the Customers dimension."
Set dsoColumn.SourceOlapObject = dsoLvl.MemberProperties("Gender")
'Identify its type.
dsoColumn.DataType = adWChar
'Make this column related to the Customer Id column.
dsoColumn.RelatedColumn = "Customer Id"
'Identify this column as one containing discrete data.
dsoColumn.ContentType = "DISCRETE"
'------------------------------------------------------------------------
' Add a new column to the mining model called Unit Sales and relate
' this column to the Sales cube measure of the same name. Set the
' columns data type to Integer, and identify the data content in it as
' being continuous and logarithmically normalized. Finally, identify this
' column as being predictable.
'------------------------------------------------------------------------
'Add another column to the model.
Set dsoColumn = dsoDmm.Columns.AddNew("Unit Sales")
'Identify this column as being based on the Unit Sales measure.
Set dsoColumn.SourceOlapObject = dsoCb.Measures("Unit Sales")
'Identify the column type.
dsoColumn.DataType = adInteger
'Identify this column's content as being continuous.
dsoColumn.ContentType = "CONTINUOUS"
'Identify the statistical distribution of this data.
dsoColumn.Distribution = "LOG_NORMAL"
'Identofy the column as being predictable.
dsoColumn.IsPredictable = True
'------------------------------------------------------------------------
' Save the mining model and update its LastUpdated property.
'------------------------------------------------------------------------
'Set the date of last update to today's date.
dsoDmm.LastUpdated = Now
'Save the model definition.
dsoDmm.Update
'------------------------------------------------------------------------
' Lock the cube, process it, and then unlock it.
' Note: During processing a number of events will be fired. These events
' are trapped by the database object's ReportAfter, Report Before,
' ReportProgress, and ReportError events.
'------------------------------------------------------------------------
'Because the model is about to be processed, it must be locked.
dsoDmm.LockObject olapLockProcess, "Processing the data mining model in sample code"
'Fully process the model.
dsoDmm.Process processFull
'Unlock the model after processing is complete.
dsoDmm.UnlockObject
End Sub
B.Automatyczne tworzenie modelu OLAP górnictwo
Poniższy przykład powoduje automatyczne utworzenie i OLAP model wyszukiwania na podstawie Sales moduł w FoodMart2000 bazy danych:
Public Sub CreateOlapMiningModel_2()
'------------------------------------------------------------------------
' Declarations - Identify all of the variables that will be needed to
' create the data mining model.
'------------------------------------------------------------------------
Dim dsoSvr As New DSO.Server
Dim dsoDmm As DSO.MiningModel
Dim dsoColumn As DSO.Column
Dim dsoRole As DSO.Role
Dim dsoNestedCol As DSO.Column
'------------------------------------------------------------------------
' Before the model is created, check for a previous incarnation of it.
' If it exists, delete it. Then create a new one.
' Give the new model a new data source, and give it a role.
' Then describe the model for browsing of the schema, and declare the
' algorithm that will be used to predict with.
' Finally, set up the OLAP properties that the model will need.
'------------------------------------------------------------------------
dsoSvr.Connect "LocalHost"
Set dsoDb = dsoSvr.MDStores("Foodmart 2000")
If Not dsoDb.MiningModels("CustSales_Olap2") Is Nothing Then
dsoDb.MiningModels.Remove "CustSales_Olap2"
End If
Set dsoDmm = dsoDb.MiningModels.AddNew("CustSales_Olap2", sbclsOlap)
'Create a new mining model role called All Users.
Set dsoRole = dsoDmm.Roles.AddNew("All Users")
dsoDmm.Description = "Analyzes the purchasing behavior of customers"
dsoDmm.MiningAlgorithm = "Microsoft_Decision_Trees"
dsoDmm.SourceCube = "Sales"
dsoDmm.CaseDimension = "Customers"
dsoDmm.TrainingQuery = "" 'Let DSO figure out the training query.
'------------------------------------------------------------------------
' In this next step, the update method checks to see whether there are any
' columns in the columns collection. In this case, because there are not
' any, the update method will automatically add columns based on the
' structure of the Sales cube.
'------------------------------------------------------------------------
dsoDmm.Update 'Let DSO automatically populate the Columns collection.
'Enable the Products dimension.
'Set dsoColumn = dsoDmm.Columns("Products")
'dsoColumn.IsDisabled = False
'Make the Unit Sales measure predictable.
Set dsoColumn = dsoDmm.Columns("Unit Sales")
'Enable the column.
dsoColumn.IsDisabled = False
'Make the column predictable.
dsoColumn.IsPredictable = True
' Set the last updated date to today's date.
dsoDmm.LastUpdated = Now
' Save the model's metadata.
dsoDmm.Update
'------------------------------------------------------------------------
' Lock the cube, process it, and then unlock it.
' Note: During processing a number of events will be fired. These events
' are trapped by the database object's ReportAfter, ReportBefore,
' ReportProgress, and ReportError events.
'------------------------------------------------------------------------
'Because the model is about to be processed, lock it.
dsoDmm.LockObject olapLockProcess, "Processing the data mining model in sample code"
'Process the model.
dsoDmm.Process processFull
'Unlock the model.
dsoDmm.UnlockObject
End Sub