我必须生成一个正常的分数转换。 可以使用quantile_transformer来实现这一点。但是我在这个项目中使用斯坦(Pystan),因此必须导出查找表。 我找不到任何从分位数变换器中提取查找表的方法
有人知道我如何使用另一个包提取或生成它吗
现在我正在使用我自己的基本实现。如果我说的不清楚,可以在下面看到
任何意见都将不胜感激
在自己的实现中,注意第三个图上的两个异常值:
# Import
import numpy as np
import matplotlib.pyplot as plt
# Nested fucntion
def histogram(data, title):
plt.figure()
plt.hist(data, bins=50, edgecolor='black')
plt.grid()
plt.title(title)
# Synthetic data distribution
data = np.random.laplace(0,1,(1000,1))
# Normal distributed data used for make table
data_n = np.random.normal(0,1,(1000000,1))
# Determine quantiles of both data sets
quan = np.linspace(0,100, 10000)
val = np.percentile(data, q=quan)
val_n = np.percentile(data_n, q=quan)
# Plot distributions
histogram(data, 'Synthetic data')
histogram(data_n, 'Normal distribution used for look-up table')
# Transform from data to normal distribution
synth2norm = np.zeros((len(data)))
for i in range(0, len(data)):
idx = np.argmin(abs(val-data[i]))
synth2norm[i] = val_n[idx]
histogram(synth2norm, 'Tranform synthetic to normal')
# Transform sampled normal to synthetic data distribution
sample = np.random.normal(0,1,(500,1))
sample2synth = np.zeros((len(sample)))
for i in range(0, len(sample)):
idx = np.argmin(abs(val_n-sample[i]))
sample2synth[i] = val[idx]
histogram(sample2synth, 'Sample from STAN (normal) to synthetic data distribution')
目前没有回答
相关问题 更多 >
编程相关推荐