Using an output layer with a single neuron, a neural network can be used for data regression.
val reg = new NeuralNetworkRegressor()
This is the application of a neural network regression algorithm to the linear dataset
Without further hyperparameter tuning, the same network can also predict the cubic dataset reasonably well.