python boxcox_Python stats.boxcox方法代码示例

本文整理汇总了Python中scipy.stats.boxcox方法的典型用法代码示例。如果您正苦于以下问题:Python stats.boxcox方法的具体用法?Python stats.boxcox怎么用?Python stats.boxcox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块scipy.stats的用法示例。

在下文中一共展示了stats.boxcox方法的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: _estimate_lambda_single_y

​点赞 6

# 需要导入模块: from scipy import stats [as 别名]

# 或者: from scipy.stats import boxcox [as 别名]

def _estimate_lambda_single_y(y):

"""Estimate lambda for a single y, given a range of lambdas

through which to search. No validation performed.

Parameters

----------

y : ndarray, shape (n_samples,)

The vector being estimated against

"""

# ensure is array

y = np.array(y)

# Use scipy's log-likelihood estimator

b = boxcox(y, lmbda=None)

# Return lambda corresponding to maximum P

return b[1]

开发者ID:tgsmith61591,项目名称:skutil,代码行数:21,

示例2: _yeo_johnson_optimize

​点赞 6

# 需要导入模块: from scipy import stats [as 别名]

# 或者: from scipy.stats import boxcox [as 别名]

def _yeo_johnson_optimize(self, x):

"""Find and return optimal lambda parameter of the Yeo-Johnson

transform by MLE, for observed data x.

Like for Box-Cox, MLE is done via the brent optimizer.

"""

def _neg_log_likelihood(lmbda):

"""Return the negative log likelihood of the observed data x as a

function of lambda."""

x_trans = self._yeo_johnson_transform(x, lmbda)

n_samples = x.shape[0]

loglike = -n_samples / 2 * np.log(x_trans.var())

loglike += (lmbda - 1) * (np.sign(x) * np.log1p(np.abs(x))).sum()

return -loglike

# the computation of lambda is influenced by NaNs so we need to

# get rid of them

x = x[~np.isnan(x)]

# choosing bracket -2, 2 like for boxcox

return optimize.brent(_neg_log_likelihood, brack=(-2, 2))

开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:25,

示例3: test_power_transformer_1d

​点赞 6

# 需要导入模块: from scipy import stats [as 别名]

# 或者: from scipy.stats import boxcox [as 别名]

def test_power_transformer_1d():

X = np.abs(X_1col)

for standardize in [True, False]:

pt = PowerTransformer(method='box-cox', standardize=standardize)

X_trans = pt.fit_transform(X)

X_trans_func = power_transform(

X, method='box-cox',

standardize=standardize

)

X_expected, lambda_expected = stats.boxcox(X.flatten())

if standardize:

X_expected = scale(X_expected)

assert_almost_equal(X_expected.reshape(-1, 1), X_trans)

assert_almost_equal(X_expected.reshape(-1, 1), X_trans_func)

assert_almost_equal(X, pt.inverse_transform(X_trans))

assert_almost_equal(lambda_expected, pt.lambdas_[0])

assert len(pt.lambdas_) == X.shape[1]

assert isinstance(pt.lambdas_, np.ndarray)

开发者ID:PacktPublishing,项目名称:Mastering-Elasticsearch-7.0,代码行数:27,

示例4: test_alpha

​点赞 6

# 需要导入模块: from scipy import stats [as 别名]

# 或者: from scipy.stats import boxcox [as 别名]

def test_alpha(self):

np.random.seed(1234)

x = stats.loggamma.rvs(5, size=50) + 5

# Some regular values for alpha, on a small sample size

_, _, interval = stats.boxcox(x, alpha=0.75)

assert_allclose(interval, [4.004485780226041, 5.138756355035744])

_, _, interval = stats.boxcox(x, alpha=0.05)

assert_allclose(interval, [1.2138178554857557, 8.209033272375663])

# Try some extreme values, see we don't hit the N=500 limit

x = stats.loggamma.rvs(7, size=500) + 15

_, _, interval = stats.boxcox(x, alpha=0.001)

assert_allclose(interval, [0.3988867, 11.40553131])

_, _, interval = stats.boxcox(x, alpha=0.999)

assert_allclose(interval, [5.83316246, 5.83735292])

开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:18,

示例5: fit

​点赞 6

# 需要导入模块: from scipy import stats [as 别名]

# 或者: from scipy.stats import boxcox [as 别名]

def fit(self, x: np.ndarray, y=None):

"""Fit a Gaussianizing transformation to each variable/column in x."""

# Initialize coefficients again with an empty list. Otherwise

# calling .fit() repeatedly will augment previous .coefs_ list.

self.coefs_ = []

x = _update_x(x)

if self.verbose:

print("Gaussianizing with strategy='%s'" % self.strategy)

if self.strategy == "lambert":

_get_coef = lambda vec: igmm(vec, self.tol, max_iter=self.max_iter)

elif self.strategy == "brute":

_get_coef = lambda vec: None # TODO: In principle, we could store parameters to do a quasi-invert

elif self.strategy == "boxcox":

_get_coef = lambda vec: boxcox(vec)[1]

else:

raise NotImplementedError("stategy='%s' no

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值