HashingTrickMl

In machine leaning, Hashing Trick is a fast and space-efficient way of vectorizing features.

Usage

Add to your class:

class Order < ActiveRecord::Base
  include HashingTrickMl::ActsAsVectorized
  acts_as_vectorized default_dimensions: 1_000
end

@order = Order.new(complete: false)

build_word_vector('Lorem ipsum dolor sit amet.')
build_word_vector('Lorem ipsum dolor sit amet.', dimensions: 50)
build_word_vector('[email protected]', dimensions: 50, separator: '@')

build_boolean_vector([2, 4], [0, 1, 2, 3, 4]) => [0, 0, 1, 0, 1]

build_fuzzy_vector(@order.complete?) => 0
@order.complete = true
build_fuzzy_vector(@order.complete?) => 1

build_exponential_vector([100, 50, 200, 150], dimensions: 10)

build_maybe_nil_vector(nil) => [0, 0]
build_maybe_nil_vector(50) => [50, 1]

Installation

Add this line to your application's Gemfile:

gem 'hashing_trick_ml'

And then execute:

$ bundle

Or install it yourself as:

$ gem install hashing_trick_ml

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.