Back to questions
JuniorTheoryCommon
What does this program print?
import numpy as np
from sklearn.neural_network import MLPClassifier
X = np.array([[0, 0, 1, 1], [1, 1, 0, 0], [0, 1, 1, 0], [1, 0, 0, 1]])
y = np.array([0, 1, 0, 1])
model = MLPClassifier(hidden_layer_sizes=(10,), max_iter=2000, random_state=0)
model.fit(X, y)
weights = sum(w.size for w in model.coefs_)
biases = sum(b.size for b in model.intercepts_)
print(weights + biases)61
- Expecting
72: with two classes the output layer has one neuron with a sigmoid, so the last layer holds10 * 1 + 1parameters, not10 * 2 + 2. - Expecting
50:intercepts_adds one intercept per neuron to the 50 weights, 10 in the hidden layer and 1 at the output.
- How would the count change with ten classes instead of two?
- How many parameters would a second hidden layer of 10 neurons add?