aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/kernel_methods/README.md
blob: 1bce3277ff46ac91a8de118db17041a0e424ebc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# TensorFlow contrib kernel_methods.

This module contains operations and estimators that enable the use of primal
(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
classification or regression tasks.

## Kernel Mappers
Implement explicit kernel mapping Ops over tensors. Kernel mappers add
Tensor-In-Tensor-Out (TITO) Ops to the TensorFlow graph. They can be used in
conjunction with other layers or ML models.

Sample usage:

```python
kernel_mapper = tf.contrib.kernel_methods.SomeKernelMapper(...)
out_tensor = kernel_mapper.map(in_tensor)
...  # code that consumes out_tensor.
```

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
output. More mappers are on the way.

## Kernel-based Estimators

These estimators inherit from the
[`tf.contrib.learn.Estimator`](https://www.tensorflow.org/code/tensorflow/contrib/learn/python/learn/estimators/estimator.py)
class and use kernel mappers internally to discover non-linearities in the
data. These canned estimators map their input features using kernel mapper
Ops and then apply linear models to the mapped features. Combining kernel
mappers with linear models and different loss functions leads to a variety of
models: linear and non-linear SVMs, linear regression (with and without
kernels) and (multinomial) logistic regression (with and without kernels).

Currently there is a [KernelLinearClassifier](https://www.tensorflow.org/code/tensorflow/contrib/kernel_methods/python/kernel_estimators.py) implemented but more pre-packaged estimators
are on the way.

Sample usage:

```python
real_column_a = tf.contrib.layers.real_valued_column(name='real_column_a',...)
sparse_column_b = tf.contrib.layers.sparse_column_with_hash_bucket(...)
kernel_mappers = {real_column_a : [tf.contrib.kernel_methods.SomeKernelMapper(...)]}
optimizer = ...

kernel_classifier = tf.contrib.kernel_methods.KernelLinearClassifier(
    feature_columns=[real_column_a, sparse_column_b],
    model_dir=...,
    optimizer=optimizer,
    kernel_mappers=kernel_mappers)

# Construct input_fns
kernel_classifier.fit(...)
kernel_classifier.evaluate(...)
```