[[
✎ pl:dydaktyka:dss:lab02
]]
aiWiki
Pokaż stronę
Ostatnie zmiany
Indeks
Zaloguj
Ta strona jest tylko do odczytu. Możesz wyświetlić źródła tej strony ale nie możesz ich zmienić.
====== Process mining in Python ====== ===== Requirements ===== Python 3.x, opyenxes, pygraphviz. ===== Implementing a simple heuristic miner ===== Using the following excerpt of code import a ''repairExample.xes'' file into your Python script: <code python> from opyenxes.data_in.XUniversalParser import XUniversalParser path = 'repairExample.xes' with open(path) as log_file: # parse the log log = XUniversalParser().parse(log_file)[0] </code> Take a look at the ''log'' variable. Using ''log.get_features()'' or ''log.get_attributes()'', you can check some information about the log. As the parsed log consists of lists of events, you can also select a single event and check its attributes: <code python> event = log[0][0] event.get_attributes() </code> For ease of further work, we will create a ''workflow_log'' consisting of names of events: <code python> workflow_log = [] for trace in log: workflow_trace = [] for event in trace[0::2]: # get the event name from the event in the log event_name = event.get_attributes()['Activity'].get_value() workflow_trace.append(event_name) workflow_log.append(workflow_trace) </code> To create a simple heuristic net of task (simplified process model like in Disco tool), we will create a structure in which for each event, we gather a set of all events that precede this event: <code python> w_net = dict() for w_trace in workflow_log: for i in range(0, len(w_trace)-1): ev_i, ev_j = w_trace[i], w_trace[i+1] if ev_i not in w_net.keys(): w_net[ev_i] = set() w_net[ev_i].add(ev_j) </code> Take a closer look at the ''w_net'' dictionary: <code> {'Analyze Defect': {'Inform User', 'Repair (Complex)', 'Repair (Simple)'}, 'Archive Repair': {'End'}, 'Inform User': {'Archive Repair', 'End', ...}, ...} </code> It represents the connections between events: | | Analyze Defect | Archive Repair | Inform User | ... | End | | Analyze Defect | | | -> | | | | Archive Repair | | | | | -> | | Inform User | -> | | | | -> | | ... | | End | Using [[https://pygraphviz.github.io/|Pygraphviz]], we can render an image depicting the process: {{ :pl:dydaktyka:dss:lab:simple_heuristic_net.png?470|}} <code python> import pygraphviz as pgv G = pgv.AGraph(strict=False, directed=True) G.graph_attr['rankdir'] = 'LR' G.node_attr['shape'] = 'Mrecord' for event in w_net: G.add_node(event, style="rounded,filled", fillcolor="#ffffcc") for preceding in w_net[event]: G.add_edge(event, preceding) G.draw('simple_heuristic_net.png', prog='dot') </code> ===== Diagram enhancing =====
pl/dydaktyka/dss/lab02.1539739911.txt.gz
· ostatnio zmienione: 2019/06/27 15:57 (edycja zewnętrzna)
Pokaż stronę
Poprzednie wersje
Menadżer multimediów
Do góry