def test_nanmode(self): X = np.array([[np.nan, np.nan, 1, 1], [2, np.nan, 1, 1]]) mode, count = nanmode(X, 0) np.testing.assert_array_equal(mode, [[2, np.nan, 1, 1]]) np.testing.assert_array_equal(count, [[1, np.nan, 2, 2]]) mode, count = nanmode(X, 1) np.testing.assert_array_equal(mode, [[1], [1]]) np.testing.assert_array_equal(count, [[2], [2]])
def test_nanmode(self): X = np.array([[np.nan, np.nan, 1, 1], [2, np.nan, 1, 1]]) mode, count = nanmode(X, 0) np.testing.assert_array_equal(mode, [[2, np.nan, 1, 1]]) np.testing.assert_array_equal(count, [[1, np.nan, 2, 2]]) mode, count = nanmode(X, 1) np.testing.assert_array_equal(mode, [[1], [1]]) np.testing.assert_array_equal(count, [[2], [2]])
def __mode(x, *args, **kwargs): if sp.issparse(x): x = x.todense(order="C") # return ss.mode(x, *args, **kwargs)[0] return ut.nanmode( x, *args, **kwargs)[0] # Temporary replacement for scipy < 1.2.0
def aggregate( var: Variable, data: np.ndarray, groupindices: Sequence[Sequence[int]], ) -> np.ndarray: if var.is_string: join = lambda values: (join_elided(", ", 42, values, " ({} more)")) # collect all original labels for every merged row values = [data[indices] for indices in groupindices] data = [join(list(map(var.str_val, vals))) for vals in values] return np.array(data, dtype=object) elif var.is_continuous: data = [ np.nanmean(data[indices]) if len(indices) else np.nan for indices in groupindices ] return np.array(data, dtype=float) elif var.is_discrete: from Orange.statistics.util import nanmode data = [ nanmode(data[indices])[0] if len(indices) else np.nan for indices in groupindices ] return np.asarray(data, dtype=float) else: raise TypeError(type(var))
def __mode(x, *args, **kwargs): if sp.issparse(x): x = x.todense(order="C") # return ss.mode(x, *args, **kwargs)[0] return ut.nanmode(x, *args, **kwargs)[0] # Temporary replacement for scipy