lib/rumale/feature_extraction/feature_hasher.rb
def transform(x)
        x = [x] unless x.is_a?(Array)
        n_samples = x.size

        z = Numo::DFloat.zeros(n_samples, n_features)

        x.each_with_index do |f, i|
          f.each do |k, v|
            k = "#{k}=#{v}" if v.is_a?(String)
            val = v.is_a?(String) ? 1 : v
            next if val.zero?

            h = Mmh3.hash32(k)
            fid = h.abs % n_features
            val *= h >= 0 ? 1 : -1 if alternate_sign?
            z[i, fid] = val
          end
        end

        z
      end
# Encode given the array of feature-value hash.
#
# @param x [Array<Hash>] (shape: [n_samples]) The array of hash consisting of feature names and values.
# @return [Numo::DFloat] (shape: [n_samples, n_features]) The encoded sample array.
Encode given the array of feature-value hash.
Encode given the array of feature - value hash .
def transform(x)
        x = [x] unless x.is_a?(Array)
        n_samples = x.size
        z = Numo::DFloat.zeros(n_samples, n_features)
        x.each_with_index do |f, i|
          f.each do |k, v|
            k = "#{k}=#{v}" if v.is_a?(String)
            val = v.is_a?(String) ? 1 : v
            next if val.zero?
            h = Mmh3.hash32(k)
            fid = h.abs % n_features
            val *= h >= 0 ? 1 : -1 if alternate_sign?
            z[i, fid] = val
          end
        end
        z
      end
def transform ( x ) x = [ x ] unless x . is_a? ( Array ) n_samples = x . size z = Numo :: DFloat . zeros ( n_samples , n_features ) x . each_with_index do | f , i | f . each do | k , v | k = "#{k}=#{v}" if v . is_a? ( String ) val = v . is_a? ( String ) ? 1 : v next if val . zero? h = Mmh3 . hash32 ( k ) fid = h . abs % n_features val *= h >= 0 ? 1 : - 1 if alternate_sign? z [ i , fid ] = val end end z end
Encode given the array of feature-value hash.
Encode given the array of feature - value hash .
[n_samples, n_features]) The encoded sample array.
[ n_samples n_features ] ) The encoded sample array .
Numo::DFloat
x
[n_samples]) The array of hash consisting of feature names and values.
[ n_samples ] ) The array of hash consisting of feature names and values .