4
$\begingroup$

I saw an article How to build a simple neural network in 9 lines of Python code and want to reconstruct the result in Mathematica. I tried the below codes:-

input = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}, {0, 1, 1}};
output = {0, 1, 1, 0};
asso = Thread[input -> output];
trained = NetTrain[LinearLayer[], asso]
trained[{1, 0, 0}]

The output is 0.577605, which is far away from the result of the Python code (e.g. 0.999937). How can I modify the code to have a more similar approach/result?

In the Python article, they are using sigmoid function as the layer. I want to do it in a similar way and to replace LinearLayer[] (replacement of ElementwiseLayer[Sigmoid] doesn't work), but I'm not sure how to do.

How can I get it done? Many thanks!

The question:-

enter image description here

$\endgroup$

1 Answer 1

6
$\begingroup$
input = {{0, 0, 1}, {1, 1, 1}, {1, 0, 1}, {0, 1, 1}};
output = {0, 1, 1, 0};
asso = Thread[input -> output];
net = NetChain[{LinearLayer[], ElementwiseLayer["Sigmoid"]}]
trained = NetTrain[net, asso]
trained[{1, 0, 0}]
(*0.995993*)
$\endgroup$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.