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

Time Series Prediction DMX Tutorial

In this tutorial, you will learn how to create a time series mining structure, create three custom time series mining models, and then make predictions by using those models.

The mining models are based on the data contained in the sample database, which stores data for the fictitious company Adventure Works Cycles. Adventure Works Cycles is a large, multinational manufacturing company.

Tutorial Scenario

Adventure Works Cycles has decided to use data mining to generate sales projections. They have already built some regional forecasting models; for more information, see Lesson 2: Building a Forecasting Scenario (Intermediate Data Mining Tutorial). However, the Sales Department needs to be able to periodically update the data mining model with new sales data. They also want to customize the models to provide different projections.

Microsoft SQL Server Analysis Services provides several tools that can be used to accomplish this task:

The Data Mining Extensions (DMX) query language

The Microsoft Time Series Algorithm

Query Editor in SQL Server Management Studio

The Microsoft Time Series algorithm creates models that can be used for prediction of time-related data. Data Mining Extensions (DMX) is a query language provided by Analysis Services that you can use to create mining models and prediction queries.

What You Will Learn

This tutorial assumes that you are already familiar with the objects that Analysis Services uses to create mining models. If you have not previously created a mining structure or mining model by using DMX, see Bike Buyer DMX Tutorial.

This tutorial is divided into the following lessons:

Creating a Time Series Mining Structure

In this lesson, you will learn how to use the CREATE MINING MODEL statement to add a new forecasting model and a related mining model.

Adding Mining Models to the Time Series Mining Structure

In this lesson, you will learn how to use the ALTER MINING STRUCTURE statement to add new mining models to the time series structure. You will also learn how to customize the algorithm used for analyzing a time series.

Lesson 3: Processing the Time Series Structure and Models

In this lesson, you will learn how to train the models by using the INSERT INTO statement and populating the structure with data from the database.

194

Creating Time Series Predictions Using DMX

In this lesson, you will learn how to create time series predictions.

Extending the Time Series Model

In this lesson, you will learn how to use the EXTEND_MODEL_CASES parameter to update the model with new data when you make predictions.

Requirements

Before doing this tutorial, make sure that the following are installed:

Microsoft SQL Server

Microsoft SQL Server Analysis Services

• The

database

By default, the sample databases are not installed, to enhance security. To install the official sample databases for Microsoft SQL Server, go to http://www.CodePlex.com/MSFTDBProdSamples or on the Microsoft SQL Server Samples and Community Projects home page in the section Microsoft SQL Server Product Samples. Click Databases, then click the Releases tab and select the databases that you want.

Note

When you review tutorials, we recommend that you add Next topic and Previous topic buttons to the document viewer toolbar. For more information, see Adding Next and Previous Buttons to Help.

See Also

Data Mining Tutorial

Intermediate Data Mining Tutorial (Analysis Services - Data Mining)

Lesson 1: Creating a Time Series Mining Model and Mining Structure

In this lesson, you will create a mining model that allows you to predict values over time, based on historical data. When you create the model, the underlying structure will be generated automatically and can be used as the basis for additional mining models.

This lesson assumes that you are familiar with forecasting models and with the requirements of the Microsoft Time Series algorithm. For more information, see Microsoft Time Series Algorithm (Analysis Services - Data Mining).

CREATE MINING MODEL Statement

In order to create a mining model directly and automatically generate the underlying mining structure, you use the CREATE MINING MODEL (DMX) statement. The code in the statement can be broken into the following parts:

Naming the model

195

Defining the time stamp

Defining the optional series key column

Defining the predictable attribute or attributes

The following is a generic example of the CREATE MINING MODEL statement:

CREATE MINING MODEL [<Mining Structure Name>]

(

<key columns>,

<predictable attribute columns>

)

USING <algorithm name>([parameter list]) WITH DRILLTHROUGH

The first line of the code defines the name of the mining model:

CREATE MINING MODEL [Mining Model Name]

Analysis Services automatically generates a name for the underlying structure, by appending "_structure" to the model name, which ensures that the structure name is unique from the model name. For information about naming an object in DMX, see Identifiers (DMX).

The next line of the code defines the key column for the mining model, which in the case of a time series model uniquely identifies a time step in the source data. The time step is identified with the KEY TIME keywords after the column name and data types. If the time series model has a separate series key, it is identified by using the KEY keyword.

<key columns>

The next line of the code is used to define the columns in the model that will be predicted. You can have multiple predictable attributes in a single mining model. When there are multiple predictable attributes, the Microsoft Time Series algorithm generates a separate analysis for each series:

<predictable attribute columns>

Lesson Tasks

You will perform the following tasks in this lesson:

Create a new blank query

Alter the query to create the mining model

Execute the query

Creating the Query

The first step is to connect to an instance of Analysis Services and create a new DMX query in SQL Server Management Studio.

To create a new DMX query in SQL Server Management Studio

196

1.Open SQL Server Management Studio.

2.In the Connect to Server dialog box, for Server type, select Analysis Services. In

Server name, type LocalHost, or the name of the instance of Analysis Services that you want to connect to for this lesson. Click Connect.

3.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.

Altering the Query

The next step is to modify the CREATE MINING MODEL statement to create the mining model used for forecasting, together with its underlying mining structure.

To customize the CREATE MINING MODEL statement

1.In Query Editor, copy the generic example of the CREATE MINING MODEL statement into the blank query.

2.Replace the following:

[mining model name] with:

[Forecasting_MIXED]

3. Replace the following:

<key columns> with:

[Reporting Date] DATE KEY TIME, [Model Region] TEXT KEY

The TIME KEY keyword indicates that the ReportingDate column contains the time step values used to order the values. Time steps can be dates and times, integers, or any ordered data type, so long as the values are unique and the data is sorted.

The TEXT and KEY keywords indicate that the ModelRegion column contains an additional series key. You can have only one series key, and the values in the column must be distinct.

4. Replace the following:

< predictable attribute columns> ) with:

[Quantity] LONG CONTINUOUS PREDICT,

[Amount] DOUBLE CONTINUOUS PREDICT

)

197

5. Replace the following:

USING <algorithm name>([parameter list]) WITH DRILLTHROUGH

with:

USING Microsoft_Time_Series(AUTO_DETECT_PERIODICITY = 0.8, FORECAST_METHOD = 'MIXED')

WITH DRILLTHROUGH

The algorithm parameter, AUTO_DETECT_PERIODICITY = 0.8, indicates that you want the algorithm to detect cycles in the data. Setting this value closer to 1 favors the discovery of many patterns but can slow processing.

The algorithm parameter, FORECAST_METHOD, indicates whether you want the data to be analyzed using ARTXP, ARIMA, or a mixture of both.

The keyword, WITH DRILLTHROUGH, specify that you want to be able to view detailed statistics in the source data after the model is complete. You must add this clause if you want to browse the model by using the Microsoft Time Series Viewer. It is not required for prediction.

The complete statement should now be as follows:

CREATE MINING MODEL [Forecasting_MIXED]

(

[Reporting Date] DATE KEY TIME, [Model Region] TEXT KEY, [Quantity] LONG CONTINUOUS PREDICT, [Amount] DOUBLE CONTINUOUS PREDICT

)

USING Microsoft_Time_Series (AUTO_DETECT_PERIODICITY = 0.8, FORECAST_METHOD = 'MIXED')

WITH DRILLTHROUGH

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

Forecasting_MIXED.dmx.

Executing the Query

The final step is to execute the query. After a query is created and saved, it needs to be executed to create the mining model and its mining structure on the server. For more information about executing queries in Query Editor, see SQL Server Management Studio Transact SQL Query.

198

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