Machine Learning Fundamentals with scikit-learn

Lesson 8 of 8

Final Project: Build a Complete Classifier Pipeline

Every piece from this course now exists on its own: loading and splitting data, training classifiers, evaluating with more than just accuracy, scaling features safely with Pipeline, and validating robustly with cross-validation and GridSearchCV. This final project assembles all of it into one complete, defensible ML workflow.

Requirements

Your finished ml_project.py should satisfy every one of these:

  1. Load a classification dataset (load_iris, load_wine, load_breast_cancer, or your own via make_classification) and split it with train_test_split.
  2. Build a Pipeline combining StandardScaler with a classifier of your choice.
  3. Fit the pipeline and report accuracy, a confusion matrix, precision, and recall on the held-out test set.
  4. Run cross_val_score on the same pipeline and print the mean cross-validated accuracy, does it roughly agree with your single-split test accuracy?
  5. Use GridSearchCV to tune at least one hyperparameter of your classifier, and report the best parameters found.
Pythonshares state with other Python blocks

Notice param_grid uses the key 'knn__n_neighbors', the double-underscore syntax lets GridSearchCV reach inside a Pipeline and tune a specific step's parameter, stepname__paramname.

Stretch goals

  • Try a different classifier in the pipeline (RandomForestClassifier, SVC, LogisticRegression) and compare cross-validated scores.
  • Try a different dataset (load_breast_cancer is a good binary-classification option) and see how precision/recall behave differently from a balanced multi-class problem like wine or iris.
  • Expand param_grid to tune more than one hyperparameter at once, GridSearchCV will try every combination.
  • Plot the confusion matrix visually instead of printing raw numbers (matplotlib is available in this sandbox too).

Submit a link to your finished project (a repo or gist) below, an instructor will review it before you can mark this lesson complete.

This lesson ends in a project. Build it on your own machine, there's nowhere to submit it here, but the brief above is everything you need.