Ethical AI · Intermediate level

Intermediate level · Module 3: Identifying Bias in Datasets and AI Predictions · Lesson 1 of 3

Training a Baseline Model

A careful, reproducible scikit-learn baseline (logistic regression with a fixed random seed and stratified split) that later lessons analyse for bias.

In this lesson you will

  • Train and evaluate a baseline classifier
  • Make results reproducible

Key concepts

train/test splitstratifyrandom_stateLogisticRegressionaccuracy

The lesson

A baseline is a simple, transparent model that sets a reference point. Logistic regression is a good choice: it trains quickly on a modest laptop and its coefficients can be read.

Split the data into training and test sets with train_test_split, using stratify so that pass and fail cases (and ideally groups) are represented in both sets. Set random_state so that results are the same each time the notebook runs. Keep sensitive attributes such as gender in a separate column used for evaluation, even if they are not used as model inputs.

Report overall accuracy, but treat it only as a starting point. The next lessons show how an accurate model can still be unfair.

Step by step

  1. Select features (attendance, homework, prior score, school type) and the label (passed).
  2. Split with train_test_split(X, y, test_size=0.25, stratify=y, random_state=42), keeping gender and county_type aside for evaluation.
  3. Fit LogisticRegression(max_iter=1000) and compute test accuracy with accuracy_score.
  4. Record the accuracy and the features used in the notebook's markdown.

Practice activity

Train a reproducible baseline model for the project and record its accuracy and settings.

Expected result: A notebook cell sequence that produces the same accuracy on every run, with documented settings.

Check your understanding

  1. Why set random_state?

    Show answer

    So that the split and results are reproducible.

  2. Why keep gender for evaluation even if it is not a model input?

    Show answer

    To check whether the model's outcomes differ by gender.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.