Turi Create  4.0
turi::sdk_model::feature_engineering::count_featurizer Class Referenceabstract

#include <toolkits/feature_engineering/count_featurizer.hpp>

Public Member Functions

size_t get_version () const override
 
void save_impl (oarchive &oarc) const override
 
void load_version (iarchive &iarc, size_t version) override
 
void init_options (const std::map< std::string, flexible_type > &_options) override
 
void init_transformer (const std::map< std::string, flexible_type > &_options) override
 
void fit (gl_sframe data) override
 
gl_sframe transform (gl_sframe data) override
 
std::vector< std::string > list_fields ()
 
const variant_typeget_value_from_state (std::string key)
 
const std::map< std::string, flexible_type > & get_current_options () const
 
std::map< std::string, flexible_typeget_default_options () const
 
const flexible_typeget_option_value (const std::string &name) const
 
const std::map< std::string, variant_type > & get_state () const
 
bool is_trained () const
 
void set_options (const std::map< std::string, flexible_type > &_options)
 
void add_or_update_state (const std::map< std::string, variant_type > &dict)
 
const std::vector< option_handling::option_info > & get_option_info () const
 
virtual const char * name ()=0
 
virtual const std::string & uid ()=0
 
void save_to_url (const std::string &url, const variant_map_type &side_data={})
 
void save_model_to_data (std::ostream &out)
 
const std::map< std::string, std::vector< std::string > > & list_functions ()
 
const std::vector< std::string > & list_get_properties ()
 
const std::vector< std::string > & list_set_properties ()
 
variant_type call_function (const std::string &function, variant_map_type argument)
 
variant_type get_property (const std::string &property)
 
variant_type set_property (const std::string &property, variant_map_type argument)
 
const std::string & get_docstring (const std::string &symbol)
 
virtual void perform_registration ()
 

Protected Member Functions

void register_function (std::string fnname, const std::vector< std::string > &arguments, impl_fn fn)
 
void register_defaults (const std::string &fnname, const variant_map_type &arguments)
 
void register_setter (const std::string &propname, impl_fn setfn)
 
void register_getter (const std::string &propname, impl_fn getfn)
 
void register_docstring (const std::pair< std::string, std::string > &fnname_docstring)
 

Protected Attributes

std::map< std::string, variant_typestate
 

Detailed Description

An approximate, limited memory implementation of the feature engineering mechanism by Misha Bilenko in https://blogs.technet.microsoft.com/machinelearning/2015/02/17/big-learning-made-easy-with-counts/ For some k-ary classification task assuming we are going to try to predict column Y. Then for every column, X, we replace it with 2k-1 numeric features: Assuming the value X in row i is x_i. We replace it two columns: count_X: a list of the following values

  • #(Y = 0 & X = x_i) the number of times Y = 0 when X has the value x_i
  • #(Y = 1 & X = x_i)
  • ...
  • #(Y = k-1 & X = x_i) prob_X: a list of the following values
  • P(Y = 0 | X = x_i) the probability Y = 0 when X has the value x_i
  • P(Y = 1 | X = x_i)
  • ...
  • P(Y = k-2 | X = x_i)

This procedure is generally quite memory intensive, requiring the count table #(Y=y, X=x) to be built up for every column, requiring O(k * N(X)) memory per column where N(X) is the number of unique values of X.

Instead, we will approximate the count table this way: For each input column X,

  • We maintain k count tables. i.e. one count for each Y value, where each count table is represented by a count-min-sketch. http://www.cs.rutgers.edu/~muthu/cmz-sdm.pdf provides some analysis on the use of the count-min sketch and empirical validation as to why the count-min sketch is preferred over the count sketch in the power-law distribution setting.

This provides counts which are inherently upper bounds on the actual counts. Therefore, estimating P(Y = 0 | X = x_i) with #(Y = 0 & X = x_i) / #(X = x_i) is problematic since if #(X = x_i) is estimated indepedendently, the probabilities may not sum to 1. Instead #(X = x_i) should be estimated with #(Y = y & X = x_i)

Definition at line 60 of file count_featurizer.hpp.

Member Function Documentation

◆ add_or_update_state()

void turi::ml_model_base::add_or_update_state ( const std::map< std::string, variant_type > &  dict)
inherited

Append the key value store of the model.

Parameters
[in]dictOptions (Key-Value pairs) to set

◆ call_function()

variant_type turi::model_base::call_function ( const std::string &  function,
variant_map_type  argument 
)
inherited

Calls a user defined function.

◆ fit()

void turi::sdk_model::feature_engineering::count_featurizer::fit ( gl_sframe  data)
overridevirtual

Fit the transformer and make it ready for transformations.

Parameters
[in]data(SFrame of data)

Python side interface

This function directly interfaces with "fit" in python.

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ get_current_options()

const std::map<std::string, flexible_type>& turi::ml_model_base::get_current_options ( ) const
inherited

Get current options.

Returns
Dictionary containing current options.

Python side interface

Interfaces with the get_current_options function in the Python side.

◆ get_default_options()

std::map<std::string, flexible_type> turi::ml_model_base::get_default_options ( ) const
inherited

Get default options.

Returns
Dictionary with default options.

Python side interface

Interfaces with the get_default_options function in the Python side.

◆ get_docstring()

const std::string& turi::model_base::get_docstring ( const std::string &  symbol)
inherited

Returns the toolkit documentation for a function or property.

◆ get_option_info()

const std::vector<option_handling::option_info>& turi::ml_model_base::get_option_info ( ) const
inherited

Returns the option information struct for each of the set parameters.

◆ get_option_value()

const flexible_type& turi::ml_model_base::get_option_value ( const std::string &  name) const
inherited

Returns the value of an option. Throws an error if the option does not exist.

Parameters
[in]nameName of the option to get.

◆ get_property()

variant_type turi::model_base::get_property ( const std::string &  property)
inherited

Reads a property.

◆ get_state()

const std::map<std::string, variant_type>& turi::ml_model_base::get_state ( ) const
inherited

Get model.

Returns
Model map.

◆ get_value_from_state()

const variant_type& turi::ml_model_base::get_value_from_state ( std::string  key)
inherited

Returns the value of a particular key from the state.

Returns
Value of a key model_base for details.

Python side interface

From the python side, this is interfaced with the get() function or the [] operator in python.

◆ get_version()

size_t turi::sdk_model::feature_engineering::count_featurizer::get_version ( ) const
overridevirtual

Returns the current model version

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ init_options()

void turi::sdk_model::feature_engineering::count_featurizer::init_options ( const std::map< std::string, flexible_type > &  _options)
overridevirtual

Set one of the options in the algorithm. Use the option manager to set these options. If the option does not satisfy the conditions that the option manager has imposed on it. Errors will be thrown.

Parameters
[in]optionsOptions to set

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ init_transformer()

void turi::sdk_model::feature_engineering::count_featurizer::init_transformer ( const std::map< std::string, flexible_type > &  _options)
overridevirtual

Init the transformer and return an instantiated object.

Parameters
[in]options(**kwargs from python)

Python side interface

This function directly interfaces with "__init__" in python.

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ is_trained()

bool turi::ml_model_base::is_trained ( ) const
inherited

Is this model trained.

Returns
True if already trained.

◆ list_fields()

std::vector<std::string> turi::ml_model_base::list_fields ( )
inherited

Methods with already meaningful default implementations.

Lists all the keys accessible in the "model" map.

Returns
List of keys in the model map. model_base for details.

Python side interface

This is the function that the list_fields should call in python.

◆ list_functions()

const std::map<std::string, std::vector<std::string> >& turi::model_base::list_functions ( )
inherited

Lists all the registered functions. Returns a map of function name to array of argument names for the function.

◆ list_get_properties()

const std::vector<std::string>& turi::model_base::list_get_properties ( )
inherited

Lists all the get-table properties of the class.

◆ list_set_properties()

const std::vector<std::string>& turi::model_base::list_set_properties ( )
inherited

Lists all the set-table properties of the class.

◆ load_version()

void turi::sdk_model::feature_engineering::count_featurizer::load_version ( iarchive iarc,
size_t  version 
)
overridevirtual

Loads a model previously saved at a particular version number. Should raise an exception on failure.

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ name()

virtual const char* turi::model_base::name ( )
pure virtualinherited

Returns the name of the toolkit class, as exposed to client code. For example, the Python proxy for this instance will have a type with this name.

Note: this function is typically overridden using the BEGIN_CLASS_MEMBER_REGISTRATION macro.

◆ perform_registration()

virtual void turi::model_base::perform_registration ( )
virtualinherited

Declare the base registration function. This class has to be handled specially; the macros don't work here due to the override declarations.

Reimplemented in turi::model_proxy.

◆ register_defaults()

void turi::model_base::register_defaults ( const std::string &  fnname,
const variant_map_type &  arguments 
)
protectedinherited

Registers default argument values

◆ register_docstring()

void turi::model_base::register_docstring ( const std::pair< std::string, std::string > &  fnname_docstring)
protectedinherited

Adds a docstring for the specified function or property name.

◆ register_function()

void turi::model_base::register_function ( std::string  fnname,
const std::vector< std::string > &  arguments,
impl_fn  fn 
)
protectedinherited

Adds a function with the specified name, and argument list.

◆ register_getter()

void turi::model_base::register_getter ( const std::string &  propname,
impl_fn  getfn 
)
protectedinherited

Adds a property getter with the specified name.

◆ register_setter()

void turi::model_base::register_setter ( const std::string &  propname,
impl_fn  setfn 
)
protectedinherited

Adds a property setter with the specified name.

◆ save_impl()

void turi::sdk_model::feature_engineering::count_featurizer::save_impl ( oarchive oarc) const
overridevirtual

Serializes the model. Must save the model to the file format version matching that of get_version()

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ save_model_to_data()

void turi::model_base::save_model_to_data ( std::ostream &  out)
inherited

Save a toolkit class to a data stream.

◆ save_to_url()

void turi::model_base::save_to_url ( const std::string &  url,
const variant_map_type &  side_data = {} 
)
inherited

Save a toolkit class to disk.

Parameters
urlThe destination url to store the class.
sidedataAny additional side information

◆ set_options()

void turi::ml_model_base::set_options ( const std::map< std::string, flexible_type > &  _options)
inherited

Set one of the options in the algorithm.

The value are checked with the requirements given by the option instance.

Parameters
[in]nameName of the option.
[in]valueValue for the option.

◆ set_property()

variant_type turi::model_base::set_property ( const std::string &  property,
variant_map_type  argument 
)
inherited

Sets a property. The new value of the property should appear in the argument map under the key "value".

◆ transform()

gl_sframe turi::sdk_model::feature_engineering::count_featurizer::transform ( gl_sframe  data)
overridevirtual

Transform the given data.

Parameters
[in]data(SFrame of data)

Python side interface

This function directly interfaces with "transform" in python.

Implements turi::sdk_model::feature_engineering::transformer_base.

◆ uid()

virtual const std::string& turi::model_base::uid ( )
pure virtualinherited

Returns a unique identifier for the toolkit class. It can be any unique ID. The UID is only used at runtime (to determine the concrete type of an arbitrary model_base instance) and is never stored.

Note: this function is typically overridden using the BEGIN_CLASS_MEMBER_REGISTRATION macro.

Implemented in turi::model_proxy.

Member Data Documentation

◆ state

std::map<std::string, variant_type> turi::ml_model_base::state
protectedinherited

All things python

Definition at line 206 of file ml_model.hpp.


The documentation for this class was generated from the following file: