我在数据框中有非正态分布,如图片 我试图通过使用 box-cox 方法获得正态分布,代码如下:
from sklearn.preprocessing import PowerTransformer
scaler = MinMaxScaler(feature_range=(1, 2))
scaler.fit(data)
data= scaler.transform(data)
#instatiate
pt = PowerTransformer(method='box-cox')
#Fit the data to the powertransformer
box_cox = pt.fit(data)
#Lets get the Lambdas that were found
print (box_cox.lambdas_)
calc_lambdas = box_cox.lambdas_
#Transform the data
box_cox = pt.transform(data)
#Pass the transformed data into a new dataframe
names= df.iloc[:,0:-1].columns
df_xt = pd.DataFrame(data=box_cox, columns=names)
df_xt.head()