解读SQL Server分析服务中的数据挖掘功能
2007-10-25 15:23:51 来源:WEB开发网下面是用Visual Basic编写的用来演示上述的命令运行的一小段程序:
Const sGUID_SCHEMA_SERVICE_PARAMETERS As String = "{3ADD8A75-D8B9-11D2-8D2A-00E029154FDE}"
Const sGUID_SCHEMA_MINING_SERVICES As String = "{3ADD8A95-D8B9-11D2-8D2A-00E029154FDE}"
Const sGUID_SCHEMA_MINING_MODELS As String = "{3ADD8A77-D8B9-11D2-8D2A-00E029154FDE}"
Const sGUID_SCHEMA_MINING_COLUMNS As String = "{3ADD8A78-D8B9-11D2-8D2A-00E029154FDE}"
Const sGUID_SCHEMA_MODEL_CONTENT As String = "{3ADD8A76-D8B9-11D2-8D2A-00E029154FDE}"
Const sGUID_SCHEMA_MODEL_CONTENT_PMML As String = "{4290B2D5-0E9C-4AA7-9369-98C95CFD9D13}"
Dim m_conn As New ADODB.Connection
Private Sub ExecuteMDX(ByVal v_sMDX As String)
On Error GoTo ErrHandler
Dim cmd As New ADODB.Command
Dim rec As Recordset
Dim nNum As Integer
Set cmd.ActiveConnection = m_conn
cmd.CommandText = v_sMDX
Set rec = cmd.Execute(nNum)
MsgBox "Command Executed Successfully. " & nNum & " rows affected.", vbOKOnly + vbInformation
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
End Sub
Private Sub Form_Load()
' Specify .2 on the provider so only SQL 2000 will work
' Connect to a server on the local PC. Change this if you are connecting
' to another PC with Analysis Services.
Call m_conn.Open("PROVIDER=MSOLAP.2;Data Source=LOCALHOST;")
' Create the mining model
Call ExecuteMDX( _"CREATE OLAP MINING MODEL [Local Find Salary] " & _
"From [Sales] " & "( " & " CASE " & _
" Dimension [Customers] " & _
" Level [Name] " & _
" PROPERTY [Gender] ," & _
" PROPERTY [Marital Status] ," & _
" PROPERTY [Education] ," & _
" PROPERTY [Yearly Income] PREDICT " & _
")" & _
"USING Microsoft_Decision_Trees")
' Fill the mining model
Call ExecuteMDX("INSERT INTO [Local Find Salary]")
' Create a virtual cube based on the mining model
Call ExecuteMDX( _
"CREATE SESSION VIRTUAL CUBE [PredictIncomeCube] " & _
"FROM [Sales] " & _
"( " & _
" MEASURE [Sales].[Unit Sales] , " & _
" DIMENSION [Sales].[Customers], " & _
" DIMENSION [Sales].[Time], " & _
" DIMENSION [PredictIncome] NOT_RELATED_TO_FACTS " & _
" FROM [Local Find Salary] " & _
" COLUMN [Customers.Name.Yearly Income] " & _
") ")
Dim recCols As Recordset
Dim vtRestrict As Variant
vtRestrict = Array(Empty, Empty, "Local Find Salary")
' open the data mining model's content as a rowset
Set recCols = m_conn.OpenSchema(adSchemaProviderSpecific, vtRestrict, sGUID_SCHEMA_MODEL_CONTENT)
' display each node caption of the resulting decision tree
Do While Not recCols.EOF
MsgBox recCols.Fields("NODE_CAPTION").Value
recCols.MoveNext
Loop
m_conn.Close
End Sub
不幸的是你不得不使用这样的程序而不是MDX范例,因为命令的执行必须用到一个返回记录集,而不是在前面讨论的三全命令中使用的标准的多维单元集,而后打开一个微软专有的图表记录集(我在例程中添加了OpenSchema函数来说明如何获取挖掘模型的内容)。例程仅仅列出了决策树中每一结点的名称,记录集被组织成象父子维表一样的结构,该记录集的每个记录在决策树中确定一个结点,并具有一个NODE_UNIQUE_NAME和PARENT_UNIQUE_NAME字段。PARENT_UNIQUE_NAME确定包含当前行的父纪录的记录。
在例程的开始,是一个包含GUID的列表,可以利用它访问所有和数据挖掘相关的特定提供者的记录集。在上面例程中没有用到它们,但如果你计划开发支持数据挖掘功能的应用程序,不妨试试它们。
比想象的要简单
当我第一次看OLE DB for DM的详细说明时,认为要完成一个简单的数据挖掘也需要程序员或应用程序用户提供如此多的信息,以至于怀疑它对于普通决策者是否有用。但通过深入的研究,我明白了它之所以看起来比较复杂,是因为在挖掘关系数据库需要较多的信息,挖掘OLAP多维数据集则不需要太多的信息。OLAP数据挖掘是简单、快速、有用的,决策树算法是一种可以帮助我们对大量数据进行结构化处理从而获取有用信息的好方法。
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接