tflearn.layers.estimator.regression (incoming, placeholder=None, optimizer='adam', loss='categorical_crossentropy', metric='default', learning_rate=0.001, dtype=tf.float32, batch_size=64, shuffle_batches=True, to_one_hot=False, n_classes=None, trainable_vars=None, restore=True, op_name=None, validation_monitors=None, validation_batch_size=None, name=None)

The regression layer is used in TFLearn to apply a regression (linear or logistic) to the provided input. It requires to specify a TensorFlow gradient descent optimizer 'optimizer' that will minimize the provided loss function 'loss' (which calculate the errors). A metric can also be provided, to evaluate the model performance.

A 'TrainOp' is generated, holding all information about the optimization process. It is added to TensorFlow collection 'tf.GraphKeys.TRAIN_OPS' and later used by TFLearn 'models' classes to perform the training.

An optional placeholder 'placeholder' can be specified to use a custom TensorFlow target placeholder instead of creating a new one. The target placeholder is added to the 'tf.GraphKeys.TARGETS' TensorFlow collection, so that it can be retrieved later.

Additionaly, a list of variables 'trainable_vars' can be specified, so that only them will be updated when applying the backpropagation algorithm.


2-D Tensor Layer.


2-D Tensor Layer (Same as input).


  • incoming: Tensor. Incoming 2-D Tensor.
  • placeholder: Tensor. This regression target (label) placeholder. If 'None' provided, a placeholder will be added automatically. You can retrieve that placeholder through graph key: 'TARGETS', or the 'placeholder' attribute of this function's returned tensor.
  • optimizer: str (name), Optimizer or function. Optimizer to use. Default: 'adam' (Adaptive Moment Estimation).
  • loss: str (name) or function. Loss function used by this layer optimizer. Default: 'categorical_crossentropy'.
  • metric: str, Metric or function. The metric to be used. Default: 'default' metric is 'accuracy'. To disable metric calculation, set it to 'None'.
  • learning_rate: float. This layer optimizer's learning rate.
  • dtype: tf.types. This layer placeholder type. Default: tf.float32.
  • batch_size: int. Batch size of data to use for training. tflearn supports different batch size for every optimizers. Default: 64.
  • shuffle_batches: bool. Shuffle or not this optimizer batches at every epoch. Default: True.
  • to_one_hot: bool. If True, labels will be encoded to one hot vectors. 'n_classes' must then be specified.
  • n_classes: int. The total number of classes. Only required when using 'to_one_hot' option.
  • trainable_vars: list of Variable. If specified, this regression will only update given variable weights. Else, all trainale variable are going to be updated.
  • restore: bool. If False, variables related to optimizers such as moving averages will not be restored when loading a pre-trained model.
  • op_name: A name for this layer optimizer (optional). Default: optimizer op name.
  • validation_monitors: list of Tensor objects. List of variables to compute during validation, which are also used to produce summaries for output to TensorBoard. For example, this can be used to periodically record a confusion matrix or AUC metric, during training. Each variable should have rank 1, i.e. shape [None].
  • validation_batch_size: int or None. Specifies the batch size to be used for the validation data feed.
  • name: A name for this layer's placeholder scope.


  • placeholder: Tensor. Placeholder for feeding labels.