hpt.utils package
hpt.utils.api module
Collection of classes defining the API this package depends on.
hpt.utils.classpath module
Utils pertaining to importing and loading objects.
hpt.utils.dict module
Utils for handling dictionaries.
- hpt.utils.dict.apply_recursively(dct, apply, pred=<function <lambda>>)[source]
Applies a function recursively to the provided dictionary, possibly filtering the fields to which it is applied.
- Parameters:
dct (dict) – The dictionary to which the callable apply will be recursively applied.
apply (Callable) – The function to apply to the dictionary’s fields.
pred (Callable) – Predicate to filter which fields to apply the function to. Receives the (key, value) pair as an input.
- Return type:
dict
hpt.utils.fairness_criteria module
Computing fairness criteria on data.
File extracted from: https://github.com/fairmlbook/fairmlbook.github.io/blob/master/code/creditscore/criteria.py
- class hpt.utils.fairness_criteria.CriteriaData(cdfs, performance, totals)[source]
Bases:
object
Class for computing fairness criteria of data.
Create a CriteriaData instance from marginals.
cdfs and performance are both dataframes, with index = score and columns being the groups.
cdfs[group][score] = fraction of people of that group with score below that score. performance[group][score] = fraction of people with that group & score that succeed. totals[group] = total number of people of that group.
totals can be either a dictionary or an array (if an array, in the same order as cdfs.columns)
- classmethod from_individuals(data, groups=None, binsize=0.025)[source]
Recover CriteriaData instance from individual performances.
data should be a dataframe with three columns: the group key, the predictor score, and the result. Scores will be binned into bins of size binsize to compute the performance per group/score.
groups is the set of group keys to use; it may be specified to restrict the set, or to define the order.
- property trisearch
- hpt.utils.fairness_criteria.first_index_above(array, value)[source]
Find the smallest index i for which array[i] > value.
If no such value exists, return len(array).
hpt.utils.load_yaml module
Utils specific to the tuners module.
Author: @sgpjesus
- class hpt.utils.load_yaml.YamlValidator[source]
Bases:
object
- assert_argument_exists(argument)[source]
Checks if a given argument for the Model Class to be isntantiated is expected by the Class signature. Uses global object of model to check signature.
- Parameters:
argument (str) – Argument to be checked.
- Returns:
True if check passes.
- Return type:
bool
- Raises:
TypeError – If argument is not expected in Class.
- assert_class_exists(path)[source]
Checks if a given module and Class exists in the current python environment. Saves class in global object to assert arguments.
- Parameters:
path (str) – Classpath to the Class to be checked.
AttributeError (Returns) – If Class does not exist within module.
ValueError – If classpath is malformed.
-------
bool – True if check passes.
- Raises:
ModuleNotFoundError – If module does not exist.
AttributeError – If Class does not exist within module.
ValueError – If classpath is malformed.
- Return type:
bool
- hpt.utils.load_yaml.load_hyperparameter_space(path_or_dict)[source]
Loads the hyperparameter space encoded as a YAML in the given path. If given a dict, space is already loaded and this function will return the same object.
- Parameters:
path_or_dict (Union[str, dict]) – Either the path to the YAML file, or a dictionary containing a hyperparameter space following the expected structure.
- Return type:
The loaded hyperparameter space.
hpt.utils.trial module
An optuna Trial to output random hyperparameters outside optuna.