# TensorFlow estimator DNNClassifier fails to fit simple data

The ready-to-use DNNClassifier in tf.estimator seems not able to fit these data:

X = [[1,2], [1,12], [1,17], [9,33], [48,49], [48,50]]
Y = [ 1,     1,      1,      1,      2,       3     ]


I've tried with 4 layers but it's fitting to 83% (=5/6 sampes) only:

hidden_units = [2000,1000,500,100]
n_classes    = 4


The sample data above are supposed to be separated by 2 lines (right-click image to open in new tab):

It seems stuck be cause of Y=2 and Y=3 are too close. How to change the DNNClassifier to fit to 100%?

Neural networks work poorly outside of relatively small numerical ranges on input. An ideal range is for each feature to be drawn from $$\mathcal{N}(0,1)$$ i.e. a Normal distribution with mean $$0$$ and standard deviation $$1$$. In your case, divide both parts of $$\mathbf{x}$$ by $$25$$ and subtract $$1$$ would probably suffice.
Your neural network architecture is completely overblown for the problem at hand. That may be because you were trying to force it to fit this data (and failing because of lack of normalisation). Try something more like: hidden_units = [20,10]
• @datdinhquoc: I can get 100% accuracy (in Keras) reliably using a simple network as I suggested, and around 500 epochs. It did take a few attempts with different hyperparameters. Probably one thing worth knowing is that tanh activations on hidden layers works better than relu for smaller networks. However, relu will work, you just need to make the NN slightly larger. – Neil Slater Aug 23 '19 at 10:17