728x90

 이번 포스팅에서는 pm4py에서 휴리스틱 마이닝을 이용하여 프로세스 모델을 도출하는 방법에 대해 알아보겠다. 휴리스틱 마이닝이 무엇인지 모른다면 다음 포스팅을 참고하자.

2019/07/28 - [Theory/Process Discovery] - Heuristic Mining이란?

 

Heuristic Mining이란?

Heuristic Mining 알고리즘은 dependency graph를 기반으로 하여 이에 다양한 threshold들을 적용시켜 프로세스 모델을 도출하는 process discovery 알고리즘이다. Heuristic Mining은 알파 알고리즘과는 다르게..

process-mining.tistory.com

 *본 포스팅은 기본적인 python 문법을 알고 있다는 가정 하에 진행된다.

Heuristic Miner 적용하기

1. 우선, xes 파일을 import하여 이를 log에 저장해 준다.

import os
from pm4py.objects.log.importer.xes import factory as xes_importer


log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes")) #괄호 안에 원하는 파일의 경로를 쓴다.

2. 이 log에 대해 휴리스틱 마이너를 적용시켜 준다.

from pm4py.algo.discovery.heuristics import factory as heuristics_miner
heu_net = heuristics_miner.apply_heu(log)

이 때, 휴리스틱 마이너에 대해 휴리스틱 마이닝에 쓰이는 다양한 threshold들을 적용시키고 싶을 수 있다. PM4Py에서 지원하는 threshold의 종류는 다음과 같다. 

 

  • dependency_thresh: dependency threshold. 자세한 설명은 위 heuristic mining 포스팅을 참고한다.
  • and_measure_thresh: AND threshold. 자세한 설명은 위 heuristic mining 포스팅을 참고한다.
  • min_act_count: 액티비티가 일어난 횟수가 해당 threshold 이상인 것만 보여준다.
  • min_dfg_occurrences: Positive Observations threshold. 자세한 설명은 위 heuristic mining 포스팅을 참고한다.
  • dfg_pre_cleaning_noise_thresh: DFG의 noise threshold. 해당 Directly follows 관계의 빈도가 선행 액티비티 혹은 후행 액티비티의 incoming/outgoing edge 개수 중 최댓값 * threshold 값 중 최댓값보다 작은 것만 보여준다.

 

위 threshold를 적용시키고 싶다면 다음과 같이 apply_heu 안에 딕셔너리 형태로 parameters 인수를 설정해주면 된다. 설정하지 않으면 각 threshold의 default 값으로 휴리스틱 넷이 도출된다.

from pm4py.algo.discovery.heuristics import factory as heuristics_miner
heu_net = heuristics_miner.apply_heu(log, parameters={"dependency_thresh": 0.6, "min_act_count" : 2})

3. 이를 눈으로 확인하기 위해 (visualization) 다음 코드를 입력한다.

from pm4py.visualization.heuristics_net import factory as hn_vis_factory
gviz = hn_vis_factory.apply(heu_net)
hn_vis_factory.view(gviz)

*이 코드를 한 번에 입력하고 싶으면 다음 코드를 입력하면 된다. (순서대로 붙여넣기 해도 되지만, 보기 좋게 바꾸어 놓았다.)

import os
from pm4py.objects.log.importer.xes import factory as xes_importer
from pm4py.algo.discovery.heuristics import factory as heuristics_miner
from pm4py.visualization.heuristics_net import factory as hn_vis_factory

log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes")) #괄호 안에 원하는 파일의 경로를 쓴다.

heu_net = heuristics_miner.apply_heu(log, parameters={"dependency_thresh": 0.6, "min_act_count" : 2})

gviz = hn_vis_factory.apply(heu_net)
hn_vis_factory.view(gviz)

4. 다음과 같은 맵이 도출된다면 성공이다.

 이 때, 도출된 맵의 arc 위의 숫자는 해당 sequence의 빈도, 네모 안의 숫자는 해당 액티비티의 빈도를 말한다.

도출된 herusitic net

휴리스틱 마이너로 페트리 넷 도출하기

 휴리스틱 마이너로 도출된 휴리스틱 넷으로부터 페트리 넷을 도출하여 이를 보고 싶을 수도 있다. 그럴 때는 다음과 같이 하면 된다.

 

1. 휴리스틱 마이너를 이용하여 페트리 넷을 도출한다.

import os
from pm4py.objects.log.importer.xes import factory as xes_importer
from pm4py.algo.discovery.heuristics import factory as heuristics_miner

log = xes_importer.import_log(os.path.join("tests","input_data","running-example.xes")) #괄호 안에 원하는 파일의 경로를 쓴다.

net, im, fm = heuristics_miner.apply(log, parameters={"dependency_thresh": 0.6, "min_act_count" : 2}) #이 부분의 코드가 살짝 다르다.

2. 이를 페트리 넷으로 visualization 한다.

from pm4py.visualization.petrinet import factory as pn_vis_factory
gviz = pn_vis_factory.apply(net, im, fm)
pn_vis_factory.view(gviz)

3. 다음과 같은 맵이 도출된다면 성공이다.

휴리스틱 마이너로 도출된 페트리 넷

 이번 포스팅에서는 PM4py로 휴리스틱 넷을 도출하는 방법과 함께 휴리스틱 마이너로 페트리 넷을 도출하는 방법에 대해 알아보았다. PM4py를 이용해 코드 몇 줄로 간단하게 event log로부터 휴리스틱 넷을 도출할 수 있다.

300x250
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기