pm4py.algo.decision_mining.algorithm module#

class pm4py.algo.decision_mining.algorithm.Parameters(*values)[source]#

Bases: Enum

ACTIVITY_KEY = 'pm4py:param:activity_key'#
LABELS = 'labels'#
pm4py.algo.decision_mining.algorithm.create_data_petri_nets_with_decisions(log: EventLog | DataFrame, net: PetriNet, initial_marking: Marking, final_marking: Marking) Tuple[PetriNet, Marking, Marking][source]#

Given a Petri net, create a data Petri net with the decisions given for each place by the decision mining algorithm.

Parameters:
  • log – Event log (EventLog or DataFrame).

  • net – Petri net.

  • initial_marking – Initial marking of the Petri net.

  • final_marking – Final marking of the Petri net.

Returns:

  • data_petri_net – Petri net enriched with guards (conditions).

  • initial_marking – Initial marking (unchanged).

  • final_marking – Final marking (unchanged).

pm4py.algo.decision_mining.algorithm.get_decision_tree(log: EventLog | DataFrame, net: PetriNet, initial_marking: Marking, final_marking: Marking, decision_point=None, attributes=None, parameters: Dict[str | Parameters, Any] | None = None) Any[source]#

Gets a decision tree classifier on a specific point of the model.

Parameters:
  • log – Event log (EventLog or DataFrame).

  • net – Petri net.

  • initial_marking – Initial marking.

  • final_marking – Final marking.

  • decision_point – Name of the place in which a decision happens: - if not specified, the method raises an Exception with a list of possible decision points.

  • attributes – Attributes of the log. If not specified, an automatic attribute selection is performed.

  • parameters – Parameters of the algorithm.

Returns:

  • clf – Fitted decision tree classifier.

  • feature_names – The names of the features used to fit the classifier.

  • classes – The classes (i.e., transitions) the classifier distinguishes.

pm4py.algo.decision_mining.algorithm.apply(log: EventLog | DataFrame, net: PetriNet, initial_marking: Marking, final_marking: Marking, decision_point=None, attributes=None, parameters: Dict[str | Parameters, Any] | None = None) Any[source]#

Gets the essential information (features, target class, and names of the target class) in order to learn a classifier.

Parameters:
  • log – Event log (EventLog or DataFrame).

  • net – Petri net.

  • initial_marking – Initial marking.

  • final_marking – Final marking.

  • decision_point – The name of the place in which a decision happens. - If not specified, raises an Exception with a list of possible places.

  • attributes – Attributes of the log. If not specified, an automatic attribute selection is performed.

  • parameters – Parameters of the algorithm.

Returns:

  • X – DataFrame of features.

  • y – Series of encoded target classes (integer).

  • class_name – Mapping of integer class -> actual transition name.

pm4py.algo.decision_mining.algorithm.get_decisions_table(log0, net, initial_marking, final_marking, attributes=None, use_trace_attributes=False, k=1, pre_decision_points=None, trace_attributes=None, parameters=None)[source]#

Builds a decision table out of a log and an accepting Petri net.

For each place that has multiple outgoing arcs (a “decision point”), we record the attributes that preceded the choice of a particular transition.

Parameters:
  • log0 – Event log (EventLog or DataFrame).

  • net – Petri net.

  • initial_marking – Initial marking.

  • final_marking – Final marking.

  • attributes – List of event attributes to consider (if not provided, all are considered).

  • use_trace_attributes – Whether to include trace attributes (e.g., case-level data) in the decision table.

  • k – Number of last events to look back at for each decision. (Default=1)

  • pre_decision_points – List of place names that should be considered. If None, the code infers them automatically.

  • trace_attributes – List of trace attribute names to consider. If None, all are considered (if use_trace_attributes=True).

  • parameters – Additional parameters (e.g., {Parameters.LABELS: True/False}).

Returns:

  • I – A dictionary keyed by place name. Values are lists of tuples (dict_of_attributes, chosen_transition).

  • decision_points – The dictionary of decision points (places with multiple outgoing arcs), possibly filtered by pre_decision_points.

pm4py.algo.decision_mining.algorithm.prepare_event_log(log)[source]#

If trace attributes are considered, we want to differentiate them from event attributes. For trace attributes, we prepend t_. For event attributes, we prepend e_.

This helps avoid collisions when both trace and event attributes share the same name.

Parameters:

log (EventLog) – The original log.

Returns:

The modified log with attribute names prefixed.

Return type:

EventLog

pm4py.algo.decision_mining.algorithm.prepare_attributes(attributes)[source]#

If trace attributes are considered, we assume all the user-provided attributes refer to event attributes and prepend e_ to them.

Parameters:

attributes (list) – List of original attribute names.

Returns:

List of attribute names, each prefixed by e_.

Return type:

list

pm4py.algo.decision_mining.algorithm.get_decision_points(net, labels=False, pre_decision_points=None, parameters=None)[source]#

Identifies “decision points” in the net, i.e., places with >= 2 outgoing arcs.

Parameters:
  • net (PetriNet) – The Petri net under analysis.

  • labels (bool) – Whether to list the labels of transitions as values rather than the raw transition names.

  • pre_decision_points (list or None) – If provided, only return decision points that appear in this list (filter).

  • parameters (dict) – (Unused in this function except for consistency.)

Returns:

A dictionary mapping place_name -> list of outgoing transition names or labels.

Return type:

dict

pm4py.algo.decision_mining.algorithm.get_attributes(log, decision_points, attributes, use_trace_attributes, trace_attributes, k, net, initial_marking, final_marking, decision_points_names, parameters=None)[source]#

For each decision place, this collects the final table of (attributes -> chosen transition) for each occurrence of a decision.

This function internally uses token-based replay (or alignment for non-fitting traces) to discover the actual transitions that were used from the log. Then, for each place with multiple outgoing arcs, we store the attributes that led to a certain chosen transition.

Parameters:
  • log (EventLog) – The event log.

  • decision_points (dict) – Dictionary mapping place_name -> list of possible transitions (IDs/names).

  • attributes (list) – Attributes to consider from events.

  • use_trace_attributes (bool) – Whether to consider trace-level attributes as well.

  • trace_attributes (list) – List of trace-level attributes to consider.

  • k (int) – Number of events to look back at each decision (the “window size”).

  • net (PetriNet) – The Petri net.

  • initial_marking (Marking) – Initial marking.

  • final_marking (Marking) – Final marking.

  • decision_points_names (dict) – Dictionary mapping place_name -> list of transition labels (if labels=True).

  • parameters (dict) – Additional parameters (e.g. {Parameters.LABELS: True/False}).

Returns:

A dictionary keyed by place name, with each value a list of tuples: (attributes_dict, chosen_transition).

Return type:

dict

pm4py.algo.decision_mining.algorithm.encode_target(df, target_column)[source]#

Adds a ‘Target’ column to df with integer-encoded classes derived from an existing column (target_column).

Method adapted from: http://chrisstrelioff.ws/sandbox/2015/06/08/decision_trees_in_python_with_scikit_learn_and_pandas.html

Parameters:
  • df (pd.DataFrame) – The DataFrame containing the target_column.

  • target_column (str) – The name of the column to map to integer classes.

Returns:

df_mod is the modified DataFrame with a ‘Target’ column. targets is the list of unique target names in their mapped order.

Return type:

(df_mod, targets)