Challenge - 5 Problems
Neural Network Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of training a simple neural network
What will be the printed output of the training accuracy after fitting this neural network on the given data?
ML Python
from sklearn.neural_network import MLPClassifier from sklearn.datasets import load_iris from sklearn.model_selection import train_test_split X, y = load_iris(return_X_y=True) X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42) model = MLPClassifier(hidden_layer_sizes=(5,), max_iter=500, random_state=1) model.fit(X_train, y_train) print(f"Training accuracy: {model.score(X_train, y_train):.2f}")
Attempts:
2 left
💡 Hint
The model is trained with enough iterations on a simple dataset, so it should fit well.
✗ Incorrect
The MLPClassifier with 5 hidden neurons and 500 iterations on the Iris training set achieves perfect or near-perfect training accuracy, so the printed accuracy is 1.00.
❓ Model Choice
intermediate1:30remaining
Choosing the correct hidden layer size
Which hidden_layer_sizes parameter will create a neural network with two hidden layers, the first with 10 neurons and the second with 5 neurons?
Attempts:
2 left
💡 Hint
The tuple defines the number of neurons per hidden layer in order.
✗ Incorrect
The hidden_layer_sizes parameter takes a tuple where each number represents the neurons in each hidden layer. (10, 5) means first layer 10 neurons, second layer 5 neurons.
❓ Hyperparameter
advanced1:30remaining
Effect of max_iter on training
What will happen if max_iter is set too low (e.g., max_iter=1) when training an MLPClassifier on a dataset?
Attempts:
2 left
💡 Hint
Training too few iterations means the model does not learn enough.
✗ Incorrect
With max_iter=1, the model barely trains, so it underfits and training accuracy remains low.
❓ Metrics
advanced1:30remaining
Interpreting loss_curve_ attribute
What does the loss_curve_ attribute of a trained MLPClassifier represent?
Attempts:
2 left
💡 Hint
Think about what 'curve' means in this context.
✗ Incorrect
loss_curve_ stores the loss value at each iteration, showing how the model improved during training.
🔧 Debug
expert2:00remaining
Identifying error in neural network code
What error will this code raise when run?
from sklearn.neural_network import MLPClassifier
model = MLPClassifier(hidden_layer_sizes=5, max_iter=200)
model.fit([[0,0],[1,1]], [0,1])
ML Python
from sklearn.neural_network import MLPClassifier model = MLPClassifier(hidden_layer_sizes=5, max_iter=200) model.fit([[0,0],[1,1]], [0,1])
Attempts:
2 left
💡 Hint
scikit-learn accepts integers for hidden_layer_sizes, converting to a single-layer tuple.
✗ Incorrect
MLPClassifier accepts an integer for hidden_layer_sizes, which is interpreted as a single hidden layer with that many neurons. No error occurs.