0
$\begingroup$

I work on a simple neural network for the detection of the forms, here is all the code on github: https://github.com/stodar/shapes/blob/main/saad.ipynb .

I get the same result even when I change the inputs, I redid the code several times but no result.

please do you have any idea?


corrects, wrongs = 0, 0

print('Target', '     Predicted', ' %')
for i in range(len(x_test)):
    input_vector = np.array(x_test[i], ndmin=2).T
    output_vector = np.dot(wh,  input_vector)
    output_vector = sigmoid(output_vector)
    output_vector = np.dot(wo, output_vector)
    res = sigmoid(output_vector)
    
    #Evaluate Model
    res_max = res.argmax()
    e = np.array(res_max)
    e = np.eye(3)[res_max]
    e.astype('int32')
    if np.array_equal(e,y_test[i]) :
        corrects += 1
    else:
        wrongs += 1
    
    print(y_test[i], ' ',e, '       ', np.max(res))
    
print("accuracy:", corrects / ( corrects + wrongs))
```
$\endgroup$

1 Answer 1

1
$\begingroup$

The line e.astype('int32') doesn't change the type of e, you need to save the result

Consider changing to:

e = e.astype('int32')

or:

if np.array_equal(e.astype('int32'),y_test[i])

Another thing: e = np.array(res_max) you override this line, you can just remove it.

Try run:

# Hidden Weight
wh = np.random.randn(no_of_hidden_nodes, no_of_in_nodes) * np.sqrt(28.0/no_of_in_nodes)
# Output Weight
wo = np.random.randn(no_of_out_nodes, no_of_hidden_nodes) * np.sqrt(28.0/no_of_hidden_nodes)

corrects, wrongs = 0, 0

print('Target', '     Predicted', ' %')
for i in range(len(x_test)):
    input_vector = np.array(x_test[i], ndmin=2).T
    output_vector = np.dot(wh,  input_vector)
    output_vector = sigmoid(output_vector)
    output_vector = np.dot(wo, output_vector)
    res = sigmoid(output_vector)
    
    #Evaluate Model
    res_max = res.argmax()
    e = np.array(res_max)
    e = np.eye(3)[res_max]
    e = e.astype('int32')
    if np.array_equal(e,y_test[i]) :
        corrects += 1
    else:
        wrongs += 1
    
    print(y_test[i], ' ',e, '       ', np.max(res))
    
print("accuracy:", corrects / ( corrects + wrongs))

And tell me if the result is different.

$\endgroup$
7
  • $\begingroup$ Yes, but the problem is that I always receive the same output, so there is an error in the code or something else. $\endgroup$ Commented Aug 18, 2021 at 15:56
  • $\begingroup$ Share an example of output and input (what is the output you always get?) $\endgroup$ Commented Aug 18, 2021 at 15:59
  • $\begingroup$ github.com/stodar/shapes/blob/main/saad.ipynb $\endgroup$ Commented Aug 18, 2021 at 16:00
  • $\begingroup$ what are the values of wh and wo.. you don't change them, maybe they are biased to choose always 3rd answer. If you will random them again and re-run the code, the answer will probably change. $\endgroup$ Commented Aug 18, 2021 at 16:09
  • $\begingroup$ Yes, I have already tried but nothing new :/ $\endgroup$ Commented Aug 18, 2021 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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