scipy.special.logit

scipy.special.logit(x) = <ufunc 'logit'>

用于ndarray的logit ufunc。

logit函数定义为logit(P)=log(p/(1-p))。请注意,当p<0或p>1时,logit(0)=-inf、logit(1)=inf和logit(P)生成NaN。

参数
xndarray

要将logit应用于逐个元素的ndarray。

退货
outndarray

与x形状相同的ndarray,它的项是x的相应项的logit。

参见

expit

注意事项

作为ufunc日志,它接受许多可选的关键字参数。有关详细信息,请参阅 ufuncs

0.10.0 新版功能.

示例

>>> from scipy.special import logit, expit
>>> logit([0, 0.25, 0.5, 0.75, 1])
array([       -inf, -1.09861229,  0.        ,  1.09861229,         inf])

expit 是与 logit

>>> expit(logit([0.1, 0.75, 0.999]))
array([ 0.1  ,  0.75 ,  0.999])

在中绘制x的logit(X)图 [0, 1] :

>>> import matplotlib.pyplot as plt
>>> x = np.linspace(0, 1, 501)
>>> y = logit(x)
>>> plt.plot(x, y)
>>> plt.grid()
>>> plt.ylim(-6, 6)
>>> plt.xlabel('x')
>>> plt.title('logit(x)')
>>> plt.show()
../../_images/scipy-special-logit-1.png