mappers.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:transform 作者: tensorflow 项目源码 文件源码
def scale_to_z_score(x, name=None):
  """Returns a standardized column with mean 0 and variance 1.

  Scaling to z-score subtracts out the mean and divides by standard deviation.
  Note that the standard deviation computed here is based on the biased variance
  (0 delta degrees of freedom), as computed by analyzers.var.

  Args:
    x: A numeric `Tensor`.
    name: (Optional) A name for this operation.

  Returns:
    A `Tensor` containing the input column scaled to mean 0 and variance 1
    (standard deviation 1), given by: (x - mean(x)) / std_dev(x).
    If `x` is floating point, the mean will have the same type as `x`. If `x` is
    integral, the output is cast to float32 for int8 and int16 and float64 for
    int32 and int64 (similar to the behavior of tf.truediv).

    Note that TFLearn generally permits only tf.int64 and tf.float32, so casting
    this scaler's output may be necessary. In particular, scaling an int64
    tensor yields a float64 tensor, which would need a cast to float32 to be
    used in TFLearn.
  """
  with tf.name_scope(name, 'scale_to_z_score'):
    # x_mean will be float32 or float64, depending on type of x.
    x_mean = analyzers.mean(x)
    return (tf.cast(x, x_mean.dtype) - x_mean) / tf.sqrt(analyzers.var(x))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号