Issue
Trying to build a Multilayer perceptron using only NumPy with iris flower dataset but I'm stuck with this:
Input layer of 4 nodes(iris dataset is shaped
(112,4)
).I want that my hidden layer consists of 3 nodes, so in theory, the correct shape would be
(112,3)
?
I know that each input has its own weights example:
input[0]
has weight[0]
etc..
The question is what shape should my random init weights have to be able to perform the dot product correct in order to get the right hidden layer output?
Solution
The number of parameters of your function should not depend on the number of entries in your dataset. From your comment it, you are having 112
feature of size 4
and you want to project those with a linear functia on to feature size of 3
. A fully connected layer comes down to matrix multiplication with optionally an additive bias. So in your case you only need to use a 4x3
matrix.
>>> x = np.random.rand(112,4)
>>> m = np.random.rand(4,3)
Inference:
>>> out = x@m # __maltmul__
>>> out.shape
(112, 3)
You could also add a bias:
>>> b = np.random.rand(1,3)
>>> out = x@m + b
Answered By - Ivan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.