nordlys.core.ml.cross_validation module

Cross Validation

Cross-validation support.

We assume that instances (i) are uniquely identified by an instance ID and (ii) they have id and score properties. We access them using the Instances class.

Authors:Faegheh Hasibi, Krisztian Balog
class nordlys.core.ml.cross_validation.CrossValidation(k, instances, callback_train, callback_test)[source]

Bases: object

Class attributes:
fold: dict of folds (1..k) with a dict
{“training”: [list of instance_ids]}, {“testing”: [list of instance_ids]}
Parameters:
  • k – number of folds
  • instances – Instances object
  • callback_train – Callback function for training model
  • callback_test – Callback function for applying model
create_folds(group_by=None)[source]

Creates folds for the data set.

Parameters:group_by – property to group by (instance_id by default)
get_folds(filename=None, group_by=None)[source]

Loads folds from file or generates them if the file doesn’t exist.

Parameters:
  • filename
  • k – number of folds
Returns:

get_instances(i, mode, property=None)[source]

Returns instances from the given fold i in [0..k-1].

Parameters:
  • i – fold number
  • mode – training or testing

:return Instances object

load_folds(filename)[source]

Loads previously created folds from (JSON) file.

run()[source]

Runs cross-validation.

save_folds(filename)[source]

Saves folds to (JSON) file.

nordlys.core.ml.cross_validation.main()[source]