Analytics Manager > Using the Tutorials > Tutorial: Use the Analytics Server Connector for Predictive Scoring on Time Series Models
Tutorial: Use the Analytics Server Connector for Predictive Scoring on Time Series Models
With this tutorial, learn how to use the TW.AnalysisServices.AnalyticsServer.AnalyticsServerConnector connector in Analytics Manager and the prediction service in Analytics Server to perform predictive scoring on time series models. The following list is a high-level overview of tasks that you need to complete:
This tutorial does not include each step of creating different entities in Analytics Manager and ThingWorx Composer. It is assumed that you have basic knowledge about these applications. However, appropriate links have been provided, wherever required.
Step A: Test and Enable an Analysis Model in Analytics Manager
1. Use the TW.AnalysisServices.AnalyticsServer.AnalyticsServerConnector connector to create the analysis provider. For this demo, create the ServerProvider analysis provider.
For more information about creating an analysis provider, refer to Create an Analysis Provider.
2. Create an analysis model in Analytics Manager. This model is uploaded to the configured Analytics Server. To create the TimeSeriesSensorModel model, complete the following steps:
a. Download the sample predictive model provided in the Reference Documents section of the PTC eSupport Portal:
b. In the Create Analysis Model window, select the Upload Model? check box, and browse to the location where you saved the predictive model file.
For more information about creating an analysis model, refer to Create an Analysis Model.
Alternatively, if you have a model that is in the “completed” state in Analytics Builder, select the model, and click Publish. This model from Analytics Builder opens as an analysis model in Analytics Manager.
3. Test the analysis model by performing the following steps:
a. From the Analysis Models page, select the TimeSeriesSensorModel model that you created in the previous step, and click View.
b. From the left navigation pane, click Test.
c. Under the Inputs for the Analysis Job section, enter the following input values in the fields of the Input Data Row Values sub-section:
You can also set the value of causalTechnique to DISTANCE_FROM_MIN or DISTANCE_FROM_MAX.
The MiningSchema tag lists all the fields in the model. For this model, the sensor field is specified with usageType="target", and so it is the goal name that is used while requesting a predictive score.
Predictive scoring on time series models do not support an important field count greater than 0. If you specify a value greater than 0, the scoring job fails.
d. Click Add Row.
e. Repeat the above step thrice.
The look back count of this model is set to 4. So, we need to provide at least 4 rows of input data. If we provide less than 4 rows of data, then the scoring job fails.
For 4 rows of input data, the job returns 1 row of result data. For 5 rows of input data, the job returns 2 rows of result data, and so on.
f. Click Submit Job to initiate the analysis job.
g. Under the Results from the Analysis Job section, view the results that are saved to the ServerProvider.TimeSeriesSensorModel.ResultDataShape infotable. This infotable has the following fields:
The results that are returned depend on the output fields that are defined in the PMML model. Different models may have different result fields.
4. Enable the analysis model that you created.
Step B: Create a Thing and Value Stream in ThingWorx Composer
1. Use the CreateOrUpdateThingTemplateAndThingForModel service in the TW.AnalysisServices.ModelManagementServicesAPI resource to create a thing template that inherits the input and result data shape properties of the specified model, and a thing that inherits this thing template. For information about creating this thing template and thing, see the input and result parameters at Services for Managing Models.
Once you execute the CreateOrUpdateThingTemplateAndThingForModel service, the ServerProvider-TimeSeriesSensorModel-AnalysisThing thing is created that inherits the ServerProvider-TimeSeriesSensorModel-AnalysisThingTemplate thing template.
2. Create a value stream and assign it to the ServerProvider-TimeSeriesSensorModel-AnalysisThingTemplate thing template.
For more information about value streams, see the ThingWorx Help Center.
3. Edit each property of the thing template, and select the Logged check box.
4. Set values of the following properties on the ServerProvider-TimeSeriesSensorModel-AnalysisThingTemplate thing template:
Step C: Create and Enable an Analysis Event in Analytics Manager
1. For this tutorial, ensure that you select the following options in the Create New Event window:
a. In the Source Type (Required) list, select Thing.
b. In the Source (Required) list, click the icon to search for the ServerProvider-TimeSeriesSensorModel-AnalysisThing thing.
c. In the Event (Required) list, select AnyDataChange.
d. In the Provider Name (Required) list, select the ServerProvider provider.
e. In the Model Name (Required) list, select the TimeSeriesSensorModel model.
f. In the Retain Job History field, select All.
The values of the Lookback Count and Data Sampling Frequency are set automatically according to the values defined in the model.
For information about creating an analysis event, see Create an Analysis Event.
2. Select the analysis event that you created, and click Map Data. In the Map Analysis Input and Results to Properties window, map the following inputs and result:
Mapping Type
Source Type
Source — ServerProvider-TimeSeriesSensorModel-AnalysisThing
a. Click Map All to map all the properties.
b. Under the Input Data Shape section, select the key property, and click Remove to remove the mapping.
Event Source
Target — ServerProvider-TimeSeriesSensorModel-AnalysisThing
a. Click Map All to map all the properties.
b. Under the Result Data Shape section, select the key property, and click Remove to remove the mapping.
For more information about inputs mapping, see Map Input Data. For information about results mapping, see Map Result Data.
3. Select the event, and click Enable to enable the analysis event.
Step D: Configure the Connector Thing for Asynchronous Jobs in ThingWorx Composer (optional)
By default, the AnalyticsServerConnector handles analysis jobs synchronously. If you prefer to handle the jobs asynchronously, follow the steps below to enable the runJobAsAsync property.
1. In ThingWorx Composer, open the list of Things.
2. Navigate to the TW.AnalysisServices.AnalyticsServer.AnalyticsServerConnector Thing and open it.
3. Open the Properties and Alerts tab.
4. On the runJobAsAsync property, click the Edit icon () in the Value column. A panel opens on the right.
5. Set the property value to True and click the Save icon (). The check box in the Value column will appear checked.
Step D: Trigger the Analysis Event from ThingWorx Composer
1. Since the event is set to be triggered on data change of any property, change the value of any of the input properties of the ServerProvider-TimeSeriesSensorModel-AnalysisThing thing.
As soon as you set the value of the property, an analysis event is triggered in Analytics Manager, and an analysis job is created.
Step E: View the results in Analytics Manager
View the results on the Analysis Jobs page in Analytics Manager. For more information, see Working with Analysis Jobs.
The results are saved to the ServerProvider.TimeSeriesSensorModel.ResultDataShape infotable.
Step F: View the results in ThingWorx Composer
Since we have mapped results back to the properties of the ServerProvider.TimeSeriesSensorModel.ResultDataShape thing, the result values are also available in the result properties of the thing.
Was this helpful?