IBM Process Mining メモ - (3) CSVの取り込みとモデル

# はじめに
IBM Process Miningを実際に使ってみた時のログを記載していきます。

IBM Process Miningの使用例については以下にハンズオンのガイドが公開されています(英語版ですが)。
参考: [GitHub - IBM/cp4ba-labs/21.0.3/Process Mining/](https://github.com/IBM/cp4ba-labs/tree/main/21.0.3/Process%20Mining)
こちらを参考に実際に動かしてみたいと思います。

今回はCSVの取り込みと生成される"モデル"あたりを中心に見ていきます。

## 関連記事

[IBM Process Mining メモ - (1) 概要](https://qiita.com/tomotagwork/items/bf187d6cd8346cb1a86b)
[IBM Process Mining メモ - (2) RHEL8へのインストール](https://qiita.com/tomotagwork/items/bea465ddc195cf06fbf7)
[IBM Process Mining メモ - (3) CSVの取り込みとモデル](https://qiita.com/tomotagwork/items/73cccfc58f5a8836683f)
[IBM Process Mining メモ - (4) BPMN](https://qiita.com/tomotagwork/items/ba07959e49afd95e24e8)
[IBM Process Mining メモ - (5) BAWの情報の取り込み](https://qiita.com/tomotagwork/items/90ca2ac6d100e4c26786)


# CSV取り込みから可視化までの操作の流れ

IBM Process Miningを試すために、サンプルとなる入力データが以下に用意されていますのでローカルにダウンロードしておきます。
[Hands_On_tutorial_exercise.zip](https://ibm.ent.box.com/v/PM-LAB-1-DATASET)
zipファイルで提供されていますが、その中身はinvenio_tutorial_100hands_on_exercise.csvというCSVファイルが1つだけ含まれています。

このサンプルデータを使って、データを取り込んでから可視化までの基本的な流れを見ていきます。

## プロセスの作成

まず、データを分析する単位として"プロセス"というものを作成します。CSVデータや分析結果を保持するガラみたいなものです。

ブラウザからProcess Miningの管理画面に接続し、"プロセスの作成"をクリック
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/1c37468d-4d2d-dcac-79dc-80f960283e53.png)

名前を付けて"プロセスの作成"をクリック。ここでは"My Order Processing"というプロセスを作成します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/c50ce71f-2dbf-e0b3-48de-76937d71afd7.png)

## CSVファイルのアップロード

作成された"My Order Processing"をクリック。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/9a8b2039-e166-a4e5-5999-cd9815434ac7.png)

"データ・ソース・ファイルの選択"をクリック
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/d32a689b-3e29-47c5-1081-aa99e38811b1.png)

ダウンロードしておいたサンプルのCSVが含まれるzipを選択します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/fdcf0949-ce15-81d7-ef27-ca3b6c230863.png)

アップロードをクリック
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/938cbcfb-3c4b-a2db-7655-31f080652876.png)

サンプルのCSVファイルが取り込まれました。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/ac7469ae-9660-b5c9-c925-75516b2d2dab.png)

## 列のマッピング

ここで、取り込んだCSVのどの列を何のデータとして扱うか、というマッピングを行います。
取り込んだCSVファイル中のReq_Line_IDという列は1つめのプロセスIDとして認識させたいので、Req_Line_IDを選択して、"プロセスID"をクリックします。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/fd0557de-09ab-d1c1-c048-2e84fa0d3b30.png)

Req_Line_ID列がプロセスID(1つめ)として認識されたことを示すアイコンが列名の横に表示されます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/ddd2a03c-4fe5-0009-4539-088c05299c6d.png)

同様に、Order_Line_ID列、 Goods_ID列,、Invoice_ID列 をそれぞれ2,3,4番目のプロセスIDとして設定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/35b89a08-f3b1-fccd-be8b-801a77e5fd0c.png)

DateTime列を開始時刻として設定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/4b915af1-1d4e-3fed-5af5-8f283e6f6a39.png)
(時刻のフォーマットはある程度自動で認識してましたが、表記のパターンを明示指定できるようです。)

Resource列をリソースとして設定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/866753af-09b1-56da-0a6f-ef57c784bb15.png)

Role列をロールとして設定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/626d1f18-445e-9f26-eb7f-03ed4f594b86.png)

Requisition_Vendor列をカスタム・フィールドとして設定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/1d1d1439-5cd4-77c3-a59f-c2d0282e4faa.png)

Requisition_Type, Requisition_Header, UserTypeも同様にカスタム・フィールドとして設定します。

## 可視化

マッピングが完了したら、"プロセスの視覚化"をクリックします。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/3a35298a-f831-2887-3540-3a247efe2d88.png)

取り込んだCSVと列のマッピング情報を元に処理が行われます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/ad8eb2e4-d89c-f70f-044e-c84696d7fb45.png)

処理が完了すると"モデル"タブが開いてアクティビティーのフローが図として表示されます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/aab6e107-5bc8-c437-a2fc-e8adb72ae586.png)

これで様々な情報が分析できるようになります。

この"モデル"タブので可視化される情報について少しみてみると...
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/fa7d2a4b-757e-84ac-b6e2-6b1b4eb17f8e.png)
この図の四角はアクティビティー、矢印はアクティビティー間の遷移を表しますが、数字も一緒に表示されています。デフォルトだと"頻度"という軸で分析された結果が表示されており、各数字はそのアクティビティーが実行された数や遷移が生じた数が図中に表示されています。


また、フローで表されているアクティビティーや遷移を表す矢印は全てのケースを網羅している訳ではありません。複雑なフローになる場合図がビジーになりすぎて意味が分からなくなってしまうので、頻度の高いアクティビティー/遷移のみ表示するようになっています。表示レベルは左側のメニューの"モデルの詳細"から変更できます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/6eb764a7-b0df-c703-832d-7c9fa69506e7.png)
上の例はアクティビティー:30%, 関係(遷移):1%のみ表示させている状態です。

ちなみに両方100%表示にすると遷移のパターンが多すぎて視覚的に逆に分かりにくい図になってしまいます。こんな感じ...
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/5452352c-ba09-f0d2-e9c8-7ca33a01fa54.png)



# 入力データと生成される"モデル"の関係

CSVデータを取り込んで可視化/分析ができそうなことはなんとなくわかりました。ブラウザからGUIベースで操作して様々な情報を分析できるので、なんとなく分かったような気になるのですが、細かい所でどういうデータを与えるとそれがどのようにProcess Mining上に現れてくるのか、というあたりをもう少し掘り下げたいと思います。
特にProcess Miningに食わせるデータの形式としてどのようなCSVを組み立ててあげないといけないか、という辺りは肝になりそうです。

※この辺りのETL操作についてはProcess Miningの範疇ではないので、別途ツール使うなりスクリプト組むなりしてデータをこねくり回してProcess Miningの入力として適切なデータを組み立てられるようにしなければなりません。どういうやり方がよいかは元になるデータの形式などにも依存するでしょう...

## サンプルのCSVデータ構造を見てみる

サンプルで使われているデータは、プロセスマイニングの世界ではよく引き合いに出されるP2P(Procure to Pay) Process のシナリオを元にしています。
先に列のマッピングをする際にプロセスIDを4つ指定していましたが、これによりMulti Level Process Miningという分析方法を用いることになります。

以下のドキュメントの"Best practices to generate and map a datasource for Multilevel Process Mining analysis" という項目にMulti Level Process Miningでのデータのイメージが記載されています。
https://www.ibm.com/docs/en/cloud-paks/1.0?topic=started-datasource
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/082dfb70-b987-8511-ac57-75473db22e18.png)

このP2Pプロセスは、基本的には4つのプロセス(Requisision, Order, Recipt, Invoice)が連なって1つの一連の処理が行われるイメージになっています。それぞれのプロセスごとにIDが振られていて、それぞれ別の列に記載されています。
"Bridge Activity"というアクティビティーを決めて、そのアクティビティーを元に各プロセスID間の関連付けを行います。"Bridge Activity"の行についてだけ2つのProcessIDの列に値をセットすることで両者の関連付けが行われます。上の表の例だとRequisition:"PR0010"からOrder:"PO0010"が派生することになりますが、ヘッダーを除いた1行目のActivity:"Order creation"をBridge ActivityとしてRequisitionIDとOrderIDの関連付けが行われます。
同様に、Activity:"Goods receipt"によりOrderID-ReceiptIDの関連付け、Activity:"Invoice registration"によりReceiptID-InvoiceIDの関連付けが行われることになります。


## シンプルケース1
どのようなデータを与えるとどのような可視化が行われるのかをもう少し明確に把握するため、データ数を極端に絞って投入した場合にどのような表示になるかを見てみます。

上のサンプルデータから、特定のReq_Line_ID "0010232220_10" に紐づくアクティビティーのみ抽出してみました。このフローでは1つの取引 "Req_Line_ID=0010232220_10"に関連するアクティビティーのみ抽出してみました。このRequisitionからは5つのOrderが派生しています。具体的なデータは以下の通りです。

<details><summary><font color="blue">test01.csv</font></summary><div>

```csv:test01.csv
"Req_Line_ID","Order_Line_ID","Goods_ID","Invoice_ID","Activity","DateTime","Resource","Role","Requisition_Vendor","Order_Vendor","Invoice_Vendor","Pay_Vendor","Requisition_Type","Order_Type","Purchasing_Group","Purchasing_Organization","Material_Group","Material_Number","Plant","Good_ReferenceNumber","Requisition_Header","Order_Header","Invoice_Header","ClearDoc_Header","Good_Year","Invoice_Year","Order_Line_Amount","Invoice_Amount","Paid_Amount","Invoice_Document_Date","Invoice_Due_Date","Pay_Type","Pay_Delay","UserType","Invoice_Is_Overdue"
"0010232220_10","","","","Requisition Line Created","2018-06-18 00:00:00","USRBR00026","Procurement","VND01430","","","","Direct","","","","","","","",10232220,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010232220_10","","","","Requisition Line Approved","2018-06-20 13:34:14","USR00470","Req Approver","VND01430","","","","Direct","","","","","","","",10232220,NA,NA,NA,NA,NA,0,0,0,"","","",0,"",""
"0010232220_10","4500238358_10","","","Order Line Created","2018-06-25 15:10:20","USR00222","Secretary","VND01430","VND04337","","","Direct","Standard Order","ID1","IT10","D008-DPI","0108000225","","",10232220,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"0010232220_10","4500238358_20","","","Order Line Created","2018-06-25 15:10:20","USR00222","Secretary","VND01430","VND04337","","","Direct","Standard Order","ID1","IT10","D008-DPI","0108000225","","",10232220,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"0010232220_10","4500238358_40","","","Order Line Created","2018-06-25 15:10:20","USR00222","Secretary","VND01430","VND04337","","","Direct","Standard Order","ID1","IT10","D008-DPI","0108000225","","",10232220,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"0010232220_10","4500238358_50","","","Order Line Created","2018-06-25 15:10:20","USR00222","Secretary","VND01430","VND04337","","","Direct","Standard Order","ID1","IT10","D008-DPI","0108000225","","",10232220,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"0010232220_10","4500238358_30","","","Order Line Created","2018-06-25 15:10:20","USR00222","Secretary","VND01430","VND04337","","","Direct","Standard Order","ID1","IT10","D008-DPI","0108000225","","",10232220,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Released","2018-06-25 15:11:55","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_20","","","Order Released","2018-06-25 15:11:55","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_40","","","Order Released","2018-06-25 15:11:55","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_50","","","Order Released","2018-06-25 15:11:55","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_30","","","Order Released","2018-06-25 15:11:55","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Approved","2018-06-25 17:48:35","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_20","","","Order Approved","2018-06-25 17:48:35","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_40","","","Order Approved","2018-06-25 17:48:35","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_50","","","Order Approved","2018-06-25 17:48:35","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_30","","","Order Approved","2018-06-25 17:48:35","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Changed: Item Quantity","2018-07-03 15:16:23","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Changed: Delivery Date","2018-07-03 15:16:23","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Changed: Delivery Date","2018-10-05 16:50:25","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_20","","","Order Changed: Delivery Date","2018-10-05 16:50:25","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_30","","","Order Changed: Delivery Date","2018-10-05 16:50:25","USR00222","Secretary","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","","","Order Printed Out","2018-06-26 09:13:25","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_20","","","Order Printed Out","2018-06-26 09:13:25","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_40","","","Order Printed Out","2018-06-26 09:13:25","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_50","","","Order Printed Out","2018-06-26 09:13:25","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_30","","","Order Printed Out","2018-06-26 09:13:25","DST112","Procurement","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","","",NA,4500238358,NA,NA,NA,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_10","5000902924_1_2018","","Goods Line Registered","2018-10-15 14:33:58","MAGA06","Warehouse","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","IT01","10116378",NA,4500238358,NA,NA,2018,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_20","5000903763_1_2018","","Goods Line Registered","2018-10-16 12:08:38","MAGA06","Warehouse","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","IT01","10116418",NA,4500238358,NA,NA,2018,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_30","5000907026_1_2018","","Goods Line Registered","2018-10-22 11:45:29","MAGA06","Warehouse","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","IT01","10116504",NA,4500238358,NA,NA,2018,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_40","5000915897_1_2018","","Goods Line Registered","2018-11-05 14:35:07","MAGA06","Warehouse","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","IT01","10116624",NA,4500238358,NA,NA,2018,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","4500238358_50","5000917992_1_2018","","Goods Line Registered","2018-11-07 17:31:30","MAGA06","Warehouse","","VND04337","","","","Standard Order","ID1","IT10","D008-DPI","0108000225","IT01","10116628",NA,4500238358,NA,NA,2018,NA,86958.0097,0,0,"","","",0,"HUMAN",""
"","","5000902924_1_2018","3018004172_2018_IT10","Invoice Registered","2018-10-19 10:08:52","DAM2A04","Administration ","","","VND04336","","","","","","","","IT01","12115639",NA,NA,3018004172,NA,2018,2018,0,87344.33,0,"2018-10-11","2018-11-30","Early",-2,"HUMAN",""
"","","5000903763_1_2018","3018004173_2018_IT10","Invoice Registered","2018-10-19 10:09:52","DAM2A04","Administration ","","","VND04336","","","","","","","","IT01","12115654",NA,NA,3018004173,NA,2018,2018,0,87194.83,0,"2018-10-12","2018-11-30","Early",-2,"HUMAN",""
"","","5000907026_1_2018","3018004570_2018_IT10","Invoice Registered","2018-11-13 10:15:28","USR02166","Administration ","","","VND04336","","","","","","","","IT01","12115733(02)",NA,NA,3018004570,NA,2018,2018,0,81601.45,0,"2018-10-19","2018-11-30","Early",-2,"HUMAN",""
"","","5000915897_1_2018","3018004605_2018_IT10","Invoice Registered","2018-11-14 08:50:24","DAM2A04","Administration ","","","VND04336","","","","","","","","IT01","12115837",NA,NA,3018004605,NA,2018,2018,0,86067.43,0,"2018-10-29","2018-11-30","Early",-2,"HUMAN",""
"","","5000917992_1_2018","3018004596_2018_IT10","Invoice Registered","2018-11-14 08:36:09","DAM2A04","Administration ","","","VND04336","","","","","","","","IT01","12115881",NA,NA,3018004596,NA,2018,2018,0,85985.11,0,"2018-10-31","2018-11-30","Early",-2,"HUMAN",""
"","","","3018004172_2018_IT10","Invoice Changed: Due date","2018-10-19 10:10:20","DAM2A04","Administration ","","","VND04336","","","","","","","","","",NA,NA,3018004172,NA,NA,2018,0,87344.33,0,"","2018-11-30","Early",-2,"HUMAN",""
"","","","3018004172_2018_IT10","Invoice Cleared","2018-11-28 10:08:52","","Procurement","","","VND04336","VND04336","","","","","","","","",NA,NA,3018004172,6018086743,NA,2018,0,87344.33,87344.33,"","2018-11-30","Early",-2,"","no"
"","","","3018004173_2018_IT10","Invoice Cleared","2018-11-28 10:09:52","","Procurement","","","VND04336","VND04336","","","","","","","","",NA,NA,3018004173,6018086743,NA,2018,0,87194.83,87194.83,"","2018-11-30","Early",-2,"","no"
"","","","3018004570_2018_IT10","Invoice Cleared","2018-11-28 10:15:28","","Procurement","","","VND04336","VND04336","","","","","","","","",NA,NA,3018004570,6018086743,NA,2018,0,81601.45,81601.45,"","2018-11-30","Early",-2,"","no"
"","","","3018004596_2018_IT10","Invoice Cleared","2018-11-28 08:36:09","","Procurement","","","VND04336","VND04336","","","","","","","","",NA,NA,3018004596,6018086743,NA,2018,0,85985.11,85985.11,"","2018-11-30","Early",-2,"","no"
"","","","3018004605_2018_IT10","Invoice Cleared","2018-11-28 08:50:24","","Procurement","","","VND04336","VND04336","","","","","","","","",NA,NA,3018004605,6018086743,NA,2018,0,86067.43,86067.43,"","2018-11-30","Early",-2,"","no"
```


</div></details>

着目点
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/790f09c2-07e9-6dba-e607-daa8d96318f3.png)

これをIBM Process Miningに食わせるとこうなります。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/27f48e49-e48d-567a-75b1-25680b250686.png)

このシナリオは全体としては1つのトランザクションということになりますが、1つのReqIDから5つのOrderが派生しておりそれぞれGoods, Invoiceの処理が行われます。Start～Endまで5つのフローとしては5ケースあると判断されています。入力データのアクティビティー数(ヘッダー除いた行数)は43で、それがそのまま43イベントとして判断されています。

シンプルなテストデータにしたので、"モデル"で表される図中に表示されている数値と元データの関係が分かりやすいですね。

## シンプルケース2

次に、GoodsIDからInvoiceIDが複数派生しているデータを追加してみます。
以下、"Req_Line_ID=0010148572_10"に関連するアクティビティーです。1つのGoodsIDから3つの異なるInvoiceIDが派生しています。

<details><summary><font color="blue">test02.csv</font></summary><div>

```test02.csv
"Req_Line_ID","Order_Line_ID","Goods_ID","Invoice_ID","Activity","DateTime","Resource","Role","Requisition_Vendor","Order_Vendor","Invoice_Vendor","Pay_Vendor","Requisition_Type","Order_Type","Purchasing_Group","Purchasing_Organization","Material_Group","Material_Number","Plant","Good_ReferenceNumber","Requisition_Header","Order_Header","Invoice_Header","ClearDoc_Header","Good_Year","Invoice_Year","Order_Line_Amount","Invoice_Amount","Paid_Amount","Invoice_Document_Date","Invoice_Due_Date","Pay_Type","Pay_Delay","UserType","Invoice_Is_Overdue"
"0010148572_10","","","","Requisition Line Created","2017-01-11 00:00:00","DST0B","Secretary","VND00321","","","","Indirect","","","","","","","",10148572,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010148572_10","","","","Requisition Line Approved","2017-01-11 17:16:19","DST56","Req Approver","VND00321","","","","Indirect","","","","","","","",10148572,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010148572_10","4500152822_10","","","Order Line Created","2017-01-17 16:18:03","USR01202","Procurement","VND00321","VND06066","","","Indirect","Standard Order","II8","IT11","S140-0091","S140009101","","",10148572,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","","","Order Approved","2017-01-17 16:18:55","USR01202","Procurement","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","","","Order Changed: Item Price","2017-01-17 16:18:50","USR01202","Procurement","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","","","Order Changed: Item Price","2017-01-18 14:23:17","USR01202","Procurement","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","","","Order Changed: Delivery Date","2017-01-17 16:18:50","USR01202","Procurement","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","","","Order Printed Out","2017-01-17 16:18:59","USR01202","Procurement","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500152822,NA,NA,NA,NA,446.4,0,0,"","","",0,"HUMAN",""
"","4500152822_10","5000534333_1_2017","","Goods Line Registered","2017-01-24 09:18:08","MAGB03","Warehouse","","VND06066","","","","Standard Order","II8","IT11","S140-0091","S140009101","IT01","1134",NA,4500152822,NA,NA,2017,NA,446.4,0,0,"","","",0,"HUMAN",""
"","","5000534333_1_2017","2017002082_2017_IT10","Invoice Registered","2017-02-01 16:01:56","CONS0120","Administration ","","","VND06066","","","","","","","","IT01","0001430",NA,NA,2017002082,NA,2017,2017,0,544.61,0,"2017-01-26","2017-03-31","Early",-57,"HUMAN",""
"","","5000534333_1_2017","2017002083_2017_IT10","Invoice Registered","2017-02-01 16:03:55","CONS0120","Administration ","","","VND06066","","","","","","","","IT01","0001430",NA,NA,2017002083,NA,2017,2017,0,-544.61,0,"2017-01-26","2017-03-31","Early",-57,"HUMAN",""
"","","5000534333_1_2017","2017002084_2017_IT10","Invoice Registered","2017-02-01 16:05:47","CONS0120","Administration ","","","VND06066","","","","","","","","IT01","0001101",NA,NA,2017002084,NA,2017,2017,0,544.61,0,"2017-01-23","2017-03-31","Early",-1,"HUMAN",""
"","","","2017002083_2017_IT10","Invoice Reversed","2017-02-01 16:03:55","CONS0120","Administration ","","","VND06066","","","","","","","","","",NA,NA,2017002083,NA,NA,2017,0,-544.61,0,"","2017-03-31","Early",-57,"HUMAN",""
"","","","2017002082_2017_IT10","Invoice Cleared","2017-02-01 16:01:56","","Procurement","","","VND06066","VND06066","","","","","","","","",NA,NA,2017002082,5417007390,NA,2017,0,544.61,544.61,"","2017-03-31","Early",-57,"","no"
"","","","2017002083_2017_IT10","Invoice Cleared","2017-02-01 16:03:55","","Procurement","","","VND06066","VND06066","","","","","","","","",NA,NA,2017002083,5417007390,NA,2017,0,-544.61,-544.61,"","2017-03-31","Early",-57,"","no"
"","","","2017002084_2017_IT10","Invoice Cleared","2017-03-30 16:05:47","","Procurement","","","VND06066","VND06066","","","","","","","","",NA,NA,2017002084,6017022723,NA,2017,0,544.61,544.61,"","2017-03-31","Early",-1,"","no"
```

</div></details>

着目点
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/1e3bd8ce-d7e0-565d-7e99-58f9439f96af.png)

これをシンプルケース1のデータに追加してIBM Process Miningに食わせるとこうなります。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/e3a61abf-989e-2374-3d0e-24308e4f26e3.png)

途中で3つの派生が生じているシナリオを追加したので合計8ケースと判断されています。フローのパターンも増えているので図が複雑になってきてますね。

## シンプルケース3

次に、複数のGoodsIDが1つのInvoiceIDに集約されているデータを追加してみます。
以下、"Req_Line_ID=0010156512_10"に関連するアクティビティーです。異なる2のGoodsIDはそれぞれ同一のInvoiceIDに紐づいています。

<details><summary><font color="blue">test03.csv</font></summary><div>

```test03.csv
"Req_Line_ID","Order_Line_ID","Goods_ID","Invoice_ID","Activity","DateTime","Resource","Role","Requisition_Vendor","Order_Vendor","Invoice_Vendor","Pay_Vendor","Requisition_Type","Order_Type","Purchasing_Group","Purchasing_Organization","Material_Group","Material_Number","Plant","Good_ReferenceNumber","Requisition_Header","Order_Header","Invoice_Header","ClearDoc_Header","Good_Year","Invoice_Year","Order_Line_Amount","Invoice_Amount","Paid_Amount","Invoice_Document_Date","Invoice_Due_Date","Pay_Type","Pay_Delay","UserType","Invoice_Is_Overdue"
"0010156512_10","","","","Requisition Line Created","2017-02-24 00:00:00","COQB67","Procurement","VND00964","","","","Direct","","","","","","","",10156512,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010156512_10","","","","Requisition Line Approved","2017-03-02 16:55:30","USR01465","Req Approver","VND00964","","","","Direct","","","","","","","",10156512,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010156512_10","4500161125_20","","","Order Line Created","2017-03-03 16:30:30","DST25","Procurement","VND00964","VND05254","","","Direct","Standard Order","ID9","IT10","D005-SFS","71782","","",10156512,4500161125,NA,NA,NA,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","4500161125_20","","","Order Released","2017-03-03 16:50:21","DST25","Procurement","","VND05254","","","","Standard Order","ID9","IT10","D005-SFS","71782","","",NA,4500161125,NA,NA,NA,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","4500161125_20","","","Order Approved","2017-03-03 18:48:32","DST112","Procurement","","VND05254","","","","Standard Order","ID9","IT10","D005-SFS","71782","","",NA,4500161125,NA,NA,NA,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","4500161125_20","","","Order Printed Out","2017-03-07 09:58:39","DST112","Procurement","","VND05254","","","","Standard Order","ID9","IT10","D005-SFS","71782","","",NA,4500161125,NA,NA,NA,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","4500161125_20","5000566734_1_2017","","Goods Line Registered","2017-03-24 09:48:59","COQB67","Procurement","","VND05254","","","","Standard Order","ID9","IT10","D005-SFS","71782","IT01","170194",NA,4500161125,NA,NA,2017,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","4500161125_20","5000566732_1_2017","","Goods Line Registered","2017-03-24 09:46:38","COQB67","Procurement","","VND05254","","","","Standard Order","ID9","IT10","D005-SFS","71782","IT01","170194",NA,4500161125,NA,NA,2017,NA,41617.8,0,0,"","","",0,"HUMAN",""
"","","5000566734_1_2017","0101700046_2017_IT10","Invoice Registered","2017-03-30 14:53:21","DAM2A04","Administration ","","","VND05254","","","","","","","","IT01","17FCL00290",NA,NA,101700046,NA,2017,2017,0,42891.39,0,"2017-03-22","2017-03-22","Late",43,"HUMAN",""
"","","5000566732_1_2017","0101700046_2017_IT10","Invoice Registered","2017-03-30 14:53:21","DAM2A04","Administration ","","","VND05254","","","","","","","","IT01","17FCL00290",NA,NA,101700046,NA,2017,2017,0,42891.39,0,"2017-03-22","2017-03-22","Late",43,"HUMAN",""
"","","","0101700046_2017_IT10","Invoice Cleared","2017-05-05 14:53:21","","Procurement","","","VND05254","VND05254","","","","","","","","",NA,NA,101700046,6017031983,NA,2017,0,42891.39,42891.39,"","2017-03-22","Late",43,"","yes"
```

</div></details>

着目点
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/9c73f6fd-3ffa-e169-db3f-d85dc446a46f.png)

このデータを先のシンプルケース1,2に追加してIBM Process Miningに食わせるとこうなります。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/3d7e6fb6-a975-2f22-049d-7499bfc75829.png)

途中でOrder⇒Goodsの所で2つに派生しているのですが、Goods⇒Invoiceでまた1つに集約されているので、このシナリオだと1ケースと判断されるようです(シンプルケース2と比べると、全体のケース数が8⇒9と1つしか増えていない)。
また、シンプルケース3として追加したデータの行数は11ですが、シンプルケース2の結果と比較すると全体のイベント数が10しか増加していません(59⇒69)。これは、シンプルケース3で追加したデータ中"Invoice Registered" アクティビティーについては2つのGoodsIDから1つのInvoiceIDにマッピングするために実質1つのアクティビティーを2行としてデータを準備しているためと思われます。IBM Process Miningではこの2行を1アクティビティーとしてカウントしているようです。

参考: [Datasource](https://www.ibm.com/docs/en/cloud-paks/1.0?topic=started-datasource)

>Generate one record of the bridge activity for every linked entityID (e.g. an InvoiceID is linked to 4 different ReceiptIDs → 4 Invoice registration activities have to be created; InvoiceID keeps the same value, while ReceiptID is always different).
>- If multiple records are generated for the same bridge activity, they must have the same timestamp.
>- Process Mining will recognize the bridge activity and will manage it accordingly with frequency 1, even if the record is repeated.


## シンプルケース4

続いて、Req_Line_IDが存在しないデータに着目してみます。
以下、"Order_Line_ID=4500150997_3"に関連するアクティビティーを抽出したものです。この"Order Line Created"のアクティビティーは、"Resource=BATCH_PDE", "Role=Job System", "UserType=ROBOT" となっているのでバッチによる自動化の仕組みにより生成されたものと思われます。

<details><summary><font color="blue">test04.csv</font></summary><div>

```test04.csv
"Req_Line_ID","Order_Line_ID","Goods_ID","Invoice_ID","Activity","DateTime","Resource","Role","Requisition_Vendor","Order_Vendor","Invoice_Vendor","Pay_Vendor","Requisition_Type","Order_Type","Purchasing_Group","Purchasing_Organization","Material_Group","Material_Number","Plant","Good_ReferenceNumber","Requisition_Header","Order_Header","Invoice_Header","ClearDoc_Header","Good_Year","Invoice_Year","Order_Line_Amount","Invoice_Amount","Paid_Amount","Invoice_Document_Date","Invoice_Due_Date","Pay_Type","Pay_Delay","UserType","Invoice_Is_Overdue"
"","4500150997_3","","","Order Line Created","2017-01-03 16:15:07","BATCH_P0E","Job System","","VND05408","","","","E-Procurement","II3","IT11","S140-0141","S140014101","","",NA,4500150997,NA,NA,NA,NA,82.39,0,0,"","","",0,"ROBOT",""
"","4500150997_3","5000528635_1_2017","","Goods Line Registered","2017-01-10 09:56:01","TFM19","Warehouse","","VND05408","","","","E-Procurement","II3","IT11","S140-0141","S140014101","IT02","1388",NA,4500150997,NA,NA,2017,NA,82.39,0,0,"","","",0,"HUMAN",""
"","","5000528635_1_2017","2017009309_2017_IT10","Invoice Registered","2017-05-04 10:41:48","CONS0120","Administration ","","","VND05232","","","","","","","","IT02","V2/505172",NA,NA,2017009309,NA,2017,2017,0,29684.84,0,"2017-01-31","2017-04-30","Late",12,"HUMAN",""
"","","","2017009309_2017_IT10","Invoice Cleared","2017-05-12 10:41:48","","Procurement","","","VND05232","VND05232","","","","","","","","",NA,NA,2017009309,6017034491,NA,2017,0,29684.84,29684.84,"","2017-04-30","Late",12,"","yes"
```

</div></details>

着目点
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/17faa9ed-d4c2-70be-d565-6782a0c0d873.png)

このデータを先のシンプルケース1,2,3に追加してIBM Process Miningに食わせるとこうなります。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/de95e498-e91d-fb1f-c2a9-66f32fcd775a.png)

StartからOrder Line Created直接遷移する矢印が増えました。


## シンプルケース5

Invoice_IDが無いデータについても着目してみます。ただ、サンプルデータからはみつけられなかったので "Req_Line_ID=0010147361_10"(オーソドックスなフローのもの) からInvoice関連のActivityを削除した以下のようなデータを用意しました。

<details><summary><font color="blue">test05.csv</font></summary><div>

```test05.csv
"Req_Line_ID","Order_Line_ID","Goods_ID","Invoice_ID","Activity","DateTime","Resource","Role","Requisition_Vendor","Order_Vendor","Invoice_Vendor","Pay_Vendor","Requisition_Type","Order_Type","Purchasing_Group","Purchasing_Organization","Material_Group","Material_Number","Plant","Good_ReferenceNumber","Requisition_Header","Order_Header","Invoice_Header","ClearDoc_Header","Good_Year","Invoice_Year","Order_Line_Amount","Invoice_Amount","Paid_Amount","Invoice_Document_Date","Invoice_Due_Date","Pay_Type","Pay_Delay","UserType","Invoice_Is_Overdue"
"0010147361_10","","","","Requisition Line Created","2017-01-02 00:00:00","USR00376","Secretary","VND00510","","","","Indirect","","","","","","","",10147361,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010147361_10","","","","Requisition Line Approved","2017-01-02 10:29:14","PROB03","Procurement","VND00510","","","","Indirect","","","","","","","",10147361,NA,NA,NA,NA,NA,0,0,0,"","","",0,"HUMAN",""
"0010147361_10","4500150938_10","","","Order Line Created","2017-01-03 11:37:34","USR01202","Procurement","VND00510","VND06626","","","Indirect","Standard Order","II8","IT11","S140-0091","S140009101","","",10147361,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","","","Order Approved","2017-01-03 11:39:04","USR01202","Procurement","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","","","Order Changed: Purchasing Group","2017-01-03 11:38:58","USR01202","Procurement","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","","","Order Changed: Item Price","2017-01-03 14:04:09","USR01202","Procurement","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","","","Order Changed: Item Price","2017-01-03 11:38:58","USR01202","Procurement","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","","","Order Printed Out","2017-01-03 11:39:10","USR01202","Procurement","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","","",NA,4500150938,NA,NA,NA,NA,1588,0,0,"","","",0,"HUMAN",""
"","4500150938_10","5000529872_1_2017","","Goods Line Registered","2017-01-12 14:24:29","DST55","Warehouse","","VND06626","","","","Standard Order","II8","IT11","S140-0091","S140009101","IT01","810656531",NA,4500150938,NA,NA,2017,NA,1588,0,0,"","","",0,"HUMAN",""
```

</div></details>

着目点
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/d5a844cc-35d8-3b05-be19-a5f1775f4748.png)

このデータを先のシンプルケース1,2,3,4に追加してIBM Process Miningに食わせるとこうなります。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/57249d27-a1a8-f4fc-8add-6d815f505573.png)

Good Line RegisteredからEndへ直接遷移する矢印が増えました。

## まとめ
"モデル"タブの左側に表示されている各値は恐らくこんな感じで認識されていると思われます。

**ケース数**: Endに到達するフローの数を示している。
**イベント数**: データ中に含まれるアクティビティー数を示している(Bridge Activityとして複数同一行がある場合は1としてカウントされる)。
**ケース統計の各プロセスIDごとの数値**: 各プロセスIDの種類(ユニークなIDの数)を示している。


# 参照モデルとの比較

Process Miningでは、基準となる業務フローのモデルを"参照モデル"(Reference Model)として登録しておき、分析対象として与えたデータの業務フローが、その基準となる"参照モデル"からどのくらい類似しているか、あるいはギャップがあるかを比較分析することができます。
この機能を使う場合、比較対象とする"参照モデル"が必要になります。
ここでは、上で試したシンプルケース1で生成したモデルを"参照モデル"として登録し、シンプルケース1～5のデータを比較分析してみます。

## 参照モデルの作成

IBM Process Miningで生成したフローを標準形式でエクスポートすることができます。
シンプルケース1のデータを取り込んだプロセスの、BPMNタブを開きます。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/bf21c31b-d302-2697-ffc2-edb5cf6e872d.png)

ここでは入力データとして与えたCSVを元に生成したフローがBPMNのモデル図として表されます。

右上の上矢印のアイコンから"モデル"を選択します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/60eac438-647a-0fea-5419-16fbfa5bb1a0.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/b949f605-6487-257a-d690-b9ebcb72f764.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/14dd0927-0178-dea5-07f1-cad412285d73.png)

bpmnファイルとしてエクスポートできます。これを参照モデルとして使用します。

## 参照モデルの登録

シンプルケース1～5を含むデータを分析する際に、シンプルケース1を参照モデルとして登録します。
シンプルケース1～5のデータを取り込んだプロセスのデータ・ソースタブを開いて"参照モデル・ファイルの選択"をクリック。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/8d0345a9-14dc-571f-0551-a44d8e7bd6bd.png)

先にエクスポートしたbpmnファイルを指定します。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/0ea7d140-d387-edae-d188-11191d284e80.png)

アップロード
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/4fc0fbf8-4dac-9099-a9e1-d0e5af1523f5.png)


## 比較分析

参照モデルが登録されたので、シンプルケース1～5のデータを比較してみます。
"モデル"タブを開いて右側の目のようなアイコンをクリックします。すると、以下のように参照モデルから外れたActivityや遷移の矢印が赤で表示されます。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/132331/23ed5449-fade-0701-42c8-b6205267fa51.png)

これにより基準となるフローからどの部分がどのくらい逸脱しているかが把握しやすくなります。これを元にコストがかかる例外的なフローの判別やフローの見直しにつなげる、といったところで活用できそうです。