Skip to content

Commit 28a2e6e

Browse files
OWFeatureStatistics: Fixup warnings when calculating dispersion
1 parent ac534ea commit 28a2e6e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Orange/widgets/data/owfeaturestatistics.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def _categorical_entropy(x):
3939
return np.fromiter((ss.entropy(pk) for pk in p), dtype=np.float64)
4040

4141

42+
def coefficient_of_variation(x: np.ndarray) -> np.ndarray:
43+
mu = ut.nanmean(x, axis=0)
44+
mask = ~np.isclose(mu, 0, atol=1e-12)
45+
result = np.full_like(mu, fill_value=np.inf)
46+
result[mask] = np.sqrt(ut.nanvar(x, axis=0)[mask]) / mu[mask]
47+
return result
48+
49+
4250
def format_time_diff(start, end, round_up_after=2):
4351
"""Return an approximate human readable time difference between two dates.
4452
@@ -228,7 +236,7 @@ def __compute_statistics(self):
228236
self._dispersion = self.__compute_stat(
229237
matrices,
230238
discrete_f=_categorical_entropy,
231-
continuous_f=lambda x: np.sqrt(ut.nanvar(x, axis=0)) / ut.nanmean(x, axis=0),
239+
continuous_f=coefficient_of_variation,
232240
)
233241
self._missing = self.__compute_stat(
234242
matrices,

0 commit comments

Comments
 (0)