0
0
ML Pythonml~20 mins

Simple neural network with scikit-learn in ML Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Neural Network Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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}")
ATraining accuracy: 1.00
BTraining accuracy: 0.50
CTraining accuracy: 0.75
DTraining accuracy: 0.00
Attempts:
2 left
💡 Hint
The model is trained with enough iterations on a simple dataset, so it should fit well.
Model Choice
intermediate
1: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?
A(5, 10)
B(10, 5)
C10
D(15,)
Attempts:
2 left
💡 Hint
The tuple defines the number of neurons per hidden layer in order.
Hyperparameter
advanced
1: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?
AThe model will overfit and training accuracy will be very high.
BThe model will raise a runtime error and stop.
CThe model will train normally with no effect on accuracy.
DThe model will likely underfit and training accuracy will be low.
Attempts:
2 left
💡 Hint
Training too few iterations means the model does not learn enough.
Metrics
advanced
1:30remaining
Interpreting loss_curve_ attribute
What does the loss_curve_ attribute of a trained MLPClassifier represent?
AA list of loss values at each iteration during training.
BThe final loss value after training completes.
CThe weights of the neural network layers.
DThe accuracy values on the test set during training.
Attempts:
2 left
💡 Hint
Think about what 'curve' means in this context.
🔧 Debug
expert
2: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])
AValueError: hidden_layer_sizes must be a tuple
BTypeError: 'int' object is not iterable
CNo error, code runs successfully
DAttributeError: 'MLPClassifier' object has no attribute 'fit'
Attempts:
2 left
💡 Hint
scikit-learn accepts integers for hidden_layer_sizes, converting to a single-layer tuple.