16.20 - NaiveBayesTextClassifierPredictの例 - Teradata Vantage NewSQL Engine

Teradata Vantage™ - NewSQL Engineの分析関数

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
プログラミング リファレンス
featnum
B035-1206-162K-JPN

入力

入力テーブルcomplaints_testは、自動車のクレームのログです。この例では、ML Engine TextTokenizer関数をcomplaints_testに適用してテスト データのテーブルcomplaints_tokens_testを作成し、ML Engine NaiveBayesTextClassifierTrainer関数で出力されたモデルcomplaints_tokens_modelを使用します。

complaints_test
doc_id text_data
1 ELECTRICAL CONTROL MODULE IS SHORTENING OUT, CAUSING THE VEHICLE TO STALL. ENGINE WILL BECOME TOTALLY INOPERATIVE. CONSUMER HAD TO CHANGE ALTERNATOR/ BATTERY AND STARTER, AND MODULE REPLACED 4 TIMES, BUT DEFECT STILL OCCURRING CANNOT DETERMINE WHAT IS CAUSING THE PROBLEM。
2 ABS BRAKES FAIL TO OPERATE PROPERLY, AND AIR BAGS FAILED TO DEPLOY DURING A CRASH AT APPROX. 28 MPH IMPACT. MANUFACTURER NOTIFIED。
3 WHILE DRIVING AT 60 MPH GAS PEDAL GOT STUCK DUE TO THE RUBBER THAT IS AROUND THE GAS PEDAL。
4 THERE IS A KNOCKING NOISE COMING FROM THE CATALYITC CONVERTER ,AND THE VEHICLE IS STALLING. ALSO, HAS PROBLEM WITH THE STEERING。
5 CONSUMER WAS MAKING A TURN ,DRIVING AT APPROX 5- 10 MPH WHEN CONSUMER HIT ANOTHER VEHICLE. UPON IMPACT, DUAL AIRBAGS DID NOT DEPLOY . ALL DAMAGE WAS DONE FROM ENGINE TO TRANSMISSION,TO THE FRONT OF VEHICLE, AND THE VEHICLE CONSIDERED A TOTAL LOSS。
6 WHEEL BEARING AND HUBS CRACKED, CAUSING THE METAL TO GRIND WHEN MAKING A RIGHT TURN. ALSO WHEN APPLYING THE BRAKES, PEDAL GOES TO THE FLOOR, CAUSE UNKNOWN. WAS ADVISED BY MIDAS NOT TO DRIVE VEHICLE- WHEELE COULD COME OFF。
7 DRIVING ABOUT 5-10 MPH, THE VEHICLE HAD A LOW FRONTAL IMPACT IN WHICH THE OTHER VEHICLE HAD NO DAMAGES. UPON IMPACT, DRIVER'S AND THE PASSENGER'S AIR BAGS DID NOT DEPLOY, RESULTING IN INJURIES. PLEASE PROVIDE FURTHER INFORMATION AND VIN#。
8 THE AIR BAG WARNING LIGHT HAS COME ON. INDICATING AIRBAGS ARE INOPERATIVE.THEY WERE FIXED ONE AT THE TIME, BUT PROBLEM HAS REOCCURRED。
9 CONSUMER WAS DRIVING WEST WHEN THE OTHER CAR WAS GOING EAST. THE OTHER CAR TURNED IN FRONT OF CONSUMER'S VEHICLE, CONSUMER HIT OTHER VEHICLE AND STARTED TO SPIN AROUND ,COULDN'T STOP, RESULTING IN A CRASH. UPON IMPACT, AIRBAGS DIDN'T DEPLOY。
10 WHILE DRIVING ABOUT 65 MPH AND THE TRANSMISISON MADE A STRANGE NOISE, AND THE LEFT FRONT AXLE LOCKED UP. THE DEALER HAS REPAIRED THE VEHICLE。

SQL呼び出し

complaints_tokens_testを作成する、TextTokenizerへの呼び出し:

CREATE MULTISET TABLE complaints_tokens_test AS (
  SELECT doc_id, lower(cast(token AS VARCHAR(1024))) AS token
    FROM TextTokenizer (
      ON complaints_test AS input PARTITION BY ANY
      USING
      TextColumn ('text_data')
      OutputByWord ('true')
      Accumulate ('doc_id')
    ) AS dt
) WITH DATA;
NaiveBayesTextClassifierPredictへの呼び出し:
SELECT * FROM NaiveBayesTextClassifierPredict (
  ON complaints_tokens_test AS PredictorValues PARTITION BY doc_id
  ON complaints_tokens_model AS Model DIMENSION
  USING
  InputTokenColumn ('token')
  ModelType ('Bernoulli')
  DocIDColumns ('doc_id')
  TopK ('1')
) AS dt ORDER BY doc_id;

出力

doc_id prediction loglik
1 no_crash -98.5428474553942
2 no_crash -93.588731591964
3 no_crash -74.6281619901653
4 no_crash -80.2178104775681
5 crash -115.803709744721
6 no_crash -116.281532818164
7 crash -111.174594434561
8 no_crash -92.1427644980375
9 no_crash -109.322164262443
10 no_crash -82.820437621875