应用分位数变换的keras层及其逆
FastQuantileLayer的Python项目详细描述
快速量化层
FastQuantileLayer是Keras实现分位数转换的层 类似于scikit学习量子位变换器。 类似的实现,更精确但不局限于keras,可以在这里找到: https://github.com/yandexdataschool/QuantileTransformerTF/blob/master/README.md
此套餐的目的是:
- 删除对scikit learn的所有依赖项
- 尽可能快地获得正变换和反变换的求值 (以某种精度换取性能)
- 在keras中获得序列模型中可运行的tensorflow图
包由两个类组成:
- fixedbininterpolator:用于插入点定义函数 y=f(x),等距x采样(x网格)
- fastQuantileLayer:用于计算要预处理的转换 将数据输入到均匀分布或正态分布的变量中。
路缘石外示例
## Creates the training dataset
dataset = np.random.uniform ( 0., 1., 1000 )
## Train the QuantileTransformer
transformer = FastQuantileLayer (output_distribution='normal')
transformer . fit ( dataset )
## Gets a new dataset with the same distribution as the training dataset
test_dataset = tf.constant(np.random.uniform ( 0., 1., 100000 ))
## Transform the variable into a Gaussian-distributed variable t
t = transformer . transform ( test_dataset )
[...]
## Appiles the inverted transform to the Gaussian distributed variable t
bkwd = transformer . transform ( t, inverse=True )
## bkwd differs from test_dataset only for computational errors
## (order 1e-5) that can be reduced tuning the arguments of QuantileTransformer
路缘石内的示例
## Creates the training dataset
dataset = np.random.uniform ( 0., 1., 1000 )
model = tf.keras.models.Sequential()
model.add ( FastQuantileLayer ( output_distribution = 'normal' ).fit ( dataset ) )
model.add ( Dense ( 10, activation = 'tanh' ) )
model.add ( Dense ( 1, activation = 'sigmoid' ) )