pm4py / pm4py-core

Public repository for the PM4Py (Process Mining for Python) project.
https://pm4py.fit.fraunhofer.de
GNU Affero General Public License v3.0
742 stars 286 forks source link

KeyError: 'concept:name' #173

Closed ritwikraj1 closed 4 years ago

ritwikraj1 commented 4 years ago

I am trying to run a discovery algorithm with the data I have. I wrote the following simple code:

import pandas as pd
from pm4py.objects.log.util import dataframe_utils
from pm4py.objects.conversion.log import converter as log_converter
from pm4py.algo.discovery.alpha import algorithm as alpha_miner
from pm4py.algo.discovery.inductive import algorithm as inductive_miner

log_csv = pd.read_csv('case_history.csv', sep=',')
log_csv = log_csv.drop(log_csv.columns[[0, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 14]], axis=1)
log_csv.columns = ['case', 'activity', 'timestamp']
log_csv = dataframe_utils.convert_timestamp_columns_in_df(log_csv)
log_csv = log_csv.sort_values('timestamp')

parameters = {log_converter.Variants.TO_EVENT_LOG.value.Parameters.CASE_ID_KEY: 'case'}

event_log = log_converter.apply(log_csv, parameters=parameters, variant=log_converter.Variants.TO_EVENT_LOG)

print(event_log)

net, initial_marking, final_marking = alpha_miner.apply(event_log)

However, I am getting this error:

Traceback (most recent call last):
  File "processmining.py", line 19, in <module>
    net, initial_marking, final_marking = alpha_miner.apply(event_log)
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\algo\discovery\alpha\algorithm.py", line 60, in apply
    return exec_utils.get_variant(variant).apply(log_conversion.apply(log, parameters, log_conversion.TO_EVENT_LOG), parameters)
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\algo\discovery\alpha\versions\classic.py", line 63, in apply
    dfg = {k: v for k, v in dfg_inst.apply(log, parameters=parameters).items() if v > 0}
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\algo\discovery\dfg\versions\native.py", line 21, in apply
    return log_calc.native(log, parameters=parameters)
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\objects\dfg\retrieval\log.py", line 65, in native
    return Counter([dfg for lista in dfgs for dfg in lista])
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\objects\dfg\retrieval\log.py", line 65, in <listcomp>
    return Counter([dfg for lista in dfgs for dfg in lista])
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\objects\dfg\retrieval\log.py", line 64, in <lambda>
    dfgs = map((lambda t: [(t[i - window][activity_key], t[i][activity_key]) for i in range(window, len(t))]), log)
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\objects\dfg\retrieval\log.py", line 64, in <listcomp>
    dfgs = map((lambda t: [(t[i - window][activity_key], t[i][activity_key]) for i in range(window, len(t))]), log)
  File "C:\Users\ritwi\AppData\Local\Programs\Python\Python38\lib\site-packages\pm4py\objects\log\log.py", line 10, in __getitem__
    return self._dict[key]
KeyError: 'concept:name'

Could you please help me with this error? Thank you in advance.

fit-alessandro-berti commented 4 years ago

Dear ritwikraj1,

You would need to pass the activity as parameter of the alpha miner.

You can do in the following way:

parameters={alpha_miner.Variants.CLASSIC.value.Parameters.ACTIVITY_KEY: 'activity'} net, initial_marking, final_marking = alpha_miner.apply(event_log, parameters=parameters)