categorical
add_missing_elements(a, b)
¶
Add missing elements from list a to list b. Arguments: a (list): List of elements to check. b (list): List of elements to add to.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
List of elements with missing elements from list a added. |
Examples:
>>> a = [1, 4]
b = [1, 2]
add_missing_elements(a, b)
[1, 2, 4]
Source code in spotpython/hyperparameters/categorical.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
find_closest_key(integer_value, encoding_dict)
¶
Given an integer value and an encoding dictionary that maps keys to binary values, this function finds the key in the dictionary whose binary value is closest to the binary representation of the integer value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
integer_value |
int
|
The integer value to find the closest key for. |
required |
encoding_dict |
dict
|
The encoding dictionary that maps keys to binary values. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The key in the encoding dictionary whose binary value is |
str
|
closest to the binary representation of the integer value. |
Examples:
>>> encoding_dict = {'A': [1, 0, 0], 'B': [0, 1, 0], 'C': [0, 0, 1]}
find_closest_key(6, encoding_dict)
'B'
Source code in spotpython/hyperparameters/categorical.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
get_one_hot(alg, hyper_param, d=None, filename='data.json')
¶
Get one hot encoded values for a hyper parameter of an algorithm. Arguments: alg (str): Name of the algorithm. hyper_param (str): Name of the hyper parameter. d (dict): Dictionary of algorithms and their hyperparameters. filename (str): Name of the file containing the dictionary. Returns: dict: Dictionary of hyper parameter values and their one hot encoded values.
Examples:
>>> alg = "HoeffdingAdaptiveTreeClassifier"
hyper_param = "split_criterion"
d = {
"HoeffdingAdaptiveTreeClassifier": {
"split_criterion": ["gini", "info_gain", "hellinger"],
"leaf_prediction": ["mc", "nb", "nba"],
"bootstrap_sampling": ["0", "1"]
},
"HoeffdingTreeClassifier": {
"split_criterion": ["gini", "info_gain", "hellinger"],
"leaf_prediction": ["mc", "nb", "nba"],
"binary_split": ["0", "1"],
"stop_mem_management": ["0", "1"]
}
}
get_one_hot(alg, hyper_param, d)
{'gini': [1, 0, 0], 'info_gain': [0, 1, 0], 'hellinger': [0, 0, 1]}
Source code in spotpython/hyperparameters/categorical.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
one_hot_encode(strings)
¶
One hot encode a list of strings. Arguments: strings (list): List of strings to encode. Returns: dict: Dictionary of strings and their one hot encoded values. Examples: >>> one_hot_encode([‘a’, ‘b’, ‘c’]) {‘a’: [1, 0, 0], ‘b’: [0, 1, 0], ‘c’: [0, 0, 1]}
Source code in spotpython/hyperparameters/categorical.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
sum_encoded_values(strings, encoding_dict)
¶
Sum the encoded values of a list of strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strings |
list
|
List of strings to encode. |
required |
encoding_dict |
dict
|
Dictionary of strings and their one hot encoded values. |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Decimal value of the sum of the encoded values. |
Examples:
>>> encoding_dict = {'a': [1, 0, 0], 'b': [0, 1, 0], 'c': [0, 0, 1]}
sum_encoded_values(['a', 'b', 'c'], encoding_dict)
7
sum_encoded_values(['a', 'c'], encoding_dict)
5
Source code in spotpython/hyperparameters/categorical.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|