Chapter 2

Implement a complete Data Science pipeline

Presentation & objectives

This session focuses on implementing complete data science workflows, from exploratory analysis in notebooks to production-ready machine learning systems. Students will learn to handle real-world data challenges including time-series analysis, geographic data processing, and the critical transition from experimental code to structured, maintainable ML pipelines.

Assessment Information

This session contributes to your final assessment through two complementary mini-projects. For detailed evaluation criteria and requirements, please refer to the Assessment Guidelines section.

This work must be completed in pairs. Each student must have their own Git account and make commits using their own account.

Learning Objectives

By the end of this session, students will be able to:

  • Analyze time-series data with geographic groupings and temporal dependencies
  • Handle missing data appropriately for time-dependent datasets
  • Implement cross-validation strategies that prevent data leakage in grouped data
  • Transform notebook code into modular, production-ready Python packages
  • Apply software engineering best practices for machine learning systems
  • Understand the transition from experimentation to production deployment

Activities

  1. Air Quality Data Analysis
  2. Towards Production-Ready ML (Homework)
  3. Structuring ML Code
  4. Hyperparameter Optimization
  5. MLOps Introduction
  6. Evaluation & Business Impact
Info

Before attending the practical session Structuring ML Code, you must read at home Towards Production-Ready ML.

Submission Guidelines

  • Deadline: December 14, 11:59 p.m.
  • Format: Link to the project’s GitLab repository
  • Deliverable: Complete Git repository with commit history
Warning

Important: Projects without appropriate Git history or with unbalanced commits between team members will be penalized. The quality of collaborative work is as important as the technical quality of the code.

Knowledge Check

Answer these questions once you have finished this course module.

--- primary_color: steelblue secondary_color: lightgray text_color: black shuffle_questions: false shuffle_answers: true --- # Why is GroupKFold cross-validation essential when working with geographic data in machine learning? 1. [ ] It reduces the total number of cross-validation folds needed 2. [x] It prevents data leakage by ensuring entire cities are either in training OR validation, never both 3. [ ] It automatically selects the best features for geographic prediction 4. [ ] It improves model performance by mixing geographic locations # What is the primary limitation of Jupyter notebooks for production machine learning systems? 1. [ ] They cannot handle large datasets efficiently 2. [x] They have non-linear execution, global state management issues, and limited reusability 3. [ ] They don't support advanced machine learning algorithms 4. [ ] They require expensive software licenses for deployment # When implementing hyperparameter optimization with GridSearchCV, what is the correct approach for geographic data? 1. [ ] Use standard KFold cross-validation with more folds 2. [ ] Apply GridSearchCV without any cross-validation strategy 3. [x] Combine GridSearchCV with GroupKFold to respect geographic boundaries during optimization 4. [ ] Use TimeSeriesSplit for all geographic datasets # What is the main advantage of transforming notebook code into a modular pipeline architecture? 1. [ ] It automatically improves model accuracy and performance 2. [x] It creates reusable components with clear responsibilities that are easier to test and maintain 3. [ ] It reduces the amount of code needed for machine learning projects 4. [ ] It eliminates the need for data preprocessing steps # Why is forward and backward fill particularly important for time-series data with geographic groupings? 1. [ ] It automatically removes outliers from the dataset 2. [x] It handles missing values while respecting temporal order and geographic boundaries 3. [ ] It improves model performance by creating more features 4. [ ] It standardizes the data distribution across different cities # What is the key principle behind systematic hyperparameter optimization in production ML systems? 1. [ ] Always use the most complex parameter grids possible 2. [ ] Optimize parameters manually based on domain expertise 3. [x] Balance exploration of parameter space with computational efficiency while preventing data leakage 4. [ ] Use random search instead of grid search for all scenarios # In a structured ML pipeline, what is the primary responsibility of the FeatureEngineer class? 1. [ ] Training models and evaluating their performance 2. [ ] Loading and cleaning raw data from various sources 3. [x] Transforming raw data into meaningful features through temporal and geographic extractions 4. [ ] Performing cross-validation and calculating metrics # Why is it important to maintain geographic integrity during model evaluation? 1. [ ] It reduces computational complexity and training time 2. [x] It ensures the model can generalize to completely new locations rather than memorizing city-specific patterns 3. [ ] It automatically selects the best features for prediction 4. [ ] It improves the visual quality of data visualizations # What trade-off must be considered when implementing hyperparameter optimization in production systems? 1. [ ] Model accuracy vs. data quality 2. [ ] Feature selection vs. data preprocessing 3. [x] Model performance improvements vs. computational costs and time constraints 4. [ ] Training data size vs. test data size # Which software engineering practice is most critical when transitioning from experimental notebooks to production ML systems? 1. [ ] Using the most advanced algorithms available 2. [ ] Maximizing the number of features in the model 3. [x] Implementing comprehensive testing with separation of concerns and modular design 4. [ ] Minimizing the amount of documentation needed # What is the correct approach for handling missing values in time-series data with multiple geographic locations? 1. [ ] Drop all rows with any missing values across the entire dataset 2. [x] Apply forward and backward fill within each geographic group independently 3. [ ] Use the global mean to fill all missing values 4. [ ] Interpolate missing values across all locations simultaneously # Why should model comparison be performed using statistical rigor rather than single performance metrics? 1. [ ] It reduces the computational cost of model training 2. [x] It ensures that performance differences are meaningful and not due to random variation 3. [ ] It automatically selects the best hyperparameters 4. [ ] It simplifies the model deployment process # What is the primary benefit of using MLflow for experiment tracking in machine learning projects? 1. [ ] It automatically improves model accuracy and performance 2. [ ] It reduces the computational cost of training models 3. [x] It provides systematic logging of parameters, metrics, and artifacts for reproducible and comparable experiments 4. [ ] It eliminates the need for cross-validation in model evaluation