本文整理汇总了Python中scipy.stats.iqr方法的典型用法代码示例。如果您正苦于以下问题:Python stats.iqr方法的具体用法?Python stats.iqr怎么用?Python stats.iqr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.iqr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _check_params
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def _check_params(n_iter, dis_measure, random_state):
"""Internal function to check for and validate class parameters.
Also, to return random state instance and the appropriate dissimilarity
measure if valid.
"""
if isinstance(n_iter, int):
check_parameter(n_iter, low=1, param_name='n_iter')
else:
raise TypeError("n_iter should be int, got %s" % n_iter)
if isinstance(dis_measure, str):
if dis_measure not in ('aad', 'var', 'iqr'):
raise ValueError("Unknown dissimilarity measure type, "
"dis_measure should be in "
"(\'aad\', \'var\', \'iqr\'), "
"got %s" % dis_measure)
# TO-DO: 'mad': Median Absolute Deviation to be added
# once Scipy stats version 1.3.0 is released
else:
raise TypeError("dis_measure should be str, got %s" % dis_measure)
return check_random_state(random_state), _aad if dis_measure == 'aad' \
else (np.var if dis_measure == 'var'
else (stats.iqr if dis_measure == 'iqr' else None))
示例2: std_iqr
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def std_iqr(x):
"""Robust estimation of the standard deviation, based on the inter-quartile
(IQR) distance of x.
This computes the IQR of x, and applies the Gaussian distribution
correction, making it a consistent estimator of the standard-deviation
(when the sample looks Gaussian with outliers).
Parameters
----------
x : `np.ndarray`
Input vector
Returns
-------
output : `float`
A robust estimation of the standard deviation
"""
from scipy.stats import iqr
from scipy.special import erfinv
correction = 2 ** 0.5 * erfinv(0.5)
return correction * iqr(x)
示例3: test_constant
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_constant(self):
# Constant array always gives 0
x = np.ones((7, 4))
assert_equal(stats.iqr(x), 0.0)
assert_array_equal(stats.iqr(x, axis=0), np.zeros(4))
assert_array_equal(stats.iqr(x, axis=1), np.zeros(7))
# Even for older versions, 'linear' does not raise a warning
with _numpy_version_warn_context_mgr('1.9.0a', RuntimeWarning, 4):
assert_equal(stats.iqr(x, interpolation='linear'), 0.0)
assert_equal(stats.iqr(x, interpolation='midpoint'), 0.0)
assert_equal(stats.iqr(x, interpolation='nearest'), 0.0)
assert_equal(stats.iqr(x, interpolation='lower'), 0.0)
assert_equal(stats.iqr(x, interpolation='higher'), 0.0)
# 0 only along constant dimensions
# This also tests much of `axis`
y = np.ones((4, 5, 6)) * np.arange(6)
assert_array_equal(stats.iqr(y, axis=0), np.zeros((5, 6)))
assert_array_equal(stats.iqr(y, axis=1), np.zeros((4, 6)))
assert_array_equal(stats.iqr(y, axis=2), 2.5 * np.ones((4, 5)))
assert_array_equal(stats.iqr(y, axis=(0, 1)), np.zeros(6))
assert_array_equal(stats.iqr(y, axis=(0, 2)), 3. * np.ones(5))
assert_array_equal(stats.iqr(y, axis=(1, 2)), 3. * np.ones(4))
示例4: _rs
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def _rs(data, axis=0):
"""
Normalizes `data` with a robust sigmoid function
Parameters
----------
data : array_like
Input data array to be transformed
axis : int, optional
Axis of `data` to be normalized
Returns
-------
normed : array_like
Normalized input `data`
"""
data = np.asanyarray(data)
# calculate sigmoid normalization
med = np.median(data, axis=axis, keepdims=True)
iqr = sstats.iqr(data, axis=axis, scale='normal', keepdims=True)
normed = 1 / (1 + np.exp(-(data - med) / iqr))
return normed
示例5: add_features_in_group
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def add_features_in_group(features, gr_, feature_name, aggs, prefix):
for agg in aggs:
if agg == 'sum':
features['{}{}_sum'.format(prefix, feature_name)] = gr_[feature_name].sum()
elif agg == 'mean':
features['{}{}_mean'.format(prefix, feature_name)] = gr_[feature_name].mean()
elif agg == 'max':
features['{}{}_max'.format(prefix, feature_name)] = gr_[feature_name].max()
elif agg == 'min':
features['{}{}_min'.format(prefix, feature_name)] = gr_[feature_name].min()
elif agg == 'std':
features['{}{}_std'.format(prefix, feature_name)] = gr_[feature_name].std()
elif agg == 'count':
features['{}{}_count'.format(prefix, feature_name)] = gr_[feature_name].count()
elif agg == 'skew':
features['{}{}_skew'.format(prefix, feature_name)] = skew(gr_[feature_name])
elif agg == 'kurt':
features['{}{}_kurt'.format(prefix, feature_name)] = kurtosis(gr_[feature_name])
elif agg == 'iqr':
features['{}{}_iqr'.format(prefix, feature_name)] = iqr(gr_[feature_name])
elif agg == 'median':
features['{}{}_median'.format(prefix, feature_name)] = gr_[feature_name].median()
return features
示例6: test_basic
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_basic(self):
x = np.arange(8) * 0.5
np.random.shuffle(x)
assert_equal(stats.iqr(x), 1.75)
示例7: test_api
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_api(self):
d = np.ones((5, 5))
stats.iqr(d)
stats.iqr(d, None)
stats.iqr(d, 1)
stats.iqr(d, (0, 1))
stats.iqr(d, None, (10, 90))
stats.iqr(d, None, (30, 20), 'raw')
stats.iqr(d, None, (25, 75), 1.5, 'propagate')
if NumpyVersion(np.__version__) >= '1.9.0a':
stats.iqr(d, None, (50, 50), 'normal', 'raise', 'linear')
stats.iqr(d, None, (25, 75), -0.4, 'omit', 'lower', True)
示例8: test_empty
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_empty(self):
assert_equal(stats.iqr([]), np.nan)
assert_equal(stats.iqr(np.arange(0)), np.nan)
示例9: test_scalarlike
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_scalarlike(self):
x = np.arange(1) + 7.0
assert_equal(stats.iqr(x[0]), 0.0)
assert_equal(stats.iqr(x), 0.0)
if NumpyVersion(np.__version__) >= '1.9.0a':
assert_array_equal(stats.iqr(x, keepdims=True), [0.0])
else:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
assert_array_equal(stats.iqr(x, keepdims=True), 0.0)
_check_warnings(w, RuntimeWarning, 1)
示例10: test_rng
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_rng(self):
x = np.arange(5)
assert_equal(stats.iqr(x), 2)
assert_equal(stats.iqr(x, rng=(25, 87.5)), 2.5)
assert_equal(stats.iqr(x, rng=(12.5, 75)), 2.5)
assert_almost_equal(stats.iqr(x, rng=(10, 50)), 1.6) # 3-1.4
assert_raises(ValueError, stats.iqr, x, rng=(0, 101))
assert_raises(ValueError, stats.iqr, x, rng=(np.nan, 25))
assert_raises(TypeError, stats.iqr, x, rng=(0, 50, 60))
示例11: test_keepdims
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def test_keepdims(self):
numpy_version = NumpyVersion(np.__version__)
# Also tests most of `axis`
x = np.ones((3, 5, 7, 11))
assert_equal(stats.iqr(x, axis=None, keepdims=False).shape, ())
assert_equal(stats.iqr(x, axis=2, keepdims=False).shape, (3, 5, 11))
assert_equal(stats.iqr(x, axis=(0, 1), keepdims=False).shape, (7, 11))
assert_equal(stats.iqr(x, axis=(0, 3), keepdims=False).shape, (5, 7))
assert_equal(stats.iqr(x, axis=(1,), keepdims=False).shape, (3, 7, 11))
assert_equal(stats.iqr(x, (0, 1, 2, 3), keepdims=False).shape, ())
assert_equal(stats.iqr(x, axis=(0, 1, 3), keepdims=False).shape, (7,))
if numpy_version >= '1.9.0a':
assert_equal(stats.iqr(x, axis=None, keepdims=True).shape, (1, 1, 1, 1))
assert_equal(stats.iqr(x, axis=2, keepdims=True).shape, (3, 5, 1, 11))
assert_equal(stats.iqr(x, axis=(0, 1), keepdims=True).shape, (1, 1, 7, 11))
assert_equal(stats.iqr(x, axis=(0, 3), keepdims=True).shape, (1, 5, 7, 1))
assert_equal(stats.iqr(x, axis=(1,), keepdims=True).shape, (3, 1, 7, 11))
assert_equal(stats.iqr(x, (0, 1, 2, 3), keepdims=True).shape, (1, 1, 1, 1))
assert_equal(stats.iqr(x, axis=(0, 1, 3), keepdims=True).shape, (1, 1, 7, 1))
else:
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
assert_equal(stats.iqr(x, axis=None, keepdims=True).shape, ())
assert_equal(stats.iqr(x, axis=2, keepdims=True).shape, (3, 5, 11))
assert_equal(stats.iqr(x, axis=(0, 1), keepdims=True).shape, (7, 11))
assert_equal(stats.iqr(x, axis=(0, 3), keepdims=True).shape, (5, 7))
assert_equal(stats.iqr(x, axis=(1,), keepdims=True).shape, (3, 7, 11))
assert_equal(stats.iqr(x, (0, 1, 2, 3), keepdims=True).shape, ())
assert_equal(stats.iqr(x, axis=(0, 1, 3), keepdims=True).shape, (7,))
_check_warnings(w, RuntimeWarning, 7)
示例12: median_similarity
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def median_similarity(self, column, tolerance=2):
new_median = float(np.median(self.new_data[column]))
old_median = float(np.median(self.historical_data[column]))
iqr = float(stats.iqr(self.historical_data[column]))
upper_bound = old_median + (iqr * tolerance)
lower_bound = old_median - (iqr * tolerance)
if new_median < lower_bound:
return False
elif new_median > upper_bound:
return False
else:
return True
示例13: describe_scores
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def describe_scores(self, scores, method):
"""
Describes scores.
Parameters
----------
scores : array-like
the scores from the model, as a list or numpy array
method : string
the method to use to calculate central tendency and spread
Returns
-------
Returns the central tendency, and spread
by method.
Methods:
mean:
* central tendency: mean
* spread: standard deviation
median:
* central tendency: median
* spread: interquartile range
trimean:
* central tendency: trimean
* spread: trimean absolute deviation
"""
if method == "mean":
return np.mean(scores), np.std(scores)
elif method == "median":
return np.median(scores), stats.iqr(scores)
elif method == "trimean":
return self.trimean(scores), self.trimean_absolute_deviation(scores)
示例14: _mixedsig
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def _mixedsig(data, low=0, high=1, axis=0):
"""
Uses `_scaledsig()` if IQR is 0; otherwise, uses `_srs()`
Parameters
----------
data : array_like
Input data array to be transformed
low : float, optional
Lower bound for rescaling. Default: 0
high : float, optional
Upper bound for rescaling. Default: 1
axis : int, optional
Axis of `data` to be normalized
Returns
-------
normed : array_like
Normalized input `data`
"""
data = np.asanyarray(data)
iqr = sstats.iqr(data, axis=axis, scale='normal')
mask = iqr == 0
normed = np.zeros_like(data)
normed[:, mask] = _scaledsig(data[:, mask])
normed[:, ~mask] = _srs(data[:, ~mask])
# constant columns set to 0
return np.nan_to_num(normed)
示例15: find_bad_by_deviation
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import iqr [as 别名]
def find_bad_by_deviation(self, deviation_thresh=3.29053):
"""Detect channels that contain extreme amplitudes.
This function is working on robust z-scores. You might want to
select the thresholds according to how much of the data is expected
to fall within the absolute bounds:
95.0% --> 1.95996
97.0% --> 2.17009
99.0% --> 2.57583
99.9% --> 3.29053
Parameters
----------
deviation_thresh : float
Channels with a higher amplitude z-score than `deviation_thresh`
will be considered bad_by_deviation.
"""
# Calculate robust z-score of robust standard deviation for each chan
chn_devi = 0.7413 * iqr(self.x, axis=1)
chn_devi_sd = 0.7413 * iqr(chn_devi, axis=0)
chn_devi_median = np.median(chn_devi)
robust_chn_devi = (chn_devi - chn_devi_median) / chn_devi_sd
# z-scores exceeding our theshold are classified as bad
bad_idxs_bool = np.abs(robust_chn_devi) > deviation_thresh
bad_idxs = np.argwhere(bad_idxs_bool)
bads = self.ch_names[bad_idxs.astype(int)]
bads = [i[0] for i in bads]
bads.sort()
self.bad_by_deviation = bads
self._channel_deviations = robust_chn_devi
return None