Monday, March 26, 2012

order by importance

hi i have an association rule mining model and i want to order the output by the importance here is the select statment:

SELECT

[RelatedOrder].[Order Line]

From

[RelatedOrder]

NATURAL PREDICTION JOIN

(SELECT (SELECT 888 AS [Product ID]) AS [Order Line]) AS t

thanx

You can do the following to get the top N predictions ordered by importance:

SELECT FLATTENED TopCount(Predict([RelatedOrder].[Order Line], INCLUDE_STATISTICS), $AdjustedProbability, N)

From

[RelatedOrder]

NATURAL PREDICTION JOIN

(SELECT (SELECT 888 AS [Product ID]) AS [Order Line]) AS t

If you really want to get all the predictions, the following should work:

SELECT * FROM

(SELECT FLATTENED Predict([RelatedOrder].[Order Line], INCLUDE_STATISTICS) AS PredictedProducts

From

[RelatedOrder]

NATURAL PREDICTION JOIN

(SELECT (SELECT 888 AS [Product ID]) AS [Order Line]) AS t) AS P

ORDER BY [PredictedProducts.$AdjustedProbability]

|||

Here is a different solution for top N predictions sorted by importance:

SELECT FLATTENED Predict([Order Line], N, INCLUDE_STATISTICS, $ADJUSTEDPROBABILITY) FROM [RelatedOrder] NATURAL PREDICTION JOIN ...

This solution is less general (it applies only to nested table predictions, while TopCount applies to any nested table), but typically has better performance (growing to much better if the number of keys in the nested table is large)

Predict([Order Line]) -- returns all predictions from the table

Predict([Order Line], INCLUDE_STATISTICS) -- returns all predictions from the table plus statistics

Predict([Order Line], N, INCLUDE_STATISTICS) -- returns top N predictions sorted by probability (default) from plus statistics

Predict([Order Line], N, INCLUDE_STATISTICS, $ADJUSTEDPROBABILITY) does same as above, but sorts by Adjusted Probability (what you actually need)

No comments:

Post a Comment