Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/hotfixes' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
fit-alessandro-berti committed Apr 12, 2024
2 parents 55870f9 + 22609f4 commit 104d2db
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 196 deletions.
14 changes: 6 additions & 8 deletions examples/timestamp_granularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ def execute_script():

# Here are some common options that you can use as a granularity:
#
# 'D': Day
# 'H': Hour
# 'T' or 'min': Minute
# 'S': Second
# 'L' or 'ms': Millisecond
# 'U': Microsecond
# 'N': Nanosecond
# 'h': Hour
# 'min': Minute
# 's': Second
# 'ms': Millisecond
# 'ns': Nanosecond

st = time.time_ns()
# cast on the minute
dataframe["time:timestamp"] = dataframe["time:timestamp"].dt.floor('T')
dataframe["time:timestamp"] = dataframe["time:timestamp"].dt.floor(freq='min')
ct = time.time_ns()

print("required time for the timestamp casting: %.2f seconds" % ((ct-st)/10**9))
Expand Down
73 changes: 38 additions & 35 deletions tests/dec_tree_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import unittest
import importlib.util

from pm4py.objects.log.importer.xes import importer as xes_importer
from pm4py.objects.log.util import get_class_representation
Expand All @@ -8,43 +9,45 @@

class DecisionTreeTest(unittest.TestCase):
def test_decisiontree_evattrvalue(self):
from pm4py.util import ml_utils
from pm4py.visualization.decisiontree import visualizer as dt_vis

# to avoid static method warnings in tests,
# that by construction of the unittest package have to be expressed in such way
self.dummy_variable = "dummy_value"
log_path = os.path.join("input_data", "roadtraffic50traces.xes")
log = xes_importer.apply(log_path)
data, feature_names = log_to_features.apply(log, variant=log_to_features.Variants.TRACE_BASED,
parameters={"str_tr_attr": [], "str_ev_attr": ["concept:name"],
"num_tr_attr": [], "num_ev_attr": ["amount"]})
target, classes = get_class_representation.get_class_representation_by_str_ev_attr_value_value(log,
"concept:name")
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
gviz = dt_vis.apply(clf, feature_names, classes,
parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: "svg"})
del gviz
if importlib.util.find_spec("sklearn"):
from pm4py.util import ml_utils
from pm4py.visualization.decisiontree import visualizer as dt_vis

# to avoid static method warnings in tests,
# that by construction of the unittest package have to be expressed in such way
self.dummy_variable = "dummy_value"
log_path = os.path.join("input_data", "roadtraffic50traces.xes")
log = xes_importer.apply(log_path)
data, feature_names = log_to_features.apply(log, variant=log_to_features.Variants.TRACE_BASED,
parameters={"str_tr_attr": [], "str_ev_attr": ["concept:name"],
"num_tr_attr": [], "num_ev_attr": ["amount"]})
target, classes = get_class_representation.get_class_representation_by_str_ev_attr_value_value(log,
"concept:name")
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
gviz = dt_vis.apply(clf, feature_names, classes,
parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: "svg"})
del gviz

def test_decisiontree_traceduration(self):
from pm4py.util import ml_utils
from pm4py.visualization.decisiontree import visualizer as dt_vis

# to avoid static method warnings in tests,
# that by construction of the unittest package have to be expressed in such way
self.dummy_variable = "dummy_value"
log_path = os.path.join("input_data", "roadtraffic50traces.xes")
log = xes_importer.apply(log_path)
data, feature_names = log_to_features.apply(log, variant=log_to_features.Variants.TRACE_BASED,
parameters={"str_tr_attr": [], "str_ev_attr": ["concept:name"],
"num_tr_attr": [], "num_ev_attr": ["amount"]})
target, classes = get_class_representation.get_class_representation_by_trace_duration(log, 2 * 8640000)
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
gviz = dt_vis.apply(clf, feature_names, classes,
parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: "svg"})
del gviz
if importlib.util.find_spec("sklearn"):
from pm4py.util import ml_utils
from pm4py.visualization.decisiontree import visualizer as dt_vis

# to avoid static method warnings in tests,
# that by construction of the unittest package have to be expressed in such way
self.dummy_variable = "dummy_value"
log_path = os.path.join("input_data", "roadtraffic50traces.xes")
log = xes_importer.apply(log_path)
data, feature_names = log_to_features.apply(log, variant=log_to_features.Variants.TRACE_BASED,
parameters={"str_tr_attr": [], "str_ev_attr": ["concept:name"],
"num_tr_attr": [], "num_ev_attr": ["amount"]})
target, classes = get_class_representation.get_class_representation_by_trace_duration(log, 2 * 8640000)
clf = ml_utils.DecisionTreeClassifier(max_depth=7)
clf.fit(data, target)
gviz = dt_vis.apply(clf, feature_names, classes,
parameters={dt_vis.Variants.CLASSIC.value.Parameters.FORMAT: "svg"})
del gviz


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 104d2db

Please sign in to comment.