scipy.special.logit#

scipy.special.logit(x, out=None) = <ufunc 'logit'>#

ndarray 的 Logit ufunc。

logit 函數定義為 logit(p) = log(p/(1-p))。請注意,logit(0) = -inf,logit(1) = inf,且當 p<0 或 p>1 時,logit(p) 會產生 nan。

參數:
xndarray

要逐元素套用 logit 函數的 ndarray。

outndarray,選用

函數結果的選用輸出陣列

返回:
純量或 ndarray

與 x 形狀相同的 ndarray。其條目是 x 相應條目的 logit 值。

另請參閱

expit

註解

作為 ufunc,logit 接受許多選用關鍵字引數。如需更多資訊,請參閱 ufuncs

在版本 0.10.0 中新增。

範例

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

expitlogit 的反函數

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

繪製 x 在 [0, 1] 範圍內的 logit(x) 圖

>>> 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