microtc.utils

class microtc.utils.Counter(iter=None, update_calls=0, **kwargs)[source]
classmethod fromjson(data)[source]

Create class from json.

tojson()[source]

Represent class in json.

update(*args, **kwargs)[source]

Like dict.update() but add counts instead of replacing them.

Source can be an iterable, a dictionary, or another Counter instance.

>>> c = Counter('which')
>>> c.update('witch')           # add elements from another iterable
>>> d = Counter('watch')
>>> c.update(d)                 # add elements from another counter
>>> c['h']                      # four 'h' in which, witch, and watch
4
property update_calls

Count the number of times update() has been called.

class microtc.utils.SparseMatrix[source]
tonp(X)[source]

Sparse representation to sparce matrix

Parameters:

X (list) – Sparse representation of matrix

Return type:

csr_matrix

microtc.utils.get_class(m)[source]

Import class from string

Parameters:

m (str or class) – string or class to be imported

Return type:

class

>>> get_class('microtc.textmodel.TextModel')
<class 'microtc.textmodel.TextModel'>
microtc.utils.load_model(fname)[source]

Read model from file. The model must be stored using gzip and pickle

Parameters:

fname (str (path)) – filename

microtc.utils.save_model(obj, fname)[source]

Store model from file. The model is stored using gzip and pickle

Parameters:
  • obj (object) – object to store

  • fname (str (path)) – filename