layer_discretization {keras}R Documentation

A preprocessing layer which buckets continuous features by ranges.

Description

A preprocessing layer which buckets continuous features by ranges.

Usage

layer_discretization(
  object,
  bin_boundaries = NULL,
  num_bins = NULL,
  epsilon = 0.01,
  output_mode = "int",
  sparse = FALSE,
  ...
)

Arguments

object

What to compose the new Layer instance with. Typically a Sequential model or a Tensor (e.g., as returned by layer_input()). The return value depends on object. If object is:

  • missing or NULL, the Layer instance is returned.

  • a Sequential model, the model with an additional layer is returned.

  • a Tensor, the output tensor from layer_instance(object) is returned.

bin_boundaries

A list of bin boundaries. The leftmost and rightmost bins will always extend to -Inf and Inf, so bin_boundaries = c(0., 1., 2.) generates bins ⁠(-Inf, 0.)⁠, ⁠[0., 1.)⁠, ⁠[1., 2.)⁠, and ⁠[2., +Inf)⁠. If this option is set, adapt should not be called.

num_bins

The integer number of bins to compute. If this option is set, adapt should be called to learn the bin boundaries.

epsilon

Error tolerance, typically a small fraction close to zero (e.g. 0.01). Higher values of epsilon increase the quantile approximation, and hence result in more unequal buckets, but could improve performance and resource consumption.

output_mode

Specification for the output of the layer. Defaults to "int". Values can be "int", "one_hot", "multi_hot", or "count" configuring the layer as follows:

  • "int": Return the discretized bin indices directly.

  • "one_hot": Encodes each individual element in the input into an array the same size as num_bins, containing a 1 at the input's bin index. If the last dimension is size 1, will encode on that dimension. If the last dimension is not size 1, will append a new dimension for the encoded output.

  • "multi_hot": Encodes each sample in the input into a single array the same size as num_bins, containing a 1 for each bin index index present in the sample. Treats the last dimension as the sample dimension, if input shape is ⁠(..., sample_length)⁠, output shape will be ⁠(..., num_tokens)⁠.

  • "count": As "multi_hot", but the int array contains a count of the number of times the bin index appeared in the sample.

sparse

Boolean. Only applicable to "one_hot", "multi_hot", and "count" output modes. If TRUE, returns a SparseTensor instead of a dense Tensor. Defaults to FALSE.

...

standard layer arguments.

Details

This layer will place each element of its input data into one of several contiguous ranges and output an integer index indicating which range each element was placed in.

Input shape: Any tf.Tensor or tf.RaggedTensor of dimension 2 or higher.

Output shape: Same as input shape.

See Also

Other numerical features preprocessing layers: layer_normalization()

Other preprocessing layers: layer_category_encoding(), layer_center_crop(), layer_hashing(), layer_integer_lookup(), layer_normalization(), layer_random_brightness(), layer_random_contrast(), layer_random_crop(), layer_random_flip(), layer_random_height(), layer_random_rotation(), layer_random_translation(), layer_random_width(), layer_random_zoom(), layer_rescaling(), layer_resizing(), layer_string_lookup(), layer_text_vectorization()


[Package keras version 2.15.0 Index]