--- title: "Lesson 4: Executing Market Basket Predictions | Microsoft Docs" ms.custom: "" ms.date: "03/06/2017" ms.prod: "sql-server-2014" ms.reviewer: "" ms.technology: analysis-services ms.topic: conceptual ms.assetid: b3238f1b-ea04-4253-ade2-838a806b62fe author: minewiskan ms.author: owend manager: kfile --- # Lesson 4: Executing Market Basket Predictions In this lesson, you will use the DMX `SELECT` statement to create predictions based on the association models you created in [Lesson 2: Adding Mining Models to the Market Basket Mining Structure](../../2014/tutorials/lesson-2-adding-mining-models-to-the-market-basket-mining-structure.md). A prediction query is created by using the DMX `SELECT` statement and adding a `PREDICTION JOIN` clause. For more information about the syntax of a prediction join, see [SELECT FROM <model> PREDICTION JOIN (DMX)](/sql/dmx/select-from-model-cases-dmx). The **SELECT FROM \ PREDICTION JOIN** form of the `SELECT` statement contains three parts: - A list of the mining model columns and prediction functions that are returned in the result set. This list can also contain input columns from the source data. - A source query that defines the data that is being used to create a prediction. For example, if you are creating many predictions in a batch, the source query could retrieve a list of customers. - A mapping between the mining model columns and the source data. If the columns names match, you can use the `NATURAL PREDICTION JOIN` syntax and omit the column mappings. You can enhance the query by using prediction functions. Prediction functions provide additional information, such as the probability of a prediction occurring, or the support for a prediction in the training dataset. For more information about prediction functions, see [Functions (DMX)](/sql/dmx/functions-dmx). You can also use the prediction query builder in [!INCLUDE[ssBIDevStudioFull](../includes/ssbidevstudiofull-md.md)] to create prediction queries. ## Singleton PREDICTION JOIN Statement The first step is to create a singleton query, by using the **SELECT FROM \ PREDICTION JOIN** syntax and supplying a single set of values as input. The following is a generic example of the singleton statement: ``` SELECT ] ``` The first line of the code defines the columns from the mining model that the query returns, and specifies the name of the mining model used to generate the prediction: ``` SELECT ``` with: ``` PREDICT([Default Association].[Products],INCLUDE_STATISTICS,3) ``` You could just include the column name [Products], but by using the [Predict (DMX)](/sql/dmx/predict-dmx) function, you can limit the number of products that are returned by the algorithm to three. You can also use `INCLUDE_STATISTICS`, which returns the support, probability, and adjusted probability for each product. These statistics help you rate the accuracy of the prediction. 4. Replace the following: ``` [] ``` with: ``` [Default Association] ``` 5. Replace the following: ``` (SELECT '' AS [], (SELECT 'value' AS [] UNION SELECT 'value' AS [] ...) AS []) ``` with: ``` (SELECT (SELECT 'Mountain Bottle Cage' AS [Model] UNION SELECT 'Mountain Tire Tube' AS [Model] UNION SELECT 'Mountain-200' AS [Model]) AS [Products]) AS t ``` This statement uses the `UNION` statement to specify three products that must be included in the shopping cart together with the predicted products. The Model column in the `SELECT` statement corresponds to the model column that is contained in the nested products table. The complete statement should now be as follows: ``` SELECT PREDICT([Default Association].[Products],INCLUDE_STATISTICS,3) From [Default Association] NATURAL PREDICTION JOIN (SELECT (SELECT 'Mountain Bottle Cage' AS [Model] UNION SELECT 'Mountain Tire Tube' AS [Model] UNION SELECT 'Mountain-200' AS [Model]) AS [Products]) AS t ``` 6. On the **File** menu, click **Save DMXQuery1.dmx As**. 7. In the **Save As** dialog box, browse to the appropriate folder, and name the file `Association Prediction.dmx`. 8. On the toolbar, click the **Execute** button. The query returns a table that contains three products: HL Mountain Tire, Fender Set - Mountain, and ML Mountain Tire. The table lists these returned products in order of probability. The returned product that is most likely to be included in the same shopping cart as the three products specified in the query appears at the top of the table. The two products that follow are the next most likely to be included in the shopping cart. The table also contains statistics describing the accuracy of the prediction. ## Create a Prediction by Using a Model with a MINIMUM_PROBABILITY of 0.01 #### To create an association query 1. In **Object Explorer**, right-click the instance of [!INCLUDE[ssASnoversion](../includes/ssasnoversion-md.md)], point to **New Query**, and then click **DMX** to open the Query Editor. 2. Copy the generic example of the `PREDICTION JOIN` statement into the blank query. 3. Replace the following: ```