本文整理汇总了Python中scipy.stats.zscore方法的典型用法代码示例。如果您正苦于以下问题:Python stats.zscore方法的具体用法?Python stats.zscore怎么用?Python stats.zscore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.stats
的用法示例。
在下文中一共展示了stats.zscore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zscore_axis
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def test_zscore_axis(self):
# Test use of 'axis' keyword in zscore.
x = np.array([[0.0, 0.0, 1.0, 1.0],
[1.0, 1.0, 1.0, 2.0],
[2.0, 0.0, 2.0, 0.0]])
t1 = 1.0/np.sqrt(2.0/3)
t2 = np.sqrt(3.)/3
t3 = np.sqrt(2.)
z0 = stats.zscore(x, axis=0)
z1 = stats.zscore(x, axis=1)
z0_expected = [[-t1, -t3/2, -t3/2, 0.0],
[0.0, t3, -t3/2, t1],
[t1, -t3/2, t3, -t1]]
z1_expected = [[-1.0, -1.0, 1.0, 1.0],
[-t2, -t2, -t2, np.sqrt(3.)],
[1.0, -1.0, 1.0, -1.0]]
assert_array_almost_equal(z0, z0_expected)
assert_array_almost_equal(z1, z1_expected)
示例2: get_external_state
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def get_external_state(self):
# Use Hi-Low median as signal:
x = (
np.frombuffer(self.data.high.get(size=self.time_dim)) +
np.frombuffer(self.data.low.get(size=self.time_dim))
) / 2
# Differences along time dimension:
d_x = np.gradient(x, axis=0) * self.p.cwt_signal_scale
# Compute continuous wavelet transform using Ricker wavelet:
cwt_x = signal.cwt(d_x, signal.ricker, self.cwt_width).T
# Note: differences taken once again along channels axis,
# apply weighted scaling to normalize channels
norm_x = np.gradient(cwt_x, axis=-1)
norm_x = zscore(norm_x, axis=0) * self.p.state_ext_scale
#out_x = tanh(norm_x)
out_x = np.clip(norm_x, -10, 10)
return out_x[:, None, :]
示例3: test_zscore
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def test_zscore(self):
for n in self.get_n():
x, y, xm, ym = self.generate_xy_sample(n)
#reference solution
zx = (x - x.mean()) / x.std()
zy = (y - y.mean()) / y.std()
#validate stats
assert_allclose(stats.zscore(x), zx, rtol=1e-10)
assert_allclose(stats.zscore(y), zy, rtol=1e-10)
#compare stats and mstats
assert_allclose(stats.zscore(x), stats.mstats.zscore(xm[0:len(x)]),
rtol=1e-10)
assert_allclose(stats.zscore(y), stats.mstats.zscore(ym[0:len(y)]),
rtol=1e-10)
示例4: efficient_corr
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def efficient_corr(x, y):
"""
Computes correlation of matching columns in `x` and `y`
Parameters
----------
x, y : (N, M) array_like
Input data arrays
Returns
-------
corr : (M,) numpy.ndarray
Correlations of columns in `x` and `y`
"""
corr = np.sum(zscore(x, ddof=1) * zscore(y, ddof=1), axis=0) / (len(x) - 1)
return corr
示例5: neural_sorting
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def neural_sorting(self,i):
if i==0:
self.isort = np.argsort(self.u[:,int(self.PCedit.text())-1])
elif i==1:
self.isort = self.isort1
if i<2:
self.spF = gaussian_filter1d(self.sp[np.ix_(self.isort,self.tsort)].T,
np.minimum(8,np.maximum(1,int(self.sp.shape[0]*0.005))),
axis=1)
self.spF = self.spF.T
else:
self.spF = self.sp
self.spF = zscore(self.spF, axis=1)
self.spF = np.minimum(8, self.spF)
self.spF = np.maximum(-4, self.spF) + 4
self.spF /= 12
self.img.setImage(self.spF)
self.ROI_position()
示例6: ks_refine
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def ks_refine(varr, seeds, sig=0.05):
print("selecting seeds")
varr_sub = varr.sel(
spatial=[tuple(hw) for hw in seeds[['height', 'width']].values])
print("performing KS test")
ks = xr.apply_ufunc(
lambda x: kstest(zscore(x), 'norm')[1],
varr_sub.chunk(dict(frame=-1, spatial='auto')),
input_core_dims=[['frame']],
vectorize=True,
dask='parallelized',
output_dtypes=[float])
mask = ks < sig
mask_df = mask.to_pandas().rename('mask_ks').reset_index()
seeds = pd.merge(seeds, mask_df, on=['height', 'width'], how='left')
return seeds
示例7: center
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def center(X):
r"""
Subtracts the row means and divides by the row standard deviations.
Then subtracts column means.
Parameters
----------
X : array-like, shape (n_observations, n_features)
The data to preprocess
Returns
-------
centered_X : preprocessed data matrix
"""
# Mean along rows using sample mean and sample std
centered_X = stats.zscore(X, axis=1, ddof=1)
# Mean along columns
mu = np.mean(centered_X, axis=0)
centered_X -= mu
return centered_X
示例8: score
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def score(self, Z, U, zscore=False):
"""
Compute classification error on test set.
Parameters
----------
Z : array
new data set (M samples x D features)
zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns
-------
preds : array
label predictions (M samples x 1)
"""
# If classifier is trained, check for same dimensionality
if self.is_trained:
if not self.train_data_dim == Z.shape[1]:
raise ValueError("""Test data is of different dimensionality
than training data.""")
# Make predictions
preds = self.predict(Z, zscore=zscore)
# Compute error
return np.mean(preds != U)
示例9: predict
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def predict(self, Z, zscore=False):
"""
Make predictions on new dataset.
Parameters
----------
Z : array
new data set (M samples x D features)
zscore : boolean
whether to transform the data using z-scoring (def: false)
Returns
-------
preds : array
label predictions (M samples x 1)
"""
# If classifier is trained, check for same dimensionality
if self.is_trained:
if not self.train_data_dim == Z.shape[1]:
raise ValueError("""Test data is of different dimensionality
than training data.""")
# Call predict_proba() for posterior probabilities
probs = self.predict_proba(Z, zscore=zscore)
# Take maximum over classes for indexing class list
preds = self.K[np.argmax(probs, axis=1)]
# Return predictions array
return preds
示例10: get_outliers
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def get_outliers(self, y):
return absolute(zscore(y)) > self.threshold
示例11: randmvn
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def randmvn(rho, size=(1, 2), standardize=False):
'''create random draws from equi-correlated multivariate normal distribution
Parameters
----------
rho : float
correlation coefficient
size : tuple of int
size is interpreted (nobs, nvars) where each row
Returns
-------
rvs : ndarray
nobs by nvars where each row is a independent random draw of nvars-
dimensional correlated rvs
'''
nobs, nvars = size
if 0 < rho and rho < 1:
rvs = np.random.randn(nobs, nvars+1)
rvs2 = rvs[:,:-1] * np.sqrt((1-rho)) + rvs[:,-1:] * np.sqrt(rho)
elif rho ==0:
rvs2 = np.random.randn(nobs, nvars)
elif rho < 0:
if rho < -1./(nvars-1):
raise ValueError('rho has to be larger than -1./(nvars-1)')
elif rho == -1./(nvars-1):
rho = -1./(nvars-1+1e-10) #barely positive definite
#use Cholesky
A = rho*np.ones((nvars,nvars))+(1-rho)*np.eye(nvars)
rvs2 = np.dot(np.random.randn(nobs, nvars), np.linalg.cholesky(A).T)
if standardize:
rvs2 = stats.zscore(rvs2)
return rvs2
#============================
#
# Part 2: Multiple comparisons and independent samples tests
#
#============================
示例12: test_standardize1
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def test_standardize1():
np.random.seed(123)
x = 1 + np.random.randn(5, 4)
transf = StandardizeTransform(x)
xs1 = transf(x)
assert_allclose(transf.mean, x.mean(0), rtol=1e-13)
assert_allclose(transf.scale, x.std(0, ddof=1), rtol=1e-13)
xs2 = stats.zscore(x, ddof=1)
assert_allclose(xs1, xs2, rtol=1e-13, atol=1e-20)
# check we use stored transformation
xs4 = transf(2 * x)
assert_allclose(xs4, (2*x - transf.mean) / transf.scale, rtol=1e-13, atol=1e-20)
# affine transform doesn't change standardized
x2 = 2 * x + np.random.randn(4)
transf2 = StandardizeTransform(x2)
xs3 = transf2(x2)
assert_allclose(xs3, xs1, rtol=1e-13, atol=1e-20)
# check constant
x5 = np.column_stack((np.ones(x.shape[0]), x))
transf5 = StandardizeTransform(x5)
xs5 = transf5(x5)
assert_equal(transf5.const_idx, 0)
assert_equal(xs5[:, 0], np.ones(x.shape[0]))
assert_allclose(xs5[:, 1:], xs1, rtol=1e-13, atol=1e-20)
示例13: get_external_state
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def get_external_state(self):
# Use Hi-Low median as signal:
x = (
np.frombuffer(self.data.high.get(size=self.time_dim)) +
np.frombuffer(self.data.low.get(size=self.time_dim))
) / 2
# Differences along time dimension:
d_x = np.gradient(x, axis=0) * self.p.cwt_signal_scale
# Compute continuous wavelet transform using Ricker wavelet:
cwt_x = signal.cwt(d_x, signal.ricker, self.cwt_width).T
norm_x = cwt_x
# Note: differences taken once again along channels axis,
# apply weighted scaling to normalize channels
# norm_x = np.gradient(cwt_x, axis=-1)
# norm_x = zscore(norm_x, axis=0) * self.p.state_ext_scale
# norm_x *= self.p.state_ext_scale
out_x = tanh(norm_x)
# out_x = np.clip(norm_x, -10, 10)
# return out_x[:, None, :]
return out_x[..., None]
示例14: get_external_2_state
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def get_external_2_state(self):
x = np.stack(
[
np.frombuffer(self.data.high.get(size=self.time_dim)),
np.frombuffer(self.data.open.get(size=self.time_dim)),
np.frombuffer(self.data.low.get(size=self.time_dim)),
np.frombuffer(self.data.close.get(size=self.time_dim)),
],
axis=-1
)
# # Differences along features dimension:
d_x = np.gradient(x, axis=-1) * self.p.cwt_signal_scale
# Compute continuous wavelet transform using Ricker wavelet:
# cwt_x = signal.cwt(d_x, signal.ricker, self.cwt_width).T
norm_x = d_x
# Note: differences taken once again along channels axis,
# apply weighted scaling to normalize channels
# norm_x = np.gradient(cwt_x, axis=-1)
# norm_x = zscore(norm_x, axis=0) * self.p.state_ext_scale
# norm_x *= self.p.state_ext_scale
out_x = tanh(norm_x)
# out_x = np.clip(norm_x, -10, 10)
return out_x[:, None, :]
示例15: get_single_external_state
# 需要导入模块: from scipy import stats [as 别名]
# 或者: from scipy.stats import zscore [as 别名]
def get_single_external_state(self, key):
# Use Hi-Low median as signal:
x = (
np.frombuffer(self.data_streams[key].high.get(size=self.time_dim)) +
np.frombuffer(self.data_streams[key].low.get(size=self.time_dim))
) / 2
# Differences along time dimension:
d_x = np.gradient(x, axis=0) * self.p.cwt_signal_scale
# Compute continuous wavelet transform using Ricker wavelet:
cwt_x = signal.cwt(d_x, signal.ricker, self.cwt_width).T
norm_x = cwt_x
# Note: differences taken once again along channels axis,
# apply weighted scaling to normalize channels
# norm_x = np.gradient(cwt_x, axis=-1)
# norm_x = zscore(norm_x, axis=0) * self.p.state_ext_scale
norm_x *= self.p.state_ext_scale[key]
out_x = tanh(norm_x)
# out_x = np.clip(norm_x, -10, 10)
# return out_x[:, None, :]
return out_x[:, None, :]