Elena' s AI Blog

TensorFlow: Regression Model

21 Jan 2022 (updated: 24 Aug 2026) / 32 minutes to read

Elena Daehnhardt


Flux: A smooth curved trend line fitting scattered data points on a soft grid, representing a neural network learning a num...


TL;DR:
  • Build TensorFlow regression models: use Sequential API, compile with loss='mae', fit with train/test split. Adjust epochs, learning rate, and layers to improve predictions for numerical values.

Previous: Part 6 — Tensors in TensorFlow

Next: Part 8 — TensorFlow: Global and Operation-level Seeds

What Is Regression in Machine Learning?

Regression is a supervised machine learning task that predicts a continuous numerical value from one or more input features. Regression is defined in Wikipedia as:

In statistical modeling, regression analysis is a set of statistical processes for estimating the relationships between a dependent variable (often called the ‘outcome’ or ‘response’ variable) and one or more independent variables (often called ‘predictors,’ ‘covariates,’ ‘explanatory variables’ or ‘features’). The most common form of regression analysis is linear regression. One finds the line (or a more complex linear combination) that most closely fits the data according to a specific mathematical criterion.

In plain terms, you want to predict a numerical value from other numerical values, as described in the TensorFlow Developer Certificate course. In Machine Learning, regression analysis is widely used for prediction and forecasting. For instance, you can use regression models to predict house sale prices, modelled against the number of bedrooms, bathrooms, or garages. Other applications of regression include predicting how many people will buy an app, forecasting seasonal sales, and even predicting bounding-box coordinates in an object detection task. With regression, you are answering the questions “How many?” and “How much?”

Building a Regression Model in TensorFlow: Three Steps

When you build neural networks in TensorFlow with the Keras Sequential API, you generally follow three steps:

  1. create a model and define the input, hidden and output layers, and the number of neurons in each layer;
  2. compile the model with the required loss function, optimiser, and evaluation metrics;
  3. fit the model to find patterns between features and labels.

In the code below, I create a simple regression model with input features stored in X and output stored in y. For demonstration purposes, I kept the data small — just enough to show how you build a regression model and then improve it by adjusting hyperparameters at the compile and fit steps.

Improving Regression Model Performance: Hyperparameter Tuning

🔒 Subscribe to keep reading.

Evaluating Regression Models with Larger Datasets

🔒 Subscribe to keep reading.

Train, Validation, and Test Dataset Splits

🔒 Subscribe to keep reading.

Evaluating Model Predictions with MAE and MSE

🔒 Subscribe to keep reading.

Final Thoughts

🔒 Subscribe to keep reading.

References

🔒 Subscribe to keep reading.

Subscribe to unlock the full article ❤️

I keep most of the site completely open. A few unusually detailed tutorials need a free subscriber login so I can keep publishing this kind of work.

The form below signs you up for the newsletter. It does not log you into the app — log in afterwards (same email) to unlock this article and download your subscriber gifts. New subscribers get an inbox mail: Set a password to unlock articles.

desktop bg dark

About Elena

Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.

Citation
Elena Daehnhardt. (2022) 'TensorFlow: Regression Model', daehnhardt.com, 21 January 2022. Available at: https://daehnhardt.com/blog/2022/01/21/tf-regression/
All Posts