FreeCampus Python

Unit Challenge: Build a Baseline before a Bigger Model

Evaluate a simple classifier against a baseline while keeping test data out of fitting.
Open in Colab
  • Goal: Evaluate a simple classifier against a baseline while keeping test data out of fitting.
  • Estimated time: 60–120 minutes of active work.
  • Before starting: Complete the unit lessons.
  • Keep: Your source, observed outputs, checks, and a debugging note.

This community challenge is ungraded. Use the checks to review your own work; there is no submission service or automatic grade. Completion is self-reported in this browser on this device.

1. Build a baseline before a bigger model

Use sklearn.datasets.load_iris and train_test_split with test_size=0.25, random_state=42, stratify=y. Fit DummyClassifier(strategy=“most_frequent”) and DecisionTreeClassifier(max_depth=3, random_state=42) using training data only. Report test size, accuracy, and confusion matrix for each; explain matrix rows and columns.

Predict an ordinary result before coding. Start with the smallest part you can run and inspect. Use Colab for notebooks and the local workspace introduced in the units for packaging or command-line tasks.

2. Set up the experiment

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, test_size=0.25, random_state=42, stratify=y
)
# Fit both estimators on training data only.

The starter is deliberately incomplete. Implement the contract; do not change the expected results to match an incorrect implementation.

3. Check the observable results

  1. There are 112 training examples and 38 test examples, with all three classes in each.
  2. Each confusion matrix sums to 38; trace divided by 38 agrees with accuracy.
  3. The baseline predicts only its learned majority class; explain what the comparison tests.
  4. Record scikit-learn version, seed, parameters, and metrics; do not require exact accuracy across versions.

Record actual outputs beside predictions. Reduce a failure to a small example, change one cause at a time, and repeat the failed check after repairing it.

4. Change one condition

Try a deeper tree using a validation partition within the training set. Choose depth there, then evaluate once on the held-out test set. Explain why repeated test-driven choices would compromise the test.

5. Review a hint after attempting the task

Hint: connect the relevant tools

Fit only on the training partition and use accuracy_score and confusion_matrix. A baseline shows whether extra complexity improves the selected measure.

6. Explain and self-review

Keep partition counts, predictions, matrices, and an explanation of one error. Discuss why this small curated dataset cannot establish performance for new field conditions or justify using a transformer.

Review path: compare your result with the contract

Check the ordinary result first, then the boundary cases and changed condition. Explain which rule justifies each result. An implementation that differs from the hint can still satisfy the contract; explain why yours does.

7. Save your work and record completion

Save the notebook or project somewhere you control. Include one decision, one failed check, its repair, and a result you can reproduce. Record completion after reviewing the checks; you can undo it later.

Not yet recorded.

Return to the unit overview.

Back to top