Dung (Donny) Nguyen

Senior Software Engineer

Core Machine Learning Concepts

Introduction

Machine learning is the practice of building systems that learn patterns from data instead of following hand-written rules. Understanding its core concepts is essential for anyone working with AI-powered applications, building ML pipelines, or preparing for technical interviews in data science and AI engineering.

This article covers the foundational ideas that underpin nearly all machine learning work.


1. Types of Machine Learning

Machine learning problems fall into three main categories based on how the model learns from data.

Supervised Learning

The model trains on labeled examples, where each input has a known output. The goal is to learn a mapping from inputs to outputs so the model can predict the correct label for unseen data.

Examples:

Common algorithms: Linear Regression, Logistic Regression, Decision Trees, Random Forests, Support Vector Machines, Neural Networks.

Unsupervised Learning

The model trains on unlabeled data and discovers structure on its own. There are no target labels to guide learning.

Examples:

Common algorithms: K-Means Clustering, DBSCAN, Principal Component Analysis (PCA), Autoencoders.

Reinforcement Learning

An agent learns by interacting with an environment. It takes actions, receives rewards or penalties, and adjusts its behavior over time to maximize cumulative reward.

Examples:

Key concepts: agent, environment, state, action, reward, policy.


2. The Machine Learning Pipeline

A typical ML project follows a series of steps from raw data to a deployed model.

  1. Problem definition – Define the goal, the success metric, and whether ML is the right tool.
  2. Data collection – Gather training data from databases, APIs, scraping, or manual labeling.
  3. Exploratory Data Analysis (EDA) – Understand distributions, correlations, and outliers.
  4. Data preprocessing – Clean missing values, encode categorical features, normalize numerical features.
  5. Feature engineering – Create new features that improve predictive power.
  6. Model selection – Choose a model class appropriate for the problem and data size.
  7. Training – Fit the model on training data.
  8. Evaluation – Measure performance on a held-out test set.
  9. Hyperparameter tuning – Optimize model settings to improve performance.
  10. Deployment – Serve the model in production.
  11. Monitoring – Track performance over time and detect data drift.

3. Bias and Variance

Bias and variance describe two sources of prediction error.

Bias is the error introduced by oversimplifying the problem. A high-bias model makes strong assumptions and fails to capture real patterns. This leads to underfitting, where the model performs poorly on both training and test data.

Variance is the error introduced by sensitivity to small fluctuations in the training data. A high-variance model fits training data too closely and fails to generalize. This leads to overfitting, where the model performs well on training data but poorly on test data.

The bias-variance tradeoff describes the tension between these two types of error. Making a model more complex usually reduces bias but increases variance. The goal is to find the right level of complexity.

Common remedies:


4. Training, Validation, and Test Sets

To evaluate a model honestly, data is split into three subsets.

Training set – Used to fit the model parameters. The model sees this data during learning.

Validation set – Used to tune hyperparameters and make decisions about model architecture. The model does not train on this data, but choices are influenced by its performance here.

Test set – Used once, at the end, to estimate real-world performance. The model should never influence design decisions based on test set results.

A common split is 70% training, 15% validation, 15% test, but the right ratio depends on the total dataset size.

Cross-validation is a technique where the training data is split into k equal folds. The model trains on k−1 folds and validates on the remaining one, repeating this process k times. This gives a more reliable performance estimate when data is limited.


5. Evaluation Metrics

Choosing the right metric depends on the type of problem.

Classification Metrics

Regression Metrics


6. Regularization

Regularization reduces overfitting by adding a penalty to the loss function for model complexity.

L1 Regularization (Lasso) – Adds the sum of absolute values of weights to the loss. Encourages sparse weights by driving some to exactly zero. Useful for feature selection.

L2 Regularization (Ridge) – Adds the sum of squared weights to the loss. Shrinks weights toward zero but rarely to exactly zero. More stable than L1 when features are correlated.

Elastic Net – Combines L1 and L2 penalties.

Dropout – A regularization technique for neural networks where random neurons are disabled during each training step. This prevents the network from relying too heavily on any single neuron.


7. Gradient Descent and Optimization

Most machine learning models learn by minimizing a loss function, which measures the difference between the model’s predictions and the true labels.

Gradient Descent is the core optimization algorithm. It computes the gradient of the loss with respect to model parameters and takes a step in the direction that reduces the loss.

The learning rate controls the size of each step. Too large and training becomes unstable. Too small and training is slow.

Variants of gradient descent:

Common optimizers used in deep learning:


8. Feature Engineering and Preprocessing

Raw data is rarely ready for a model. Preprocessing and feature engineering transform data into a form that helps the model learn better.

Handling missing values:

Encoding categorical variables:

Scaling numerical features:

Feature selection:


9. Neural Networks

A neural network is a function composed of layers of interconnected nodes called neurons. It is the foundation of deep learning.

Structure:

Activation functions introduce non-linearity, allowing the network to learn complex mappings:

Backpropagation is the algorithm used to train neural networks. It computes gradients of the loss with respect to each weight by applying the chain rule of calculus, then gradient descent updates the weights.

Epochs and batches – One epoch means the model has processed all training examples once. Training typically runs for many epochs.


10. Key Model Families

Decision Trees and Ensembles

A decision tree splits data recursively based on feature thresholds, building a tree of yes/no decisions. Simple to interpret but prone to overfitting.

Random Forest builds many decision trees on random subsets of data and features, then averages their predictions. Reduces variance through ensemble averaging.

Gradient Boosting (XGBoost, LightGBM, CatBoost) builds trees sequentially, where each tree corrects the errors of the previous one. Often the best-performing algorithm for tabular data.

Linear Models

Linear Regression fits a weighted sum of input features to predict a continuous target. Logistic Regression applies a sigmoid to the same linear combination to predict binary probabilities.

These models are fast, interpretable, and work well when the relationship between features and target is approximately linear.

Support Vector Machines (SVM)

SVMs find the hyperplane that maximizes the margin between classes. They work well in high-dimensional spaces and with the kernel trick can model non-linear boundaries.


11. Transfer Learning

Training a large model from scratch requires substantial data and compute. Transfer learning reuses a model trained on one task as the starting point for a different but related task.

A model pre-trained on a large general dataset has already learned useful representations. Fine-tuning adapts these representations to a specific downstream task with far less data and compute.

Transfer learning is central to modern deep learning. Large language models and vision models are almost always used this way in practice.


12. Common Pitfalls

Data leakage – When information from outside the training set accidentally influences model training or evaluation. For example, scaling using statistics computed on the full dataset before splitting, or including features derived from the target. Leakage causes optimistically biased evaluation metrics.

Class imbalance – When one class appears far more frequently than another. Accuracy becomes misleading. Remedies include oversampling the minority class (SMOTE), undersampling the majority class, or adjusting class weights in the loss function.

Distribution shift – When the distribution of real-world data in production differs from training data. The model’s performance degrades because it was never exposed to the new patterns. Monitoring and periodic retraining help address this.

Target leakage – Including features that are causally downstream of the target in training data. The model learns to exploit these features but cannot use them in production because they are not yet available at prediction time.


Summary

Core machine learning concepts build on each other. Supervised, unsupervised, and reinforcement learning define the learning paradigm. The ML pipeline describes how a project flows from data to deployment. Bias-variance tradeoff, regularization, and proper evaluation practices determine whether a model generalizes. Gradient descent and optimization drive learning. Neural networks extend these ideas to complex, high-dimensional problems.

A solid grasp of these foundations makes it much easier to understand more advanced topics such as deep learning architectures, large language models, MLOps, and responsible AI.