Box-Cox変換

データサイエンス




Box-Cox変換

$$
x’ = \begin{cases}
\displaystyle \frac{x^\lambda – 1}{\lambda} & \lambda \neq 0\\
\log x & \lambda = 0\end{cases}
$$

Python

sklearn

#from sklearn
from sklearn.preprocessing import PowerTransformer
sk_boxcox = PowerTransformer('box-cox')

#lambda = sk_boxcox.lambdas_
boxcox_data = sk_boxcox.fit_transform(x)
inv_boxcox_data = sk_boxcox.inverse_transform(boxcox_data)

scipy

#from scipy
from scipy.stats import boxcox
from scipy.special import inv_boxcox

boxcox_data = boxcox(x)
inv_boxcox_data = inv_boxcox(boxcox_data)

参考

  1. https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.boxcox.html
  2. https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.inv_boxcox.html
  3. https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PowerTransformer.html#sklearn.preprocessing.PowerTransformer
タイトルとURLをコピーしました