Tradeoff Analytics のテスト | Watson メモ

Tradeoff Analyticsのテスト方法に関して説明します。あらかじめ Bluemix アカウントを作成し、さらにTradeoff Analystics サービスを作成する必要があります。

Tradeoff Analytics service Tutorial

上記より、 problem.json (https://www.ibm.com/watson/developercloud/doc/tradeoff-analytics/example/problem.json) をダウンロードしサンプルとして使用します。

このサンプルファイルでは7機種のスマホの仕様、及びユーザ(あなた)がこれらのスマホを選ぶとき、どの項目 "price(値段)"、"weight(重さ)"、"brand(ブランド)"、"rData(発売日)"を重視して購入するかを指定しているファイルです。

例えば「price」を例として説明します。

スポンサーリンク

key key 名を指定します。ここでは"price"を価格として指定しています。
type 型のタイプです。numeric(数値)、datetime(日付)など。
goal この項目を重視する場合、どのような値をプラス要素かを指定します。例えば価格なら安い(min)、重量な少ない(min)、発売日なら最近(max)を指定します。価格なので安い方が良いため「min」を指定しています。
is_objective Tradeoffに含める、要するにこのケースではスマホを選ぶ際に重視するかを指定します。
true の場合、スマホを選択するのに価格を重視するとうことです。
full_name 名前です。
range 値の範囲を指定します。0~400を指定しています。価格が400を超える場合は購入しません。

次はスマホです。ここでは1~7までのスマホが定義されています。これが購入する候補ということです。

Samsung Galaxy S4」を例として説明します。

key 1。このファイルでは1~7まで7機種指定されています。
name Samsung Galaxy S4。名前です。
values -
price 249。価格です。
weight 130。重さです。
brand Samsung。ブランド名、メーカ名です。
rDate  2013-04-29T00:00:00Z。発売年月日です。

これでTradeoff対象のスマホ、及びスマホの選定の条件が揃ったことになります。

スポンサーリンク

{
  "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"
      }
    }
  ]
}

以下の例ではこのファイルが c:\temp\problem.json に保管されている想定です。Watson API に投入して結果を確認します。

C:\>set APIURL=https://gateway.watsonplatform.net/tradeoff-analytics/api
C:\>set USERNAME=********-****-****-****-************
C:\>set PASSWORD=************

C:\>curl -k -X POST -u "%USERNAME%":"%PASSWORD%" -H "Content-Type: application/json" --data @c:\temp\problem.json "%APIURL%/v1/dilemmas?generate_visualization=false"

結果は以下の通りとなります。

{"problem":{"columns":[{"type":"numeric","key":"price","full_name":"Price","range":{"low":0.0,"high":400.0},"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","excluded_by":[{"solution_ref":"1","objectives":[{"key":"price","difference":100.0},{"key":"weight","difference":5.0}]}]},{"solution_ref":"5","status":"EXCLUDED","excluded_by":[{"solution_ref":"2","objectives":[{"key":"price","difference":50.0},{"key":"weight","difference":6.0}]}]},{"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"]}}]}}

Resolution 以下に結果が格納されています。

"solution_ref":"1","status":"FRONT" は上記の key 1 (Samsung Galaxy S4) の結果が FRONT (条件に一致)であることを示しています。


"solution_ref":"4","status":"EXCLUDED","excluded_by":[{"solution_ref":"1","objectives":[{"key":"price","difference":100.0},{"key":"weight","difference":5.0}]}]},{"solution_ref":"5","status":"EXCLUDED","excluded_by":[{"solution_ref":"2","objectives":[{"key":"price","difference":50.0},{"key":"weight","difference":6.0}]}]},{"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]

EXCLUDED (条件外)であることを示しています。理由は価格 499 が指定したレンジである0~400を超えているからです。


"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"]

はbrand が指定した範囲に含まれないことをDOES_NOT_MEET_PREFERENCEとして表現しています。

スポンサーリンク

[Watson メモに戻る]