nkululeko 0.93.13__py3-none-any.whl → 0.93.15__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nkululeko/constants.py +1 -1
- nkululeko/data/dataset_csv.py +5 -4
- nkululeko/modelrunner.py +4 -4
- nkululeko/models/model_mlp.py +1 -1
- nkululeko/plots.py +12 -3
- nkululeko/utils/stats.py +11 -9
- nkululeko/utils/util.py +15 -0
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/METADATA +1 -1
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/RECORD +13 -13
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/LICENSE +0 -0
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/WHEEL +0 -0
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/entry_points.txt +0 -0
- {nkululeko-0.93.13.dist-info → nkululeko-0.93.15.dist-info}/top_level.txt +0 -0
nkululeko/constants.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
VERSION="0.93.
|
1
|
+
VERSION="0.93.15"
|
2
2
|
SAMPLING_RATE = 16000
|
nkululeko/data/dataset_csv.py
CHANGED
@@ -3,19 +3,20 @@ import ast
|
|
3
3
|
import os
|
4
4
|
import os.path
|
5
5
|
|
6
|
-
import audformat.utils
|
7
6
|
import pandas as pd
|
8
7
|
|
9
|
-
import
|
8
|
+
import audformat.utils
|
9
|
+
|
10
10
|
from nkululeko.data.dataset import Dataset
|
11
|
+
import nkululeko.glob_conf as glob_conf
|
11
12
|
from nkululeko.reporting.report_item import ReportItem
|
12
13
|
|
13
14
|
|
14
15
|
class Dataset_CSV(Dataset):
|
15
|
-
"""Class to represent datasets stored as a csv file"""
|
16
|
+
"""Class to represent datasets stored as a csv file."""
|
16
17
|
|
17
18
|
def load(self):
|
18
|
-
"""Load the dataframe with files, speakers and task labels"""
|
19
|
+
"""Load the dataframe with files, speakers and task labels."""
|
19
20
|
self.util.debug(f"loading {self.name}")
|
20
21
|
self.got_target, self.got_speaker, self.got_gender = False, False, False
|
21
22
|
data_file = self.util.config_val_data(self.name, "", "")
|
nkululeko/modelrunner.py
CHANGED
@@ -68,7 +68,7 @@ class Modelrunner:
|
|
68
68
|
report.plot_confmatrix(plot_name, epoch)
|
69
69
|
else:
|
70
70
|
# for all epochs
|
71
|
-
for epoch in range(epoch_num):
|
71
|
+
for epoch_index, epoch in enumerate(range(epoch_num)):
|
72
72
|
if only_test:
|
73
73
|
self.model.load(self.run, epoch)
|
74
74
|
self.util.debug(f"reusing model: {self.model.store_path}")
|
@@ -119,13 +119,13 @@ class Modelrunner:
|
|
119
119
|
)
|
120
120
|
break
|
121
121
|
# After training, report the best performance and epoch
|
122
|
-
|
122
|
+
last_report = reports[-1]
|
123
123
|
# self.util.debug(f"Best score at epoch: {self.best_epoch}, UAR: {self.best_performance}") # move to reporter below
|
124
124
|
|
125
125
|
if not plot_epochs:
|
126
126
|
# Do at least one confusion matrix plot
|
127
|
-
self.util.debug(f"plotting confusion matrix to {plot_name}")
|
128
|
-
|
127
|
+
self.util.debug(f"plotting last confusion matrix to {plot_name}")
|
128
|
+
last_report.plot_confmatrix(plot_name, epoch_index)
|
129
129
|
return reports, epoch
|
130
130
|
|
131
131
|
def _select_model(self, model_type):
|
nkululeko/models/model_mlp.py
CHANGED
nkululeko/plots.py
CHANGED
@@ -24,8 +24,10 @@ class Plots:
|
|
24
24
|
self.format = self.util.config_val("PLOT", "format", "png")
|
25
25
|
self.target = self.util.config_val("DATA", "target", "emotion")
|
26
26
|
self.with_ccc = eval(self.util.config_val("PLOT", "ccc", "False"))
|
27
|
+
self.type_s = "samples"
|
27
28
|
|
28
29
|
def plot_distributions_speaker(self, df):
|
30
|
+
self.type_s = "speaker"
|
29
31
|
df_speakers = pd.DataFrame()
|
30
32
|
pd.options.mode.chained_assignment = None # default='warn'
|
31
33
|
for s in df.speaker.unique():
|
@@ -301,11 +303,18 @@ class Plots:
|
|
301
303
|
plot_df = plot_df.rename(columns={cont_col: self.target})
|
302
304
|
cont_col = self.target
|
303
305
|
dist_type = self.util.config_val("EXPL", "dist_type", "kde")
|
304
|
-
|
306
|
+
max_cat, cat_str, effect_results = su.get_effect_size(
|
307
|
+
plot_df, cat_col, cont_col
|
308
|
+
)
|
309
|
+
self.util.debug(effect_results)
|
310
|
+
self.util.print_results_to_store(
|
311
|
+
f"cohens-d_{self.type_s}", str(effect_results) + "\n"
|
312
|
+
)
|
313
|
+
es = effect_results[max_cat]
|
305
314
|
model_type = self.util.get_model_type()
|
306
315
|
if dist_type == "hist" and model_type != "tree":
|
307
316
|
ax = sns.histplot(plot_df, x=cont_col, hue=cat_col, kde=True)
|
308
|
-
caption = f"{ylab} {plot_df.shape[0]}. {cat_str} ({
|
317
|
+
caption = f"{ylab} {plot_df.shape[0]}. {cat_str} ({max_cat}):" f" {es}"
|
309
318
|
ax.set_title(caption)
|
310
319
|
ax.set_xlabel(f"{cont_col}")
|
311
320
|
ax.set_ylabel(f"number of {ylab}")
|
@@ -319,7 +328,7 @@ class Plots:
|
|
319
328
|
warn_singular=False,
|
320
329
|
)
|
321
330
|
ax.set(xlabel=f"{cont_col}")
|
322
|
-
caption = f"{ylab} {plot_df.shape[0]}. {cat_str} ({
|
331
|
+
caption = f"{ylab} {plot_df.shape[0]}. {cat_str} ({max_cat}):" f" {es}"
|
323
332
|
ax.figure.suptitle(caption)
|
324
333
|
return ax, caption
|
325
334
|
|
nkululeko/utils/stats.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
import math
|
2
1
|
from itertools import combinations
|
2
|
+
import math
|
3
3
|
|
4
4
|
import numpy as np
|
5
|
+
import pandas as pd
|
5
6
|
|
6
7
|
|
7
8
|
def check_na(a):
|
@@ -14,9 +15,8 @@ def check_na(a):
|
|
14
15
|
return a
|
15
16
|
|
16
17
|
|
17
|
-
def cohen_d(d1, d2):
|
18
|
-
"""
|
19
|
-
Compute Cohen's d from two distributions of real valued arrays.
|
18
|
+
def cohen_d(d1: np.array, d2: np.array) -> float:
|
19
|
+
"""Compute Cohen's d from two distributions of real valued arrays.
|
20
20
|
|
21
21
|
Args:
|
22
22
|
d1: one array
|
@@ -50,7 +50,9 @@ def all_combinations(items_list):
|
|
50
50
|
return result
|
51
51
|
|
52
52
|
|
53
|
-
def get_effect_size(
|
53
|
+
def get_effect_size(
|
54
|
+
df: pd.DataFrame, target: str, variable: str
|
55
|
+
) -> tuple[str, str, dict]:
|
54
56
|
"""Get the effect size as Cohen's D.
|
55
57
|
|
56
58
|
Effect size is computed from a real numbered variable on a categorical target.
|
@@ -68,10 +70,10 @@ def get_effect_size(df, target, variable):
|
|
68
70
|
for c in categories:
|
69
71
|
cats[c] = df[df[target] == c][variable].values
|
70
72
|
combos = all_combinations(categories)
|
71
|
-
results = {}
|
73
|
+
results = {categories[0]: 0}
|
72
74
|
if len(categories) == 1:
|
73
75
|
cat_s = cohens_D_to_string(0)
|
74
|
-
return categories[0], cat_s,
|
76
|
+
return categories[0], cat_s, results
|
75
77
|
else:
|
76
78
|
for combo in combos:
|
77
79
|
one = combo[0]
|
@@ -79,10 +81,10 @@ def get_effect_size(df, target, variable):
|
|
79
81
|
results[f"{one}-{other}"] = cohen_d(cats[one], cats[other])
|
80
82
|
max_cat = max(results, key=results.get)
|
81
83
|
cat_s = cohens_D_to_string(float(results[max_cat]))
|
82
|
-
return max_cat, cat_s, results
|
84
|
+
return max_cat, cat_s, results
|
83
85
|
|
84
86
|
|
85
|
-
def cohens_D_to_string(val):
|
87
|
+
def cohens_D_to_string(val: float) -> str:
|
86
88
|
if val < 0.2:
|
87
89
|
rval = "no effect"
|
88
90
|
elif val < 0.2:
|
nkululeko/utils/util.py
CHANGED
@@ -160,6 +160,21 @@ class Util:
|
|
160
160
|
pred_name = self.get_model_description()
|
161
161
|
return f"{results_dir}/pred_{target}_{pred_name}.csv"
|
162
162
|
|
163
|
+
def print_results_to_store(self, name: str, contents: str) -> str:
|
164
|
+
"""Write contents to a result file.
|
165
|
+
|
166
|
+
Args:
|
167
|
+
name (str): the (sub) name of the file_
|
168
|
+
|
169
|
+
Returns:
|
170
|
+
str: The path to the file
|
171
|
+
"""
|
172
|
+
results_dir = self.get_path("res_dir")
|
173
|
+
pred_name = self.get_model_description()
|
174
|
+
path = os.path.join(results_dir, f"{name}_{pred_name}.txt")
|
175
|
+
with open(path, "a") as f:
|
176
|
+
f.write(contents)
|
177
|
+
|
163
178
|
def is_categorical(self, pd_series):
|
164
179
|
"""Check if a dataframe column is categorical."""
|
165
180
|
return pd_series.dtype.name == "object" or isinstance(
|
@@ -2,7 +2,7 @@ nkululeko/__init__.py,sha256=62f8HiEzJ8rG2QlTFJXUCMpvuH3fKI33DoJSj33mscc,63
|
|
2
2
|
nkululeko/aug_train.py,sha256=FoMbBrfyOZd4QAw7oIHl3X6-UpsqAKWVDIolCA7qOWs,3196
|
3
3
|
nkululeko/augment.py,sha256=3RzaxB3gRxovgJVjHXi0glprW01J7RaHhUkqotW2T3U,2955
|
4
4
|
nkululeko/cacheddataset.py,sha256=XFpWZmbJRg0pvhnIgYf0TkclxllD-Fctu-Ol0PF_00c,969
|
5
|
-
nkululeko/constants.py,sha256=
|
5
|
+
nkululeko/constants.py,sha256=66ewyVO87OYNVG6_B0zotZhLHPR1MXfKn6QBlVG7Gk4,40
|
6
6
|
nkululeko/demo-ft.py,sha256=iD9Pzp9QjyAv31q1cDZ75vPez7Ve8A4Cfukv5yfZdrQ,770
|
7
7
|
nkululeko/demo.py,sha256=4Yzhg6pCPBYPGJrP7JX2TysVosl_R1llpVDKc2P_gUA,4955
|
8
8
|
nkululeko/demo_feats.py,sha256=BvZjeNFTlERIRlq34OHM4Z96jdDQAhB01BGQAUcX9dM,2026
|
@@ -16,11 +16,11 @@ nkululeko/file_checker.py,sha256=xJY0Q6w47pnmgJVK5rcAKPYBrCpV7eBT4_3YBzTx-H8,345
|
|
16
16
|
nkululeko/filter_data.py,sha256=5AYDtqs_GWGr4V5CbbYQkVVgCD3kq2dpKu8rF3V87NI,7224
|
17
17
|
nkululeko/fixedsegment.py,sha256=Tb92QiuiyMsOO3WRWwuGjZGibS8hbHHCrcWAXGk7g04,2868
|
18
18
|
nkululeko/glob_conf.py,sha256=KL9YJQTHvTztxo1vr25qRRgaPnx4NTg0XrdbovKGMmw,525
|
19
|
-
nkululeko/modelrunner.py,sha256=
|
19
|
+
nkululeko/modelrunner.py,sha256=GGJPg41PyJPmT160d3p6mcvWePTeSaW_eilHCKmOKbw,11211
|
20
20
|
nkululeko/multidb.py,sha256=sO6OwJn8sn1-C-ig3thsIL8QMWHdV9SnJhDodKjeKrI,6876
|
21
21
|
nkululeko/nkuluflag.py,sha256=PGWSmZz-PiiHLgcZJAoGOI_Y-sZDVI1ksB8p5r7riWM,3725
|
22
22
|
nkululeko/nkululeko.py,sha256=M7baIq2nAoi6dEoBL4ATEuqAs5U1fvl_hyqAl5DybAQ,2040
|
23
|
-
nkululeko/plots.py,sha256=
|
23
|
+
nkululeko/plots.py,sha256=jutO1nC7EMXGEPXCivVGhgrk3I0WrYrvIWyClm7ASaE,26440
|
24
24
|
nkululeko/predict.py,sha256=MLnHEyFmSiHLLs-HDczag8Vu3zKF5T1rXLKdZZJ6py8,2083
|
25
25
|
nkululeko/resample.py,sha256=rn3-M1A-iwVGibfQNGyeYNa7briD24lIN9Szq_1uTJo,5194
|
26
26
|
nkululeko/runmanager.py,sha256=AswmORVUkCIH0gTx6zEyufvFATQBS8C5TXo2erSNdVg,7611
|
@@ -50,7 +50,7 @@ nkululeko/autopredict/ap_valence.py,sha256=WrW4Ltqi_odW49_4QEVKkfnrcztLIVZ4cXIEH
|
|
50
50
|
nkululeko/autopredict/estimate_snr.py,sha256=1k9-XadABudnsNOeFZD_Fg0E64-GUQVS7JEp82MLQS4,4995
|
51
51
|
nkululeko/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
52
52
|
nkululeko/data/dataset.py,sha256=G6RFK2msSVHxpzDm8gZSAD4GK6ieMS5fTbqVS-NOFuY,30081
|
53
|
-
nkululeko/data/dataset_csv.py,sha256=
|
53
|
+
nkululeko/data/dataset_csv.py,sha256=AIbtB6pGk5BSQGIgfokZ7tEGFjmuOq5w2XumRSimVWs,4833
|
54
54
|
nkululeko/feat_extract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
55
55
|
nkululeko/feat_extract/feats_agender.py,sha256=onfAQ6-xx_mFMJXEF1IX8cHBmGtGeX6weJmxbkfh1_o,3184
|
56
56
|
nkululeko/feat_extract/feats_agender_agender.py,sha256=_YQv1qw--3uQfnyTQDCwlmPRnrhdMhgXbYK2yQtseW0,3464
|
@@ -88,7 +88,7 @@ nkululeko/models/model_gmm.py,sha256=mhHFNtTzHuJvqYSA0h5YhvjA--KhnN6MTU_S0G3-d1c
|
|
88
88
|
nkululeko/models/model_knn.py,sha256=ByQlHIU_fNtSCGCvsrMEoLVJ9q2hUC4edtpp5rVS1B8,600
|
89
89
|
nkululeko/models/model_knn_reg.py,sha256=kaVP1xGNgktUGuQARi7uoJ0hmdPGHDpv2ugDesYN7RU,611
|
90
90
|
nkululeko/models/model_lin_reg.py,sha256=xqvf-06LhBkjHRdyXFqcYD8ozYPoAsZfGqfNEtuFQLc,423
|
91
|
-
nkululeko/models/model_mlp.py,sha256=
|
91
|
+
nkululeko/models/model_mlp.py,sha256=ghHg9dF9kP_m6C5FHMobmUBYJ1bE_ct77axWQKN5TUw,10671
|
92
92
|
nkululeko/models/model_mlp_regression.py,sha256=j8Y1nRHU9YJSQuBKpZb-JL-5seHGr6N5OX1biKj3Xa0,10297
|
93
93
|
nkululeko/models/model_svm.py,sha256=zP8ykLhCZTYvwSqw06XHuzq9qMBtsiYpxjUpWDAnMyA,995
|
94
94
|
nkululeko/models/model_svr.py,sha256=FEwYRdgqwgGhZdkpRnT7Ef12lklWi6GZL28PyV99xWs,726
|
@@ -110,11 +110,11 @@ nkululeko/segmenting/seg_pyannote.py,sha256=6IPbgjnGOz9juzEKDTZN3PSipX4t6Mz-DILA
|
|
110
110
|
nkululeko/segmenting/seg_silero.py,sha256=ulodnvtRq5MLHDxy_RmAK4tJg6h1d-mPq-uCPFkGVKg,4258
|
111
111
|
nkululeko/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
112
112
|
nkululeko/utils/files.py,sha256=SrrYaU7AB80MZHiV1jcB0h_zigvYLYgSVNTXV4ao38g,4593
|
113
|
-
nkululeko/utils/stats.py,sha256=
|
114
|
-
nkululeko/utils/util.py,sha256=
|
115
|
-
nkululeko-0.93.
|
116
|
-
nkululeko-0.93.
|
117
|
-
nkululeko-0.93.
|
118
|
-
nkululeko-0.93.
|
119
|
-
nkululeko-0.93.
|
120
|
-
nkululeko-0.93.
|
113
|
+
nkululeko/utils/stats.py,sha256=3Fyx8q8BSKYmiufT6OkRug9RATWmGrr9BaX_y8jziWo,3074
|
114
|
+
nkululeko/utils/util.py,sha256=J_dmqkOVAW63Q7IFUBj0BgygKzMXA0nORxY62-o8z_g,17360
|
115
|
+
nkululeko-0.93.15.dist-info/LICENSE,sha256=0zGP5B_W35yAcGfHPS18Q2B8UhvLRY3dQq1MhpsJU_U,1076
|
116
|
+
nkululeko-0.93.15.dist-info/METADATA,sha256=93FF7d1WXuyQwSPTMO-wCwHEcxEn1YiVMbm4TSObyYU,1148
|
117
|
+
nkululeko-0.93.15.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
118
|
+
nkululeko-0.93.15.dist-info/entry_points.txt,sha256=lNTkFEdh6Kjo5o95ZAWf_0Lq-4ztGoAoMVSDuPtuyS0,442
|
119
|
+
nkululeko-0.93.15.dist-info/top_level.txt,sha256=DPFNNSHPjUeVKj44dVANAjuVGRCC3MusJ08lc2a8xFA,10
|
120
|
+
nkululeko-0.93.15.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|