⇐ Blog

Kaggle: Intro to Deep learning

Posted at 5 August 2025 | 8 min read

Linear Unit

Multiple inputs Multiple input linear unit

Code example for analogy of measuring calories (output) with combination of sugars, fiber, and protein (input):

from tensorflow import keras
from tensorflow.keras import layers

# Create a network with 1 linear unit
model = keras.Sequential([
    layers.Dense(units=1, input_shape=[3])
])

Becomes

calories = keras.Sequential([
	// units=1, means there is only one neuron
	// input_shape=3, for the model accept sugar, fiber, and protein as input
    layers.Dense(units=1, input_shape=[3])
])

Why is input_shape a Python list?
The data we’ll use in this course will be tabular data, like in a Pandas dataframe. We’ll have one input for each feature in the dataset. The features are arranged by column, so we’ll always have input_shape=[num_columns]. The reason Keras uses a list here is to permit use of more complex datasets. Image data, for instance, might need three dimensions: [height, width, channels].



Code example:

from tensorflow import keras
from tensorflow.keras import layers

model = keras.Sequential([
    # the hidden ReLU layers
    layers.Dense(units=4, activation='relu', input_shape=[2]),
    layers.Dense(units=3, activation='relu'),
    
    # the linear output layer 
    layers.Dense(units=1),
])