I am working through an FNN tutorial, right now it outputs a sigmoid probability from 0-1 (0.8956 for example). My own data has 3+ possible targets so i need the output to be a list of the targets and the associated probability for testing on new samples. (In this instance it would be: 0 (probability), 1 (probability)). How would i go about this? Here is the code. Thanks.

import numpy as np

# sigmoid function
def nonlin(x,deriv=False):
    return x*(1-x)
    return 1/(1+np.exp(-x))

# input dataset
X = np.array([  [0,0,1],
                [1,1,1] ])

# output dataset            
y = np.array([[0,0,1,1]]).T

# seed random numbers to make calculation
# deterministic (just a good practice)

# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1

for iter in xrange(10000):

# forward propagation
l0 = X
l1 = nonlin(np.dot(l0,syn0))

# how much did we miss?
l1_error = y - l1

# multiply how much we missed by the 
# slope of the sigmoid at the values in l1
l1_delta = l1_error * nonlin(l1,True)

# update weights
syn0 += np.dot(l0.T,l1_delta)

print "Output After Training:"
print l1

If you have more than two targets, then you should use softmax activation instead of sigmoid. Softmax activation gives you the probability associated with each class in the output. The only thing you need to do before applying softmax is to convert your targets into one-hot encoded vectors. If you want to know more about softmax in detail, you can read about it here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.