Home | History | Annotate | Download | only in kernel_methods
      1 # TensorFlow contrib kernel_methods.
      2 
      3 This module contains operations and estimators that enable the use of primal
      4 (explicit) kernel methods in TensorFlow. See also the [tutorial](https://www.tensorflow.org/code/tensorflow/contrib/kernel_methods/g3doc/tutorial.md) on how to use this module to improve the quality of
      5 classification or regression tasks.
      6 
      7 ## Kernel Mappers
      8 Implement explicit kernel mapping Ops over tensors. Kernel mappers add
      9 Tensor-In-Tensor-Out (TITO) Ops to the TensorFlow graph. They can be used in
     10 conjunction with other layers or ML models.
     11 
     12 Sample usage:
     13 
     14 ```python
     15 kernel_mapper = tf.contrib.kernel_methods.SomeKernelMapper(...)
     16 out_tensor = kernel_mapper.map(in_tensor)
     17 ...  # code that consumes out_tensor.
     18 ```
     19 
     20 Currently, there is a [RandomFourierFeatureMapper](https://www.tensorflow.org/code/tensorflow/contrib/kernel_methods/python/mappers/random_fourier_features.py) implemented that maps dense input to dense
     21 output. More mappers are on the way.
     22 
     23 ## Kernel-based Estimators
     24 
     25 These estimators inherit from the
     26 [`tf.contrib.learn.Estimator`](https://www.tensorflow.org/code/tensorflow/contrib/learn/python/learn/estimators/estimator.py)
     27 class and use kernel mappers internally to discover non-linearities in the
     28 data. These canned estimators map their input features using kernel mapper
     29 Ops and then apply linear models to the mapped features. Combining kernel
     30 mappers with linear models and different loss functions leads to a variety of
     31 models: linear and non-linear SVMs, linear regression (with and without
     32 kernels) and (multinomial) logistic regression (with and without kernels).
     33 
     34 Currently there is a [KernelLinearClassifier](https://www.tensorflow.org/code/tensorflow/contrib/kernel_methods/python/kernel_estimators.py) implemented but more pre-packaged estimators
     35 are on the way.
     36 
     37 Sample usage:
     38 
     39 ```python
     40 real_column_a = tf.contrib.layers.real_valued_column(name='real_column_a',...)
     41 sparse_column_b = tf.contrib.layers.sparse_column_with_hash_bucket(...)
     42 kernel_mappers = {real_column_a : [tf.contrib.kernel_methods.SomeKernelMapper(...)]}
     43 optimizer = ...
     44 
     45 kernel_classifier = tf.contrib.kernel_methods.KernelLinearClassifier(
     46     feature_columns=[real_column_a, sparse_column_b],
     47     model_dir=...,
     48     optimizer=optimizer,
     49     kernel_mappers=kernel_mappers)
     50 
     51 # Construct input_fns
     52 kernel_classifier.fit(...)
     53 kernel_classifier.evaluate(...)
     54 ```
     55 
     56