eda
compare_two_tree_models(model1, model2, headers=['Parameter', 'Default', 'Spot'])
¶
Compares two tree models. Args: model1 (object): A tree model. model2 (object): A tree model. headers (list): A list with the headers of the table.
Returns:
Type | Description |
---|---|
str
|
A table with the comparison of the two models. |
Examples:
>>> from spotpython.utils.eda import compare_two_tree_models
>>> from spotpython.hyperparameters.values import get_default_values
>>> fun_control = {
... "x1": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x2": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x3": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x4": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x5": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x6": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x7": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x8": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x9": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x10": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... }
>>> default_values = get_default_values(fun_control)
>>> model1 = spot_tuner.get_model("rf", default_values)
>>> model2 = spot_tuner.get_model("rf", default_values)
>>> compare_two_tree_models(model1, model2)
Source code in spotpython/utils/eda.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
|
count_missing_data(df)
¶
Counts the number of missing values in each column of the given DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing the data to be counted. |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
DataFrame containing the number of missing values in each column. |
Example
import pandas as pd df = pd.DataFrame({‘A’: [1, 2, None], ‘B’: [4, None, 6], ‘C’: [7, 8, 9]}) count_missing_data(df) column_name missing_count 0 A 1 1 B 1
Source code in spotpython/utils/eda.py
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
filter_highly_correlated(df, sorted=True, threshold=1 - 1e-05)
¶
Return a new DataFrame with only those columns that are highly correlated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
The input DataFrame. |
required |
threshold |
float
|
The correlation threshold. |
1 - 1e-05
|
sorted |
bool
|
If True, the columns are sorted by name. |
True
|
Returns:
Name | Type | Description |
---|---|---|
DataFrame |
DataFrame
|
A new DataFrame with only highly correlated columns. |
Examples:
>>> df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
df = filter_highly_correlated(df, sorted=True, threshold=0.99)
Source code in spotpython/utils/eda.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
gen_design_table(fun_control, spot=None, tablefmt='github')
¶
Generates a table with the design variables and their bounds.
Args:
fun_control (dict):
A dictionary with function design variables.
spot (object):
A spot object. Defaults to None.
Returns:
(str):
a table with the design variables, their default values, and their bounds.
If a spot object is provided,
the table will also include the value and the importance of each hyperparameter.
Use the print
function to display the table.
Examples:
>>> from spotpython.utils.eda import gen_design_table
>>> from spotpython.hyperparameters.values import get_default_values
>>> fun_control = {
... "x1": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x2": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x3": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x4": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x5": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x6": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x7": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x8": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x9": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... "x10": {"type": "int", "default": 1, "lower": 1, "upper": 10},
... }
Source code in spotpython/utils/eda.py
48 49 50 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
generate_config_id(config, hash=False, timestamp=False)
¶
Generates a unique id for a configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
dict
|
A dictionary with the configuration. |
required |
hash |
bool
|
If True, the id is hashed. |
False
|
timestamp |
bool
|
If True, the id is appended with a timestamp. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
str
|
A unique id for the configuration. |
Examples:
>>> from spotpython.hyperparameters.values import get_one_config_from_X
>>> X = spot_tuner.to_all_dim(spot_tuner.min_X.reshape(1,-1))
>>> config = get_one_config_from_X(X, fun_control)
>>> generate_config_id(config)
Source code in spotpython/utils/eda.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
|
get_stars(input_list)
¶
Converts a list of values to a list of stars, which can be used to visualize the importance of a variable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_list |
list
|
A list of values. |
required |
Returns:
Type | Description |
---|---|
list
|
A list of strings. |
Examples:
>>> from spotpython.utils.eda import convert_list
>>> get_stars([100, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
[***, '', '', '', '', '', '', '', '']
Source code in spotpython/utils/eda.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
plot_missing_data(df, relative=False, figsize=(7, 5), color='grey', xlabel='Missing Data', title='Missing Data')
¶
Plots a horizontal bar chart of the number of missing values in each column of the given DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
DataFrame containing the data to be plotted. |
required |
relative |
bool
|
Whether to plot relative values (percentage) or absolute values. |
False
|
figsize |
tuple
|
Size of the figure to be plotted. |
(7, 5)
|
color |
str
|
Color of the bars in the bar chart. |
'grey'
|
xlabel |
str
|
Label for the x-axis. |
'Missing Data'
|
title |
str
|
Title for the plot. |
'Missing Data'
|
Returns:
Type | Description |
---|---|
NoneType
|
None |
Example
import pandas as pd df = pd.DataFrame({‘A’: [1, 2, np.nan], ‘B’: [4, np.nan, 6], ‘C’: [7, 8, 9]}) plot_missing_data(df)
Source code in spotpython/utils/eda.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
|
plot_sns_heatmap(df_heat, figsize=(16, 12), cmap='vlag', vmin=-1, vmax=1, annot=True, fmt='.5f', linewidths=0.5, annot_kws={'size': 8})
¶
Plots a heatmap of the correlation matrix of the given DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_heat |
DataFrame
|
DataFrame containing the data to be plotted. |
required |
figsize |
tuple
|
Size of the figure to be plotted. |
(16, 12)
|
cmap |
str
|
Color map to be used for the heatmap. |
'vlag'
|
vmin |
int
|
Minimum value for the color scale. |
-1
|
vmax |
int
|
Maximum value for the color scale. |
1
|
annot |
bool
|
Whether to display annotations on the heatmap. |
True
|
fmt |
str
|
Format string for annotations. |
'.5f'
|
linewidths |
float
|
Width of lines separating cells in the heatmap. |
0.5
|
annot_kws |
dict
|
Keyword arguments for annotations. |
{'size': 8}
|
Returns:
Type | Description |
---|---|
NoneType
|
None |
Example
import pandas as pd df = pd.DataFrame({‘A’: [1, 2, 3], ‘B’: [4, 5, 6], ‘C’: [7, 8, 9]}) plot_heatmap(df)
Source code in spotpython/utils/eda.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|