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:
- Load a classification dataset (
load_iris,load_wine,load_breast_cancer, or your own viamake_classification) and split it withtrain_test_split. - Build a
PipelinecombiningStandardScalerwith a classifier of your choice. - Fit the pipeline and report accuracy, a confusion matrix, precision, and recall on the held-out test set.
- Run
cross_val_scoreon the same pipeline and print the mean cross-validated accuracy, does it roughly agree with your single-split test accuracy? - Use
GridSearchCVto tune at least one hyperparameter of your classifier, and report the best parameters found.
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_canceris a good binary-classification option) and see how precision/recall behave differently from a balanced multi-class problem like wine or iris. - Expand
param_gridto tune more than one hyperparameter at once,GridSearchCVwill 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.