RincewindWizzard
RincewindWizzard

Reputation: 53

Non-linear classification with tensorflow

I am new to machine learning and Tensorflow and want to do a simple 2-dimensional classification with data, that cannot be linear separated.

Current Result On the left side, you can see the training data for the model. The right side shows, what the trained model predicts.

As of now I am overfitting my model, so every possible input is fed to the model. My expected result would be a very high accurancy as the model already 'knows' each answer. Unfortunately the Deep Neural Network I am using is only able to separate by a linear divider, which doesn't fit my data.

This is how I train my Model:

def testDNN(data):
  """ 
  * data is a list of tuples (x, y, b), 
  * where (x, y) is the input vector and b is the expected output
  """
  # Build neural network
  net = tflearn.input_data(shape=[None, 2])

  net = tflearn.fully_connected(net, 100)
  net = tflearn.fully_connected(net, 100)
  net = tflearn.fully_connected(net, 100)


  net = tflearn.fully_connected(net, 2, activation='softmax')
  net = tflearn.regression(net)

  # Define model
  model = tflearn.DNN(net)

  # check if we already have a trained model
  # Start training (apply gradient descent algorithm)
  model.fit(
    [(x,y) for (x,y,b) in data], 
    [([1, 0] if b else [0, 1]) for (x,y,b) in data], 
    n_epoch=2, show_metric=True)

  return lambda x,y: model.predict([[x, y]])[0][0]

Most of it is taken from the examples of tflearn, so I do not exactly understand, what every line does.

Upvotes: 0

Views: 771

Answers (1)

squadrick
squadrick

Reputation: 770

You need an activation function in your network for non-linearity. An activation function is the way for a neural network to fit non-linear function. Tflearn by default uses a linear activation, you could change this to 'sigmoid' and see if the results improve.

Upvotes: 1

Related Questions