Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
I want to send a webrequest to the RealtimeScore service of Thingworx (Analytics).
My model is a simple XOR (exclusive or) model.
My POST request body looks like this:
{
"jobName": "PostmanJobRealtimeScore",
"description": "descipritonPostmanRealtimeScore",
"datasetRef": {
"dataShape": {
"fieldDefinitions": {
"datasetUri": {
"name": "datasetUri",
"description": "Location of the data",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"format": {
"name": "format",
"description": "Structure of the data (CSV,PARQUET,CLQUET)",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"filter": {
"name": "filter",
"description": "SQL WHERE clause to refine the dataset",
"baseType": "STRING",
"ordinal": 0,
"aspects": {}
},
"exclusions": {
"name": "exclusions",
"description": "Fields to remove from the dataset",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {
"dataShape": "GenericStringList"
}
},
"data": {
"name": "data",
"description": "An infotable of data (must be flat. for providing data as part of request)",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {}
},
"metadata": {
"name": "metadata",
"description": "Metadata of the dataset (for providing data as part of request)",
"baseType": "INFOTABLE",
"ordinal": 0,
"aspects": {
"dataShape": "AnalyticsDatasetMetadata"
}
}
}
},
"rows": [
{
"datasetUri": "body:/",
"format": "CSV",
"metadata": {
"dataShape": {
"fieldDefinitions": {
"fieldName": {
"name": "fieldName",
"baseType": "STRING",
"ordinal": 0
},
"values": {
"name": "values",
"baseType": "INFOTABLE",
"ordinal": 0
},
"isStatic": {
"name": "isStatic",
"baseType": "BOOLEAN",
"ordinal": 0
},
"min": {
"name": "min",
"description": "Minimum observed value for Continuous fields",
"baseType": "NUMBER",
"ordinal": 0
},
"max": {
"name": "max",
"description": "Maximum observed value for Continuous fields",
"baseType": "NUMBER",
"ordinal": 0
},
"dataType": {
"name": "dataType",
"baseType": "STRING",
"ordinal": 0
},
"opType": {
"name": "opType",
"baseType": "STRING",
"ordinal": 0
},
"timeSamplingInterval": {
"name": "timeSamplingInterval",
"baseType": "STRING",
"ordinal": 0
}
}
},
"rows": [
{
"fieldName": "x1",
"dataType": "STRING",
"opType": "ORDINAL",
"values": {
"dataShape": {
"fieldDefinitions": {
"item": {
"name": "item",
"baseType": "STRING",
"ordinal": 0
}
}
},
"rows": [
{
"item": "0"
},
{
"item": "1"
}
]
}
},
{
"fieldName": "x2",
"dataType": "STRING",
"opType": "ORDINAL",
"values": {
"dataShape": {
"fieldDefinitions": {
"item": {
"name": "item",
"baseType": "STRING",
"ordinal": 0
}
}
},
"rows": [
{
"item": "0"
},
{
"item": "1"
}
]
}
},
{
"fieldName": "y",
"dataType": "STRING",
"opType": "ORDINAL",
"values": {
"dataShape": {
"fieldDefinitions": {
"item": {
"name": "item",
"baseType": "STRING",
"ordinal": 0
}
}
},
"rows": [
{
"item": "0"
},
{
"item": "1"
}
]
}
}
]
},
"data": {
"dataShape": {
"fieldDefinitions": {
"x1": {
"name": "x1",
"baseType": "STRING",
"ordinal": 0
},
"x2": {
"name": "x2",
"baseType": "STRING",
"ordinal": 0
},
"y": {
"name": "y",
"baseType": "STRING",
"ordinal": 0
}
}
},
"rows": [
{
"x1": "1",
"x2": "1",
"y": ""
}
]
}
}
]
},
"goalField": "y",
"modelUri": "thingworx://repository/TW.AnalysisServices.ModelRepository/Provider/mlp_xor.pmml",
"importantFieldCount": "0",
"causalTechnique": "FULL_RANGE"
}
But I get an error message when I want to pass my pmml file in the modelUri parameter:
Unable to Invoke Service RealtimeScore on AnalyticsServer_1_PredictionThing : Could not process request: [There is no result source registered for this scheme: thingworx [refer to logs for more details
]
]
How can I pass a pmml model to the modelUri parameter so that my webrequest works?
Also if that is not possible how can I get the guid of uploaded pmml models in the analytics manager?
Solved! Go to Solution.
Hi @Max3
I seem to have overlooked something last week for some reason, but here some more update regarding model uploaded in analytics Manager.
You will indeed need to get the GUID of the model to pass it to the modelUri argument, you cannot use thingworx:// notation.
Getting the GUID is actually the exact same was as what is described in the article I sent last week.
That is execute the ResultsThing.GetDetailsList service.
You will see there your model (file name is in description field), and you can use the resultUri output as input of modelUri.
Hope this helps
Christophe
Hi @Max3
This is an interesting question.
We do not recommend performing REST calls to ThingWorx Analytics due to the complexity of the syntax, usually using the Thing services is much easier and more flexible.
However the question would still remain if you are trying to score against a model uploaded in Analytics Manager.
I will need to do some digging into this as it does not appear obvious at first.
Could you though tell us what Analysis Provider connector did you use for your Analysis model ?
Where was this pmml file created ?
Thank you
Christophe
Hello @cmorfin
Thanks for the fast reply.
I am using the following connector: TW.AnalysisServices.AnalyticsServer.AnalyticsServerConnector
The model was created in Python using sklearn's MLPClassifier and sklean2pmml's sklearn2pmml function.
The model is valid as I can upload it in the ananlytics mangager and use it for real-time predictions.
If you have more questions don't hesitate to ask me.
The only question that remains is how I can use them using the REST interface?
Thank you in advance for your time.
Max3
I have not find yet much information about scoring a model uploaded in Analytics Manager.
However is it a requirement for you to upload it in Analytics Manager ?
I am asking because it would be very straight forward if you would upload the pmml directly to Analytics Server.
You would then get a guid that you can use to fill the modelUri.
The article https://www.ptc.com/en/support/article?n=CS287701 shows the steps to import a pmml into Analytics Server - look at the paragraph Restore / import external pmml file
Hope this helps
Kind regards
Christophe
Hi @Max3
I seem to have overlooked something last week for some reason, but here some more update regarding model uploaded in analytics Manager.
You will indeed need to get the GUID of the model to pass it to the modelUri argument, you cannot use thingworx:// notation.
Getting the GUID is actually the exact same was as what is described in the article I sent last week.
That is execute the ResultsThing.GetDetailsList service.
You will see there your model (file name is in description field), and you can use the resultUri output as input of modelUri.
Hope this helps
Christophe
Hi @Max3.
If one of the previous responses answered your question, please mark the appropriate one as the Accepted Solution for the benefit of others with the same question.
Regards.
--Sharon