ML Community Day is November 9! Join us for updates from TensorFlow, JAX, and more Learn more

tf.keras.experimental.LinearModel

Linear Model for regression and classification problems.

Inherits From: Model, Layer, Module

Used in the notebooks

Used in the guide

This model approximates the following function:

$$y = \beta + \sum_{i=1}^{N} w_{i} * x_{i}$$

where

$$\beta$$

is the bias and

$$w_{i}$$

is the weight for each feature.

Example:

model = LinearModel()
model.compile(optimizer='sgd', loss='mse')
model.fit(x, y, epochs=epochs)

This model accepts sparse float inputs as well:

Example:

model = LinearModel()
opt = tf.keras.optimizers.Adam()
loss_fn = tf.keras.losses.MeanSquaredError()
with tf.GradientTape() as tape:
  output = model(sparse_input)
  loss = tf.reduce_mean(loss_fn(target, output))
grads = tape.gradient(loss, model.weights)
opt.apply_gradients(zip(grads, model.weights))

units Positive integer, output dimension without the batch size.
activation Activation function to use. If you don't specify anything, no activation is applied.
use_bias whether to calculate the bias/intercept for this model. If set to False, no bias/intercept will be used in calculations, e.g., the data is already centered.
kernel_initializer Initializer for the kernel weights matrices.
bias_initializer Initializer for the bias vector.
kernel_regularizer regularizer for kernel vectors.
bias_regularizer regularizer for bias vector.
**kwargs The keyword arguments that are passed on to BaseLayer.init.

distribute_strategy The tf.distribute.Strategy this model was created under.
layers

metrics_names Returns the model's display labels for all outputs.

inputs = tf.keras.layers.Input(shape=(3,))
outputs = tf.keras.layers.Dense(2)(inputs)
model = tf.keras.models.Model(inputs=inputs, outputs=outputs)
model.compile(optimizer=