niklib.configs package#
Submodules#
niklib.configs.core module#
- class niklib.configs.core.JsonConfigHandler[source]#
Bases:
object
Initializes a class or method based on a predefined json config file
In the highest level of configs, there are keys that contain the name of method or property of a
Callable
object. These needs to be passed to theparse()
method of theniklib.configs.core.JsonConfigHandler
class.- Here is the convention of constructing json config file:
name the json file itself as whatever you wish. But better to be
something that represents the class object you are trying to config. e.g. assume we have
flaml_automl
object hence we name the json file asexample_flaml_automl_configs.json
. - in highest level, if args of a method need to be defined, usemethod_[name_of_the_method_of_your_class]
. e.g. let’s sayflaml_automl
hasfit
method, then key in json would be namedmethod_fit
. - values of each key are the arguments of that key. E.g. let’s saymethod_fit
has argstask
andmax_iter
. Then the value formethod_fit
would be[YOUR_CLASS_NAME]_[ARG]: value
. E.g.FLAML_AUTOML_TASK: "classification"`
orFLAML_AUTOML_MAX_ITER: 100
.
Here is a full example:
```json
- {
- “method_fit”: {
“FLAML_AUTOML_METRIC”: “log_loss”, “FLAML_AUTOML_TASK”: “classification”, “FLAML_AUTOML_MAX_ITER”: 100, “FLAML_SPLIT_RATIO”: 0.1, “FLAML_AUTOML_MEM_THRES”: 19327352832, “FLAML_AUTOML_N_CONCURRENT_TRIALS”: 1, “FLAML_AUTOML_AUTO_AUGMENT”: false, “FLAML_AUTOML_EARLY_STOP”: false, “FLAML_AUTOML_VERBOSE”: 5
}
}
After defining this file, you can added it as a constant to the root of the package hosting the class for this config. E.g. this example was for
flaml
model which is inniklib.models.trainers.aml_flaml
. So, you can fillniklib.models.trainers.__init__
with a constant to the path of this json. In the end, you can using this way:>>> from niklib.configs import JsonConfigHandler >>> from niklib.models.trainers.aml_flaml import AutoML >>> configs = JsonConfigHandler.parse(EXAMPLE_FLAML_AUTOML_CONFIGS, AutoML) >>> configs['method_fit']['task'] classification >>> configs['method_fit']['max_iter'] 100
Note
This class has hardcoded and customized definitions for different
target
values which can be found in the each packagesdata
dir such asniklib.models.trainers.EXAMPLE_FLAML_AUTOML_CONFIGS
.- parse(filename, target)[source]#
Takes a json file path and parse it for a particular class or method
Note
See class description about valid json configs and the way they are constructed.
- Parameters:
- Raises:
ValueError – If the target class or method is not supported or implemented
- Returns:
A dictionary containing the configs for each possible method or property of the target class or method.
- Return type:
Module contents#
- niklib.configs.SAMPLE = PosixPath('/home/runner/work/niklib/niklib/niklib/configs/data/sample.csv')#
Some sample data for demo
Note
The data has been obtained from http://example.com