Course materials · Introduction to Machine Learning

Multilayer Perceptron

English translation

Compare a complex model with a simple baseline classifier on the same data to examine whether complexity is always beneficial.

Before practice

01 What else changes when you increase MLP size?

Description

Greater representational capacity and more Parameters to learn require comparison with a simple baseline model.

02 Why is fitting preprocessing on the entire dataset a problem?

Description

Information from evaluation data can enter training preprocessing and distort the evaluation on new data.

Practice

Preview practice notebookDownload practice notebook

1. MLP and the Baseline Model

Starting conditions

Split Iris using the same 70/30 split as above, and fit StandardScaler only on Train.

Procedure

  1. Compare LogisticRegression(max_iter=500) and MLPClassifier(hidden_layer_sizes=(16,),max_iter=300,random_state=7).
  2. Record Train Accuracy, Test Accuracy, and whether convergence warnings occurred.

Results to retain

Items to record and points to check
Model
Train Accuracy
Test Accuracy
Iteration count and warnings

Points to check

  • Did you avoid refitting the scaler on test data?
  • Did you avoid hiding warnings and assuming that the result had converged?

2. Comparing Network Sizes

Starting conditions

Change only MLP's hidden_layer_sizes to (4,),(16,),(32,), and compare using the same metrics.

Procedure

  1. Reuse the preceding Train/Test split and Scaler fitted on Train. Train MLPs by changing only hidden_layer_sizes to (4,), (16,), and (32,).
  2. Keep max_iter=300, random_state=7, and the other settings unchanged. Record hidden size, train accuracy, test accuracy, and whether convergence warnings occur in a table.
  3. Explain how Train Accuracy and Test Accuracy each change as Hidden size increases, distinguishing cases with and without warnings.

Results to retain

Items to record and points to check
Hidden size
Train Accuracy
Test Accuracy
Convergence warnings

Points to check

  • Did you use the same split and preprocessing for each model?

3. Checking Other Inputs

Starting conditions

Compare the same two models with split seed=11 and examine variability in a small dataset.

Procedure

  1. Change only the split Seed to 11, refit the Scaler on the new Train set, and transform Train and Test.
  2. Retrain the Logistic Regression and Hidden (16,) MLP from Activity 1 on the new Train set with the same settings.
  3. Tabulate split seed, model name, Train Accuracy, and Test Accuracy, and compare with the two-model comparison at seed 7. Explain how changing the Test samples affected the comparison.

Results to retain

Items to record and points to check
Split Seed
Model and settings
Train·Test Accuracy
Comparing Different Splits

Points to check

  • Did you refit the scaler only on the new train data?