Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SQL Server 2012 Tutorials - Analysis Services Data Mining.pdf
Скачиваний:
38
Добавлен:
26.03.2016
Размер:
1.41 Mб
Скачать

WITH DRILLTHROUGH

2.On the File menu, click Save DMXQuery1.dmx As.

3.In the Save As dialog box, browse to the appropriate folder, and name the file

Forecasting_ARTXP.dmx.

4.On the toolbar, click the Execute button.

In the next lesson, you will process all of the models and the mining structure.

Next Lesson

Lesson 3: Processing the Time Series Structure and Models

See Also

Microsoft Time Series Algorithm (Analysis Services - Data Mining)

Microsoft Time Series Algorithm Technical Reference (Analysis Services - Data Mining)

Lesson 3: Processing the Time Series Structure and Models

In this lesson, you will use the INSERT INTO statement to process the time series mining structures and mining models that you created.

When you process a mining structure, Analysis Services reads the source data and builds the structures that support mining models. You always have to process a mining model and structure when you first create it. If you specify the mining structure when using INSERT INTO, the statement processes the mining structure and all its associated mining models.

When you add a mining model to a mining structure that has already been processed, you can use the INSERT INTO MINING MODEL statement to process just the new mining model by using the existing data.

For more information about processing mining models, see Processing Data Mining Objects.

INSERT INTO Statement

In order to train the time series mining structure and all its associated mining models, use the INSERT INTO (DMX) statement. The code in the statement can be broken into the following parts.

Identifying the mining structure

Listing the columns in the mining structure

Defining the training data

The following is a generic example of the INSERT INTO statement:

INSERT INTO MINING STRUCTURE [<mining structure name>]

(

<mining structure columns>

)

203

OPENQUERY (<source data definition>)

The first line of the code identifies the mining structure that you will train:

INSERT INTO MINING STRUCTURE [<mining structure name>]

The next lines of the code specify the columns that are defined by the mining structure. You must list each column in the mining structure, and each column must map to a column contained within the source query data.

(

<mining structure columns>

)

The final lines of the code define the data that will be used to train the mining structure.

OPENQUERY (<source data definition>)

In this lesson, you use OPENQUERY to define the source data. For more information about other methods of defining a query on the source data, see <source data query>.

Lesson Tasks

You will perform the following task in this lesson:

Process the mining structure Forecasting_MIXED_Structure

Process the related mining models Forecasting_MIXED, Forecasting_ARIMA, and Forecasting_ARTXP

Processing the Time Series Mining Structure

To process the mining structure and related mining models by using INSERT INTO

1.In Object Explorer, right-click the instance of Analysis Services, point to New Query, and then click DMX.

Query Editor opens and contains a new, blank query.

2.Copy the generic example of the INSERT INTO statement into the blank query.

3.Replace the following:

[<mining structure>] with:

Forecasting_MIXED_Structure

4. Replace the following:

<mining structure columns>

with:

[ReportingDate],

[ModelRegion]

5. Replace the following:

204

OPENQUERY(<source data definition>) with:

OPENQUERY([Adventure Works DW 2008R2],'SELECT [ReportingDate], [ModelRegion], [Quantity], [Amount]

FROM vTimeSeries ORDER BY [ReportingDate]')

The source query references the data source defined in the IntermediateTutorial sample project. It uses this data source to access the view vTimeSeries. This view contains the source data that will be used to train the mining model. If you are not familiar with this project or this views, see Lesson 2: Building a Forecasting Scenario (Intermediate Data Mining Tutorial).

The complete statement should now be as follows:

INSERT INTO MINING STRUCTURE [Forecasting_MIXED_Structure]

(

[ReportingDate],[ModelRegion],[Quantity],[Amount])

)

OPENQUERY(

[Adventure Works DW 2008R2],

'SELECT [ReportingDate],[ModelRegion],[Quantity],[Amount] FROM vTimeSeries ORDER BY [ReportingDate]'

)

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

ProcessForecastingAll.dmx.

8.On the toolbar, click the Execute button.

After the query has finished running, you can create predictions by using the processed mining models. In the next lesson, you will create several predictions based on the mining models that you created.

Next Lesson

Lesson 4: Creating Time Series Predictions Using DMX

See Also

Processing Data Mining Objects <source data query> OPENQUERY (DMX)

205

Lesson 4: Creating Time Series Predictions Using DMX

In this lesson and the following lesson, you will use Data Mining Extensions (DMX) to create different types of predictions based on the time series models that you created in Lesson 1: Creating a Time Series Mining Model and Mining Structure and Lesson 2: Adding Mining Models to the Time Series Mining Structure.

With a time series model, you have many options for making predictions:

Use the existing patterns and data in the mining model

Use the existing patterns in the mining model but supply new data

Add new data to the model or update the model.

The syntax for making these prediction types is summarized below:

Default time series prediction

Use PredictTimeSeries (DMX) to return the specified number of predictions from the trained mining model.

For example, see PredictTimeSeries (DMX) or Querying a Time Series Model (Analysis Services - Data Mining).

EXTEND_MODEL_CASES

Use PredictTimeSeries (DMX) with the EXTEND_MODEL_CASES argument to add new data, extend the series, and create predictions based on the updated mining model.

This tutorial contains an example of how to use EXTEND_MODEL_CASES.

REPLACE_MODEL_CASES

Use PredictTimeSeries (DMX) with the REPLACE_MODEL_CASES argument to replace the original data with a new data series, and then create predictions based on applying the patterns in the mining model to the new data series.

For an example of how to use REPLACE_MODEL_CASES, see Lesson 2: Building a Forecasting Scenario (Intermediate Data Mining Tutorial).

Lesson Tasks

You will perform the following tasks in this lesson:

Create a query to get the default predictions based on existing data. In the following lesson you will perform the following related tasks:

Create a query to supply new data and get updated predictions.

In addition to creating queries manually by using DMX, you can also create predictions by using the prediction query builder in SQL Server Data Tools (SSDT). For more information, see Using the Prediction Query Builder to Create DMX Prediction Queries or Mining Model Prediction Tab: How-to Topics.

Simple Time Series Prediction Query

The first step is to use the SELECT FROM statement together with the PredictTimeSeries function to create time series predictions. Time series models

206

support a simplified syntax for creating predictions: you do not need to supply any inputs, but only have to specify the number of predictions to create. The following is a generic example of the statement you will use:

SELECT <select list>

FROM [<mining model name>] WHERE [<criteria>]

The select list can contain columns from the model, such as the name of the product line that you are creating the predictions for, or prediction functions, such as Lag (DMX) or PredictTimeSeries (DMX), which are specifically for time series mining models.

To create a simple time series prediction query

1.In Object Explorer, right-click the instance of Analysis Services, point to New Query, and then click DMX.

Query Editor opens and contains a new, blank query.

2.Copy the generic example of the statement into the blank query.

3.Replace the following:

<select list> with:

[Forecasting_MIXED].[ModelRegion],

PredictTimeSeries([Forecasting_MIXED].[Quantity],6) AS PredictQty,

PredictTimeSeries ([Forecasting_MIXED].[Amount],6) AS PredictAmt

The first line retrieves a value from the mining model that identifies the series.

The second and third lines use the PredictTimeSeries function. Each line predicts a different attribute, [Quantity] or [Amount]. The numbers after the names of the predictable attributes specify the number of time steps to predict.

The AS clause is used to provide a name for the column that is returned by each prediction function. If you do not supply an alias, by default both columns are returned with the label, Expression.

4. Replace the following:

[<mining model>] with:

[Forecasting_MIXED]

5. Replace the following:

WHERE [criteria>]

207

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]