SELECT FLATTENED NODE_NAME, NODE_CAPTION,
(SELECT ATTRIBUTE_NAME, ATTRIBUTE_VALUE, [SUPPORT]
FROM NODE_DISTRIBUTION) AS t
FROM TM_DecisionTree.CONTENT
WHERE [PARENT_UNIQUE_NAME] = '000000001'
SELECT FLATTENED NODE_NAME, NODE_CAPTION,NODE_TYPE,
(
SELECT [SUPPORT] FROM NODE_DISTRIBUTION WHERE ATTRIBUTE_NAME = 'Bike Buyer' AND ATTRIBUTE_VALUE = '1'
) AS t
FROM TM_DecisionTree.CONTENT
WHERE ISDESCENDANT('0000000010001')
AND NODE_TYPE = 4
下面的示例查询使用在 Basic Data Mining Tutorial中创建的决策树模型。 查询从表 dbo 传入一组新的示例数据。AdventureWorks2012 DW 中的潜在购买者,用于预测新数据集中的哪些客户将购买自行车。
该查询使用预测函数 PredictHistogram (DMX) ,该函数返回一个嵌套表,其中包含有关模型发现的概率的有用信息。 该查询的最后的 WHERE 子句将筛选结果,以便仅返回预测购买自行车的概率大于 0% 的那些潜在客户。
SELECT
[TM_DecisionTree].[Bike Buyer],
PredictHistogram([Bike Buyer]) as Results
From
[TM_DecisionTree]
PREDICTION JOIN
OPENQUERY([Adventure Works DW Multidimensional 2012],
'SELECT
[FirstName],
[LastName],
[MaritalStatus],
[Gender],
[YearlyIncome],
[TotalChildren],
[NumberChildrenAtHome],
[HouseOwnerFlag],
[NumberCarsOwned]
FROM
[dbo].[ProspectiveBuyer]
') AS t
ON
[TM_DecisionTree].[First Name] = t.[FirstName] AND
[TM_DecisionTree].[Last Name] = t.[LastName] AND
[TM_DecisionTree].[Marital Status] = t.[MaritalStatus] AND
[TM_DecisionTree].[Gender] = t.[Gender] AND
[TM_DecisionTree].[Yearly Income] = t.[YearlyIncome] AND
[TM_DecisionTree].[Total Children] = t.[TotalChildren] AND
[TM_DecisionTree].[Number Children At Home] = t.[NumberChildrenAtHome] AND
[TM_DecisionTree].[House Owner Flag] = t.[HouseOwnerFlag] AND
[TM_DecisionTree].[Number Cars Owned] = t.[NumberCarsOwned]
WHERE [Bike Buyer] = 1
AND PredictProbability([Bike Buyer]) >'.05'
默认情况下,SQL Server Analysis Services返回带有列标签 Expression 的嵌套表。 可通过对返回的列使用别名来更改此标签。 如果使用别名,则该别名(本例中为 Results)将用作嵌套表中的列标题和值。 必须展开嵌套表才能查看结果。
下面的示例查询基于关联挖掘结构。 为了按照此示例内容进行操作,您可以在此挖掘结构中添加一个新模型,并且选择 Microsoft 决策树作为算法。 有关如何创建关联挖掘结构的详细信息,请参阅 第 3 课:构建市场篮方案 (中间数据挖掘教程) 。
以下示例查询是一个单一查询,可以通过选择字段,然后从下拉列表中选择这些字段的值,在SQL Server Data Tools轻松创建该查询。
SELECT PredictAssociation([DT_Association].[v Assoc Seq Line Items],3)
FROM
[DT_Association]
NATURAL PREDICTION JOIN
(SELECT (SELECT 'Patch kit' AS [Model]) AS [v Assoc Seq Line Items]) AS t
SELECT PredictAssociation([DT_Association].[v Assoc Seq Line Items],3)
From
[DT_Association]
NATURAL PREDICTION JOIN
(SELECT (SELECT 'Racing Socks' AS [Model]
UNION SELECT 'Women''s Mountain Shorts' AS [Model]) AS [v Assoc Seq Line Items]) AS t