I have data of the form:
X Y
3.53 0
4.93 50
5.53 60
6.21 70
7.37 80
9.98 90
16.56 100
And I want to find out n so that this can be fit to a function of the form:
I am trying to determine n by Box-Cox transformation. How can this be done in Python?
I think you want scipy.stats.boxcox.
from scipy import stats
import numpy as np
data = np.fromstring('3.53 0 4.93 50 5.53 60 6.21 70 7.37 80 9.98 90 16.56 100', sep=' ').reshape(7, 2)
stats.boxcox(data[0,])
(array([ 0.91024309, 1.06300488, 1.10938333, 1.15334193, 1.213348 ,
1.30668122, 1.43178909]), -0.54874593147877893)
For Box-Cox Transformation in Python you must follow below steps:-
from scipy.stats import boxcox
from scipy.special import inv_boxcox
y =[10,20,30,40,50]
y,fitted_lambda= boxcox(y,lmbda=None)
inv_boxcox(y,fitted_lambda)
in scipy.special
package box-cox
method is present but that expect lambda
explicitly.Hence i used box-cox from scipy.stats
and inv_box-cox from special as inv_boxcox not available in scipy.stats.
Box-Cox of 1+x may be helpful in cases with zeros(boxcox1p)
from scipy.special import boxcox1p
boxcox1p([0.01, 0.1], 0.25)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With