tensorflow simple regression nan after >29 observations
The way you calculate the 'error' function is wrong.
You aggregated error value whenever you train the model. Therefore, the error value increases over time and reaches infinity (you can print the error value at each epoch to check that).
The error function should be computed as follows.


  error = tf.reduce_mean((y_hat - y_label)**2)


By the way, you can check the error value at each epoch.
Choose the hyperparameters of the model to make sure that the error value decreases in the time span.
Here is the error curve over the epoch span.