Try to use Watson’s Tradeoff Analytics API
Overview Tradeoff Analytics is Helps users make better choices to best meet multiple conflicting goals. You do […]
広告ここから
広告ここまで
目次

Overview
- Tradeoff Analytics is Helps users make better choices to best meet multiple conflicting goals.
- You do only POST json at once
- This API returns better choices
Tradeoff Analytics | IBM Watson Developer Cloud
How to call the API
$ curl -X POST --user YOUR_USERNAME:YOUR_PASSWORD --header "Content-Type: application/json" --data @problem.json "https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=false" | jq .
Request body(JSON)
- subject
- Subject of your choices
- columns
- Condition of your choice
- options
- Search target
Example
{
"subject": "phones",
"columns": [
{
"key": "price",
"type": "numeric",
"goal": "min",
"is_objective": true,
"full_name": "Price",
"range": {
"low": 0,
"high": 400
},
"format": "number:2"
},
{
"key": "weight",
"type": "numeric",
"goal": "min",
"is_objective": true,
"full_name": "Weight",
"format": "number:0"
},
{
"key": "brand",
"type": "categorical",
"goal": "min",
"is_objective": true,
"full_name": "Brand",
"range": [
"Apple",
"HTC",
"Samsung",
"Sony"
],
"preference": [
"Samsung",
"Apple",
"HTC"
]
},
{
"key": "rDate",
"type": "datetime",
"goal": "max",
"full_name": "Release Date",
"format": "date: 'MMM dd, yyyy'"
}
],
"options": [
{
"key": "1",
"name": "Samsung Galaxy S4",
"values": {
"price": 249,
"weight": 130,
"brand": "Samsung",
"rDate": "2013-04-29T00:00:00Z"
}
},
{
"key": "2",
"name": "Apple iPhone 5",
"values": {
"price": 349,
"weight": 112,
"brand": "Apple",
"rDate": "2012-09-21T00:00:00Z"
}
},
{
"key": "3",
"name": "HTC One",
"values": {
"price": 299,
"weight": 112,
"brand": "HTC",
"rDate": "2013-03-01T00:00:00Z"
}
},
{
"key": "4",
"name": "Samsung Galaxy S5",
"values": {
"price": 349,
"weight": 135,
"brand": "Samsung",
"rDate": "2014-04-29T00:00:00Z"
}
},
{
"key": "5",
"name": "Apple iPhone 6",
"values": {
"price": 399,
"weight": 118,
"brand": "Apple",
"rDate": "2013-09-21T00:00:00Z"
}
},
{
"key": "6",
"name": "Apple iPhone 7",
"values": {
"price": 499,
"weight": 118,
"brand": "Apple",
"rDate": "2014-09-21T00:00:00Z"
}
},
{
"key": "7",
"name": "Sony Xperia",
"values": {
"price": 199,
"weight": 120,
"brand": "Sony",
"rDate": "2014-08-21T00:00:00Z"
}
}
]
}
If you see..
If you see following returns, some request parameter is wrong.
Invalid UserId and/or Password
{
"code": 401,
"error": "Not Authorized",
"description": "2016-11-19T21:39:28-06:00, Error ERCDPLTFRM-DNLKUPERR occurred when accessing https://158.85.132.88:443/tradeoff-analytics/api/v1/dilemmas, Invalid UserId and/or Password. Please confirm that your credentials match the end-point you are trying to access. A common error is trying to use credentials from an experimental or beta release against a GA release or vice versa"
}
Missing parameters
Following response if you see, please check your request body.
“subject” not found
{
"error": "Data supplied is missing critical information. error_arg_check=\"subject cannot be null or empty\"",
"code": 400
}
“columns” not found
{
"error": "Data supplied is missing critical information. No columns defined",
"code": 400
}
“options” not found
{
"error": "Data supplied is missing critical information. no options found",
"code": 400
}
Returns
If your request succeed.You can see following JSON.
{
"problem": {
"columns": [
{
"type": "numeric",
"key": "price",
"full_name": "Price",
"range": {
"low": 0,
"high": 400
},
"format": "number:2",
"goal": "min",
"is_objective": true
},
{
"type": "numeric",
"key": "weight",
"full_name": "Weight",
"format": "number:0",
"goal": "min",
"is_objective": true
},
{
"type": "categorical",
"key": "brand",
"full_name": "Brand",
"range": [
"Apple",
"HTC",
"Samsung",
"Sony"
],
"goal": "min",
"preference": [
"Samsung",
"Apple",
"HTC"
],
"is_objective": true
},
{
"type": "datetime",
"key": "rDate",
"full_name": "Release Date",
"format": "date: 'MMM dd, yyyy'",
"goal": "max",
"is_objective": false
}
],
"subject": "phones",
"options": [
{
"key": "1",
"name": "Samsung Galaxy S4",
"values": {
"price": 249,
"weight": 130,
"brand": "Samsung",
"rDate": "2013-04-29T00:00:00Z"
}
},
{
"key": "2",
"name": "Apple iPhone 5",
"values": {
"price": 349,
"weight": 112,
"brand": "Apple",
"rDate": "2012-09-21T00:00:00Z"
}
},
{
"key": "3",
"name": "HTC One",
"values": {
"price": 299,
"weight": 112,
"brand": "HTC",
"rDate": "2013-03-01T00:00:00Z"
}
},
{
"key": "4",
"name": "Samsung Galaxy S5",
"values": {
"price": 349,
"weight": 135,
"brand": "Samsung",
"rDate": "2014-04-29T00:00:00Z"
}
},
{
"key": "5",
"name": "Apple iPhone 6",
"values": {
"price": 399,
"weight": 118,
"brand": "Apple",
"rDate": "2013-09-21T00:00:00Z"
}
},
{
"key": "6",
"name": "Apple iPhone 7",
"values": {
"price": 499,
"weight": 118,
"brand": "Apple",
"rDate": "2014-09-21T00:00:00Z"
}
},
{
"key": "7",
"name": "Sony Xperia",
"values": {
"price": 199,
"weight": 120,
"brand": "Sony",
"rDate": "2014-08-21T00:00:00Z"
}
}
]
},
"resolution": {
"solutions": [
{
"solution_ref": "1",
"status": "FRONT"
},
{
"solution_ref": "2",
"status": "FRONT"
},
{
"solution_ref": "3",
"status": "FRONT"
},
{
"solution_ref": "4",
"status": "EXCLUDED"
},
{
"solution_ref": "5",
"status": "EXCLUDED"
},
{
"solution_ref": "6",
"status": "INCOMPLETE",
"status_cause": {
"message": "A column of a option is out of range. Option \"6\" has a value in column \"price\" which is:\"499\" while the column range\" is: [0.0,400.0]",
"error_code": "RANGE_MISMATCH",
"tokens": [
"price",
"499",
"[0.0,400.0]"
]
}
},
{
"solution_ref": "7",
"status": "DOES_NOT_MEET_PREFERENCE",
"status_cause": {
"message": "Option \"7\" has a value that does not meet preference for column \"brand\"",
"error_code": "DOES_NOT_MEET_PREFERENCE",
"tokens": [
"brand"
]
}
}
]
}
}
Where is better choise?
The api’s choice is included in resolution parameters.
$ curl -X POST --user YOUR_USERNAME:YOUR_PASSWORD --header "Content-Type: application/json" --data @problem.json "https://gateway.watsonplatform.net/tradeoff-analytics/api/v1/dilemmas?generate_visualization=false | jq ".resolution"
{
"solutions": [
{
"solution_ref": "1",
"status": "FRONT"
},
{
"solution_ref": "2",
"status": "FRONT"
},
{
"solution_ref": "3",
"status": "FRONT"
},
{
"solution_ref": "4",
"status": "EXCLUDED"
},
{
"solution_ref": "5",
"status": "EXCLUDED"
},
{
"solution_ref": "6",
"status": "INCOMPLETE",
"status_cause": {
"message": "A column of a option is out of range. Option \"6\" has a value in column \"price\" which is:\"499\" while the column range\" is: [0.0,400.0]",
"error_code": "RANGE_MISMATCH",
"tokens": [
"price",
"499",
"[0.0,400.0]"
]
}
},
{
"solution_ref": "7",
"status": "DOES_NOT_MEET_PREFERENCE",
"status_cause": {
"message": "Option \"7\" has a value that does not meet preference for column \"brand\"",
"error_code": "DOES_NOT_MEET_PREFERENCE",
"tokens": [
"brand"
]
}
}
]
}
If you check status parameters, you can check is the item is better choice.
- Front
- Once of your better choice.
- Excluded
- Excluded choices
- Incomplete / DOES_NOT_MEET_PREFERENCE
- Missing or incomplete parameters
In this example, better choices is following items.
- ID:1 – Samsung Galaxy S4
- ID:2 – Apple iPhone 5
- ID:3 – HTC One