Machine Learning System Design Stage: Modelling

Paul Deepakraj Retinraj
5 min readJun 17, 2023

--

Earlier in this series:

Machine Learning System Design: Template

Machine Learning System Design Stage: Problem Navigation

Machine Learning System Design Stage: Data Preparation

Machine Learning System Design Stage: Feature Engineering

Introduction:

The modeling stage in machine learning system design is a crucial phase where practitioners make critical decisions about the type of problem, model selection, training process, and mitigating risks. This comprehensive blog dives deep into the intricacies of the modeling stage, exploring the type of ML problems, the importance of starting with simple models, the trade-offs and pros and cons of different modeling choices, considerations for deep learning models, addressing overfitting and regularization, iterative model improvement, training process, risk mitigation strategies, model interpretability, bias mitigation, and leveraging ensemble methods for enhanced performance.

Type of ML Problem:

Determining the type of ML problem is the first step in the modeling stage. Whether it’s a classification, regression, or unsupervised learning problem, understanding the nature of the problem sets the foundation for selecting appropriate modeling techniques and algorithms.

Starting with Simple Models:

It is often recommended to start with simpler models before diving into more complex ones. Simple models have fewer parameters and are easier to interpret. They provide a baseline performance and help establish a benchmark for model improvement.

Modeling Choices and Trade-Offs:

The modeling stage involves making choices between different algorithms and models. Each choice comes with its trade-offs. It is essential to understand the strengths and weaknesses of each model and consider factors such as interpretability, training time, complexity, and scalability. Analyzing the trade-offs empowers practitioners to make informed decisions that align with their specific problem and constraints.

Understanding Deep Learning and Large Models:

Deep learning models have gained significant attention due to their ability to handle complex patterns and large datasets. However, they come with computational and resource-intensive requirements. It is crucial to understand the trade-offs associated with deep learning, such as the need for massive amounts of training data, longer training times, and potential overfitting risks. Balancing these trade-offs is vital to ensure optimal model performance.

Justifying Model Selection and Overfitting Mitigation:

Justifying the choice of a specific model involves considering factors such as the problem's complexity, available resources, and desired performance. Mitigating overfitting, where the model learns the training data too well and fails to generalize to unseen data, is crucial. Regularization techniques, such as L1 and L2 regularization, help control overfitting and promote better generalization.

Iterative Model Improvement:

Model improvement is an iterative process that involves tweaking hyperparameters, incorporating feedback data, addressing underfitting or overfitting, and evaluating performance metrics. Continuous experimentation and fine-tuning lead to incremental enhancements in model accuracy and robustness.

Training Process and Risk Mitigation:

The training process includes preparing the data, splitting it into training and validation sets, selecting appropriate loss functions and optimization algorithms, and monitoring model convergence. Risks such as data leakage, biases, or data distribution shifts must be mitigated through careful preprocessing, feature engineering, and validation techniques.

Deep Learning Models:

Deep learning models, characterized by neural networks with multiple layers, offer remarkable capabilities for capturing complex patterns. However, they require extensive computational resources, significant amounts of labeled data, and careful hyperparameter tuning. Understanding the specific use cases where deep learning models excel is essential for informed decision-making.

Model Interpretability:

Interpreting models is crucial for building trust and understanding their decision-making processes. Techniques such as feature importance analysis, SHAP values, or model-agnostic methods like LIME can help uncover the factors influencing model predictions and provide insights into the underlying patterns in the data.

Addressing Model Bias and Mitigation:

Models can unintentionally inherit biases present in the training data, leading to unfair or discriminatory outcomes. Addressing model bias requires careful analysis of the data, preprocessing techniques, and evaluating model predictions across different demographic groups. Mitigation strategies, such as fairness-aware training or post-hoc bias correction, can be employed to ensure ethical and unbiased decision-making.

Ensembling Techniques for Enhanced Performance:

Ensemble methods, including bagging, boosting, stacking, blending, weighted averaging, and rank averaging, offer powerful ways to combine multiple models to achieve superior performance. Leveraging the diversity of individual models and their collective decision-making improves generalization and robustness.

Conclusion:

The modeling stage in machine learning system design requires a thoughtful and systematic approach. By considering the type of problem, starting with simple models, understanding trade-offs, justifying model selection, addressing overfitting, iterating on model improvements, mitigating risks, ensuring interpretability, addressing bias, and harnessing ensemble methods, practitioners can develop effective and reliable machine learning systems. By mastering the intricacies of the modeling stage, businesses can unlock the full potential of their data and pave the way for impactful AI-driven solutions.

Type of ML problem:

— — — Classification, Regression, Unsupervised model?

Start with a simple model — not with fancy models

Modeling choices/tradeoffs? — pros and cons of each model over the other.

Understand the trade-offs with deep learning and large models

Justify the decision to use a specific model. Overfitting and regularization

Iteratively move on to complex models

Training process?

Risks and how do you mitigate those risks?

Deep Learning models?

Model Improvements:

— — -Hyperparams, feedback data, over/underfitting, metrics based on the algo

Model Interpretability

Model Bias and Mitigation

Ensembling:

Bagging: Train multiple base models independently using bootstrapped samples, and combine their predictions through averaging or majority voting.

Boosting: Train models sequentially, adjusting instance weights to focus on misclassified samples, and combine predictions using a weighted majority vote.

Stacking: Train multiple base models, and use their predictions as input for a meta-model, which learns to combine them optimally.

Blending: Similar to stacking, but use a validation set to train the meta-model instead of cross-validated predictions from base models.

Weighted Averaging: Combine model predictions by assigning different weights to each model based on their performance or other criteria.

Rank Averaging: Rank the predictions of individual models, average the ranks, and convert them back to predictions.

Bayesian Model Averaging: Combine model predictions using Bayesian probabilities, considering both the model’s performance and uncertainty.

Ensemble Selection: Train a large number of candidate models and select a subset with the best performance or diversity to create an ensemble.

Majority Voting: Combine the predicted classes of multiple models by choosing the class with the highest vote count.

Error-Correcting Output Codes (ECOC): Train multiple binary classifiers on subsets of the output classes and use the ensemble to predict multiclass problems.

Further in this series:

Machine Learning System Design Stage: Model Evaluation

Machine Learning System Design Stage: Deployment

Machine Learning System Design Stage: Monitoring and Observability

--

--

Paul Deepakraj Retinraj

Software Architect at Salesforce - Machine Learning, Deep Learning and Artificial Intelligence. https://www.linkedin.com/in/pauldeepakraj/