LostTech.TensorFlow : API Documentation

Type KernelLinearClassifier

Namespace tensorflow.contrib.kernel_methods

Parent _KernelEstimator

Interfaces IKernelLinearClassifier

Linear classifier using kernel methods as feature preprocessing.

It trains a linear model after possibly mapping initial input features into a mapped space using explicit kernel mappings. Due to the kernel mappings, training a linear classifier in the mapped (output) space can detect non-linearities in the input space.

The user can provide a list of kernel mappers to be applied to all or a subset of existing feature_columns. This way, the user can effectively provide 2 types of feature columns:

* those passed as elements of feature_columns in the classifier's constructor * those appearing as a key of the kernel_mappers dict.

If a column appears in feature_columns only, no mapping is applied to it. If it appears as a key in kernel_mappers, the corresponding kernel mappers are applied to it. Note that it is possible that a column appears in both places. Currently kernel_mappers are supported for _RealValuedColumns only.

Example usage: ``` real_column_a = real_valued_column(name='real_column_a',...) sparse_column_b = sparse_column_with_hash_bucket(...) kernel_mappers = {real_column_a : [RandomFourierFeatureMapper(...)]} optimizer =...

# real_column_a is used as a feature in both its initial and its transformed # (mapped) form. sparse_column_b is not affected by kernel mappers. kernel_classifier = KernelLinearClassifier( feature_columns=[real_column_a, sparse_column_b], model_dir=..., optimizer=optimizer, kernel_mappers=kernel_mappers)

# real_column_a is used as a feature in its transformed (mapped) form only. # sparse_column_b is not affected by kernel mappers. kernel_classifier = KernelLinearClassifier( feature_columns=[sparse_column_b], model_dir=..., optimizer=optimizer, kernel_mappers=kernel_mappers)

# Input builders def train_input_fn: # returns x, y ... def eval_input_fn: # returns x, y ...

kernel_classifier.fit(input_fn=train_input_fn) kernel_classifier.evaluate(input_fn=eval_input_fn) kernel_classifier.predict(...) ```

Input of `fit` and `evaluate` should have following features, otherwise there will be a `KeyError`:

* if `weight_column_name` is not `None`, a feature with `key=weight_column_name` whose value is a `Tensor`. * for each `column` in `feature_columns`: - if `column` is a `SparseColumn`, a feature with `key=column.name` whose `value` is a `SparseTensor`. - if `column` is a `WeightedSparseColumn`, two features: the first with `key` the id column name, the second with `key` the weight column name. Both features' `value` must be a `SparseTensor`. - if `column` is a `RealValuedColumn`, a feature with `key=column.name` whose `value` is a `Tensor`.

Methods

Properties

Public static methods

KernelLinearClassifier NewDyn(object feature_columns, object model_dir, ImplicitContainer<T> n_classes, object weight_column_name, object optimizer, object kernel_mappers, object config)

Construct a `KernelLinearClassifier` estimator object.
Parameters
object feature_columns
An iterable containing all the feature columns used by the model. All items in the set should be instances of classes derived from `FeatureColumn`.
object model_dir
Directory to save model parameters, graph etc. This can also be used to load checkpoints from the directory into an estimator to continue training a previously saved model.
ImplicitContainer<T> n_classes
number of label classes. Default is binary classification. Note that class labels are integers representing the class index (i.e. values from 0 to n_classes-1). For arbitrary label values (e.g. string labels), convert to class indices first.
object weight_column_name
A string defining feature column name representing weights. It is used to down weight or boost examples during training. It will be multiplied by the loss of the example.
object optimizer
The optimizer used to train the model. If specified, it should be an instance of `tf.Optimizer`. If `None`, the Ftrl optimizer is used by default.
object kernel_mappers
Dictionary of kernel mappers to be applied to the input features before training a (linear) model. Keys are feature columns and values are lists of mappers to be applied to the corresponding feature column. Currently only _RealValuedColumns are supported and therefore all mappers should conform to the `DenseKernelMapper` interface (see ./mappers/dense_kernel_mapper.py).
object config
`RunConfig` object to configure the runtime settings.
Returns
KernelLinearClassifier
A `KernelLinearClassifier` estimator.

Public properties

object config get;

object config_dyn get;

string model_dir get;

object model_dir_dyn get;

object model_fn get;

object model_fn_dyn get;

object PythonObject get;