54 lines
2.2 KiB
Python
54 lines
2.2 KiB
Python
# 13_pm-case-clusters.py
|
|
#
|
|
# content: (1) Load data and create event log
|
|
# (2) Evaluation for clusters
|
|
#
|
|
# input: ../results/eventlogs_2019_case-clusters.csv
|
|
# output: ../results/eval_case_clusters_<threshold>.csv
|
|
#
|
|
# last mod: 2024-04-17
|
|
|
|
import pm4py
|
|
import pandas as pd
|
|
|
|
from python_helpers import eval_pm, eval_append
|
|
|
|
#--------------- (1) Load data and create event logs ---------------
|
|
|
|
dat = pd.read_csv("../results/eventlogs_2019_case-clusters.csv", sep = ";")
|
|
|
|
event_log = pm4py.format_dataframe(dat,
|
|
case_id = "case",
|
|
activity_key = "item",
|
|
timestamp_key = "date.start")
|
|
|
|
#--------------- (2) Evaluation for clusters ---------------
|
|
|
|
thresholds = [0.1, 0.2, 0.3, 0.4]
|
|
|
|
for nt in thresholds:
|
|
|
|
net, im, fm = pm4py.discover_petri_net_inductive(event_log, noise_threshold = nt)
|
|
|
|
eval = eval_append(event_log, net, im, fm)
|
|
|
|
# Export process maps
|
|
# pm4py.save_vis_petri_net(net, im, fm, "results/processmaps/petrinet_complete_cases" + str(int(nt*10)).zfill(2) + ".png")
|
|
# bpmn = pm4py.convert.convert_to_bpmn(net, im, fm)
|
|
# pm4py.vis.save_vis_bpmn(bpmn, "results/processmaps/bpmn_complete_cases" + str(int(nt*10)).zfill(2) + ".png")
|
|
|
|
# Merge clusters into data frame
|
|
for cluster in [1, 2, 3, 4, 5]:
|
|
log_clst = pm4py.filter_event_attribute_values(event_log, "cluster", [cluster])
|
|
net_clst, im_clst, fm_clst = pm4py.discover_petri_net_inductive(log_clst, noise_threshold = nt)
|
|
eval_clst = eval_append(log_clst, net_clst, im_clst, fm_clst)
|
|
eval = pd.concat([eval, eval_clst])
|
|
# Export process maps
|
|
# pm4py.save_vis_petri_net(net_clst, im_clst, fm_clst, "results/processmaps/petrinet_cluster" + str(cluster) + "_cases" + str(int(nt*10)).zfill(2) + ".png")
|
|
# bpmn = pm4py.convert.convert_to_bpmn(net_clst, im_clst, fm_clst)
|
|
# pm4py.vis.save_vis_bpmn(bpmn, "results/processmaps/bpmn_cluster" + str(cluster) + "_cases" + str(int(nt*10)).zfill(2) + ".png")
|
|
|
|
eval.index = ["Complete", "Cluster 1", "Cluster 2", "Cluster 3", "Cluster 4", "Cluster 5"]
|
|
eval.to_csv("../results/eval_case_clusters_" + str(int(nt*10)).zfill(2) + ".csv", sep = ";")
|
|
|