# Why is no activation function needed for the output layer of a neural network for regression?

I'm a bit confused about the activation function in the output layer of a neural network trained for regression. In most tutorials, the output layer uses "sigmoid" to bring the results back to a nice number between 0 and 1.

But in this beginner example on the TensorFlow website, the output layer has no activation function at all? Is this allowed? Wouldn't the result be a crazy number that's all over the place? Or maybe TensorFlow has a hidden default activation?

This code is from the example where you predict miles per gallon based on horsepower of a car.

// input layer

// hidden layer

// output layer - no activation needed ???


In regression, the goal is to approximate a function $$f: \mathcal{I} \rightarrow \mathbb{R}$$, so $$f(x) \in \mathbb{R}$$. In other words, in regression, you want to learn a function whose outputs can be any number, so not necessarily just a number in the range $$[0, 1]$$.
By default, tf.keras.layers.Dense does not use any activation function, which means that the output of your neural network is indeed just a linear combination of the inputs from the previous layer. This should be fine for a regression problem.