nkululeko 0.93.13__py3-none-any.whl → 0.93.14__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 CHANGED
@@ -1,2 +1,2 @@
1
- VERSION="0.93.13"
1
+ VERSION="0.93.14"
2
2
  SAMPLING_RATE = 16000
@@ -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 nkululeko.glob_conf as glob_conf
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/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
- cats, cat_str, es = su.get_effect_size(plot_df, cat_col, cont_col)
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} ({cats}):" f" {es}"
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} ({cats}):" f" {es}"
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(df, target, variable):
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, 0
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[max_cat]
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(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: nkululeko
3
- Version: 0.93.13
3
+ Version: 0.93.14
4
4
  Summary: Machine learning audio prediction experiments based on templates
5
5
  Home-page: https://github.com/felixbur/nkululeko
6
6
  Author: Felix Burkhardt
@@ -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=B_SoEW_E21VyJqFUyh_XG4GvVYNPEsgUF31slyJ2fFY,40
5
+ nkululeko/constants.py,sha256=o5ER1luWQ6hCEUmTnLGYzK-uGjv9VCnzzDYq2KIxo0o,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
@@ -20,7 +20,7 @@ nkululeko/modelrunner.py,sha256=lJy-xM4QfDDWeL0dLTE_VIb4sYrnd_Z_yJRK3wwohQA,1119
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=2G5yNR3Q3qWDt8ncKwKUZBLE-O1rbGUiG6omwfFudVk,26138
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=p2b4eS5R2Q5zdOIc56NRRU2PTFXSRt0qrdHGafHkWKo,4830
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
@@ -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=vCRzhCR0Gx5SiJyAGbj1TIto8ocGz58CM5Pr3LltagA,2948
114
- nkululeko/utils/util.py,sha256=wFDslqxpCVDwi6LBakIFDDy1kYsxt5G7ykE38CocmtA,16880
115
- nkululeko-0.93.13.dist-info/LICENSE,sha256=0zGP5B_W35yAcGfHPS18Q2B8UhvLRY3dQq1MhpsJU_U,1076
116
- nkululeko-0.93.13.dist-info/METADATA,sha256=G0DPQrKRoSO4lB0NjR5hjc715sggueUA3lcokR1NyUQ,1148
117
- nkululeko-0.93.13.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
118
- nkululeko-0.93.13.dist-info/entry_points.txt,sha256=lNTkFEdh6Kjo5o95ZAWf_0Lq-4ztGoAoMVSDuPtuyS0,442
119
- nkululeko-0.93.13.dist-info/top_level.txt,sha256=DPFNNSHPjUeVKj44dVANAjuVGRCC3MusJ08lc2a8xFA,10
120
- nkululeko-0.93.13.dist-info/RECORD,,
113
+ nkululeko/utils/stats.py,sha256=3Fyx8q8BSKYmiufT6OkRug9RATWmGrr9BaX_y8jziWo,3074
114
+ nkululeko/utils/util.py,sha256=J_dmqkOVAW63Q7IFUBj0BgygKzMXA0nORxY62-o8z_g,17360
115
+ nkululeko-0.93.14.dist-info/LICENSE,sha256=0zGP5B_W35yAcGfHPS18Q2B8UhvLRY3dQq1MhpsJU_U,1076
116
+ nkululeko-0.93.14.dist-info/METADATA,sha256=2cqjRLPed00dMPGG8SDMHG9k0w1gx0bItfrYsGk4rR4,1148
117
+ nkululeko-0.93.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
118
+ nkululeko-0.93.14.dist-info/entry_points.txt,sha256=lNTkFEdh6Kjo5o95ZAWf_0Lq-4ztGoAoMVSDuPtuyS0,442
119
+ nkululeko-0.93.14.dist-info/top_level.txt,sha256=DPFNNSHPjUeVKj44dVANAjuVGRCC3MusJ08lc2a8xFA,10
120
+ nkululeko-0.93.14.dist-info/RECORD,,