How to predict a function/table using Keras?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
If you have a table of input and output values and want Keras to learn the relationship, you are solving a regression problem. The model does not "discover a symbolic function" in the mathematical sense, but it can approximate the mapping from inputs to outputs well enough to predict unseen values.
This works both for simple one-dimensional functions such as y = sin(x) and for multi-column tabular data where several input features influence one numeric target. The workflow is always the same: prepare x and y, build a regression model, train it, and use predict.
Start with Input and Output Arrays
For a toy example, suppose you want the network to learn a noisy sine curve:
In a real table, x might have many columns:
The important rule is that each row in x must align with one target value in y.
Build a Regression Model
For function approximation and small tabular problems, a simple dense network is a good starting point:
The final layer has one unit and no activation because this is regression. If you were predicting two continuous outputs, the final layer would use Dense(2).
Train the Model
Now fit the network on the table:
After training, predict values for inputs the model has not seen:
That is the basic pattern for "predicting a function table" with Keras.
Normalize Tabular Inputs
For real-world tables, feature scaling often matters. Neural networks usually train more reliably when numeric inputs are normalized.
This is especially important when one column contains small values such as 0.01 and another contains large values such as 100000.
Use a Train/Test Split for Honest Evaluation
Do not judge the model only on the same rows it learned from. Hold out some data:
That tells you whether the network learned the relationship or merely memorized the examples.
Understand the Limits
Neural networks are good at interpolation within the range of data they have seen. They are often much worse at extrapolation beyond that range. If your training table covers inputs from 0 to 10, a prediction at 1000 may be meaningless even if the training loss looked excellent.
For very small, smooth, and well-understood functions, classical regression or interpolation can sometimes outperform a neural network with less complexity. Keras becomes attractive when the relationship is nonlinear, multi-dimensional, or hard to model analytically.
Common Pitfalls
- Using a classification loss or activation for a regression problem.
- Forgetting to reshape one-dimensional input into a two-dimensional feature matrix.
- Training on unnormalized tabular data with wildly different numeric scales.
- Evaluating only on training data and assuming the model generalizes.
- Expecting strong extrapolation outside the region covered by the original table.
Summary
- Predicting a function or numeric table in Keras is a regression task.
- Prepare aligned input features and target values, then train a dense model.
- Use a linear output layer and a regression loss such as
mse. - Normalize tabular inputs and keep a separate test split.
- Trust interpolation more than extrapolation unless you have strong evidence otherwise.

