Callback API

scikit-mine allows to define custom callbacks to track metrics and artifacts during exploration. The definition of callbacks is volontarily very permissive so that it will work in most cases.

Simply put, a callback is a method to be called after the execution of a method it targets. This allows tracking models attributes (accesing the model directly via the ``self`` keyword), or function results.

class skmine.callbacks.CallBacks(**kwargs)[source]

A collection of callbacks

Works by defining functions to be called after the execution of the function they target

Parameters

pairs (key-value) – Keys must be string, values must be callables

Examples

>>> class A():
...     def f(self):
...         return 10
...
>>> from skmine.callbacks import CallBacks
>>> stack = list()
>>> callbacks = CallBacks(f=stack.append)
>>> a = A()
>>> callbacks(a)
>>> a.f()
10
>>> stack
[10]
skmine.callbacks.mdl_prints(miner)

Base callback for miners which inherit the skmine.base.MDLOptimizer

Prints data size and model size when compression has improved, only if verbose is set to True for the miner to attach.

Examples

>>> from skmine.callbacks import mdl_prints
>>> from skmine.base import MDLOptimizer
>>> class MyMDLMiner(MDLOptimizer):
...     def __init__(self):
...         self.codetable_ = dict()
...     def generate_candidates(self):
...         return [(2,), (2, 3), (2, 4)]
...     def evaluate(self):
...         pass
>>> miner = MyMDLMiner()
>>> mdl_prints(miner)
>>> miner.generate_candidates()
3 new candidates considered
[(2,), (2, 3), (2, 4)]