Method: Rumale::Preprocessing::OneHotEncoder#transform

Defined in:
lib/rumale/preprocessing/one_hot_encoder.rb

#transform(x) ⇒ Numo::DFloat

Encode samples into one-hot-vectors.

Parameters:

  • x (Numo::Int32)

    (shape: [n_samples, n_features]) The samples to encode into one-hot-vectors.

Returns:

  • (Numo::DFloat)

    The one-hot-vectors.

Raises:

  • (ArgumentError)


77
78
79
80
81
82
# File 'lib/rumale/preprocessing/one_hot_encoder.rb', line 77

def transform(x)
  x = Numo::Int32.cast(x) unless x.is_a?(Numo::Int32)
  raise ArgumentError, 'Expected the input samples only consists of non-negative integer values.' if x.lt(0).any?
  codes = encode(x, @feature_indices)
  codes[true, @active_features].dup
end