Study guide

3.1 Selecting the Appropriate Algorithm for a Scenario

Databricks Certified Machine Learning Associate Study Guide Exam

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Databricks Machine Learning (38% of the Exam)

1.1 MLOps Best Practices on Databricks 1.2 Advantages of Databricks ML Runtimes and Compute Selection 1.3 Promoting Code vs. Promoting Models 1.4 How AutoML Facilitates Model and Feature Selection 1.5 AutoML Advantages in the Model Development Process 1.6 Feature Tables in Unity Catalog vs. the Workspace Feature Store 1.7 Creating a Feature Table and Writing Data to It 1.8 Training a Model with Features from a Feature Table 1.9 Scoring a Model with Features from a Feature Table 1.10 Online vs. Offline Feature Tables 1.11 Manually Logging Metrics, Artifacts, and Models in an MLflow Run 1.12 Identifying the Best Run with the MLflow Client API 1.13 Information Available in the MLflow UI 1.14 Registering a Model in the Unity Catalog Registry 1.15 Model Tags, Aliases, and Champion/Challenger Promotion

2 Chapter 2: Data Processing and ML Workflows (19% of the Exam)

2.1 Computing Summary Statistics on a Spark DataFrame 2.2 Creating Visualizations for Categorical and Continuous Features 2.3 Comparing Two Categorical or Two Continuous Features 2.4 Removing Outliers with Standard Deviation and IQR 2.5 When Log-Scale Transformation Is Appropriate 2.6 Comparing and Applying Mean, Median, and Mode Imputation 2.7 One-Hot Encoding and When It Is or Is Not Appropriate

3 Chapter 3: Model Development (31% of the Exam)

3.1 Selecting the Appropriate Algorithm for a Scenario 3.2 Methods to Mitigate Data Imbalance in Training Data 3.3 Comparing Estimators and Transformers 3.4 Developing a Training Pipeline 3.5 Tuning Hyperparameters with Hyperopt's fmin 3.6 Grid, Random, and Bayesian Search Strategies 3.7 Parallelizing Single-Node Models for Hyperparameter Tuning 3.8 Cross-Validation vs. a Train-Validation Split 3.9 Counting the Models Trained by Grid Search and Cross-Validation 3.10 Using Common Classification Metrics 3.11 Using Common Regression Metrics 3.12 Choosing the Most Appropriate Metric for the Objective 3.13 Exponentiating Log-Transformed Predictions Before Evaluation 3.14 Model Complexity and the Bias-Variance Tradeoff

4 Chapter 4: Model Deployment (12% of the Exam)

4.1 Differences and Advantages of Batch, Streaming, and Real-Time Serving 4.2 Performing Batch Inference with pandas and Spark UDFs 4.3 Streaming Inference with Delta Live Tables 4.4 Deploying a Custom Model to a Model Endpoint 4.5 Deploying, Querying, and Splitting Traffic Across Real-Time Endpoints

3.1 Selecting the Appropriate Algorithm for a Scenario

Key Takeaways Explain This Topic AI

The target type sets the problem class first: a continuous target means regression, a discrete label means classification, and each carries its own loss functions and metrics.

Linear and logistic regression buy interpretability and sub-millisecond inference at the cost of being unable to represent interactions without explicit feature engineering.

Random forests reduce variance by averaging deep, independently bagged trees; gradient boosted trees reduce bias by fitting shallow trees sequentially to residuals.

Tree ensembles need no feature scaling and tolerate mixed feature types, which is why they are the default first choice for tabular data.

The execution engine is a separate decision from the algorithm: use single-node libraries when the training set fits in memory, and pyspark.ml when it does not.

Last updated: August 2026

3.1 Selecting the Appropriate Algorithm for a Scenario

Selecting the optimal supervised learning algorithm is a foundational architectural decision in enterprise machine learning workflows on Databricks. The choice directly influences model interpretability, training duration, computational cost, memory footprint, and real-time inference latency. Machine learning practitioners must balance statistical expressiveness against operational constraints, selecting the right algorithm and execution paradigm (single-node vs. distributed Spark ML) for their specific dataset and business objective.

Supervised Learning Paradigms: Regression vs. Classification

Supervised learning tasks map input feature vectors x ∈ R d \mathbf{x} \in \mathbb{R}^d x ∈ R d to a known ground-truth label y y y . The mathematical structure of the label determines the paradigm: +-----------------------------------------------------------------------------+

  • | SUPERVISED LEARNING PROBLEM TAXONOMY |
  • | |
  • | +--------------------------------+ +--------------------------------+ |
  • | | REGRESSION | | CLASSIFICATION | |
  • | | Continuous Numeric Target | | Discrete Categorical Target | |
  • | | y in (-inf, +inf) or R+ | | y in {0, 1} or {C_k} | |
  • | +--------------------------------+ +--------------------------------+ |
  • | | Loss Functions: | | Loss Functions: | |
  • | | - Mean Squared Error (MSE / L2)| | - Binary Cross-Entropy / LogLoss| |
  • | | - Mean Absolute Error (MAE / L1)| | - Multi-Class Cross-Entropy | |
  • | | - Huber / Smooth L1 Loss | | - Hinge Loss (SVM) | |
  • | +--------------------------------+ +--------------------------------+ |
  • | | Examples: | | Examples: | |
  • | | - Customer Lifetime Value ($) | | - Credit Card Fraud (0 vs 1) | |
  • | | - Demand Forecasting (Units) | | - Churn Prediction (Yes / No) | |
  • | | - Machine Remaining Life (Days)| | - Document Category (1 of K) | |
  • | +--------------------------------+ +--------------------------------+ |
  • +-----------------------------------------------------------------------------+
  • Key Characteristics of Problem Types

Binary Classification: Target y ∈ { 0 , 1 } y \in \{0, 1\} y ∈ { 0 , 1 } . Models output predicted class probabilities p ^ = P ( y = 1 ∣ x ) ∈ [ 0 , 1 ] \hat{p} = P(y=1|\mathbf{x}) \in [0, 1] p ^ ​ = P ( y = 1∣ x ) ∈ [ 0 , 1 ] via a sigmoid activation σ ( z ) = 1 1 + e − z \sigma(z) = \frac{1}{1 + e^{-z}} σ ( z ) = 1 + e − z 1 ​ . Decisions are made by applying a decision threshold τ \tau τ (default 0.5 0.5 0.5 ).

Multiclass Classification: Target y ∈ { 1 , 2 , … , K } y \in \{1, 2, \dots, K\} y ∈ { 1 , 2 , … , K } with mutually exclusive classes. Models output probability distributions over K K K classes using the softmax function Softmax ( z i ) = e z i ∑ j = 1 K e z j \text{Softmax}(z_i) = \frac{e^{z_i}}{\sum_{j=1}^K e^{z_j}} Softmax ( z i ​ ) = ∑ j = 1 K ​ e z j ​ e z i ​ ​ .

Continuous Regression: Target y ∈ R y \in \mathbb{R} y ∈ R . Predictions y ^ = f ( x ) \hat{y} = f(\mathbf{x}) y ^ ​ = f ( x ) directly estimate the expected value E [ y ∣ x ] \mathbb{E}[y|\mathbf{x}] E [ y ∣ x ] , evaluated through residual metrics (RMSE, MAE, R 2 R^2 R 2 ).

Comprehensive Algorithm Taxonomy & Core Mechanics

Understanding the mathematical foundation of candidate algorithms allows engineers to diagnose model behavior, feature sensitivity, and failure modes. +-----------------------------------------------------------------------------+

  • | SUPERVISED ALGORITHM TAXONOMY |
  • | |
  • | LINEAR MODELS TREE-BASED MODELS ENSEMBLE ARCHITECTURES|
  • | +-------------------+ +-----------------+ +-----------------+ |
  • | | Linear Regression | | Decision Tree | | Random Forest | |
  • | | - OLS (Unreg.) | | - CART | | (Bagging + | |
  • | | - Ridge (L2) | | - Gini / Entropy| | Feature Subspace| |
  • | | - Lasso (L1) | | - Variance Red. | | Sampling) | |
  • | | - ElasticNet | +--------+--------+ +-----------------+ |
  • | | | | |
  • | | Logistic Regr. | +-------------> +-----------------+ |
  • | | - Binomial | | Gradient Boosted| |
  • | | - Multinomial | | Trees (GBT) | |
  • | +-------------------+ | - XGBoost | |
  • | | - LightGBM | |
  • | | - CatBoost | |
  • | | - Spark GBT | |
  • | +-----------------+ |
  • +-----------------------------------------------------------------------------+
  • Linear Models

Ordinary Least Squares (OLS): Solves min ⁡ w ∥ y − X w ∥ 2 2 \min_{\mathbf{w}} \|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2_2 min w ​ ∥ y − Xw ∥ 2 2 ​ . Unregularized linear regression is analytically computed via the normal equation w = ( X T X ) − 1 X T y \mathbf{w} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y} w = ( X T X ) − 1 X T y . If features are highly correlated (multicollinearity), X T X \mathbf{X}^T\mathbf{X} X T X becomes non-invertible or ill-conditioned, leading to extreme variance in weight estimates.

Ridge Regression (L2 Regularization): Adds a quadratic weight penalty: min ⁡ w ∥ y − X w ∥ 2 2 + λ ∥ w ∥ 2 2 \min_{\mathbf{w}} \|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2_2 + \lambda \|\mathbf{w}\|^2_2 min w ​ ∥ y − Xw ∥ 2 2 ​ + λ ∥ w ∥ 2 2 ​ . Ridge shrinks coefficients toward zero without forcing them exactly to zero. It stabilizes matrix inversion by solving ( X T X + λ I ) − 1 X T y (\mathbf{X}^T\mathbf{X} + \lambda \mathbf{I})^{-1}\mathbf{X}^T\mathbf{y} ( X T X + λ I ) − 1 X T y , effectively mitigating multicollinearity.

Lasso Regression (L1 Regularization): Adds an absolute weight penalty: min ⁡ w ∥ y − X w ∥ 2 2 + λ ∥ w ∥ 1 \min_{\mathbf{w}} \|\mathbf{y} - \mathbf{X}\mathbf{w}\|^2_2 + \lambda \|\mathbf{w}\|_1 min w ​ ∥ y − Xw ∥ 2 2 ​ + λ ∥ w ∥ 1 ​ . Due to the sharp diamond geometry of the L1 ball at zero axes, Lasso drives non-informative feature coefficients to exact zero, performing automatic embedded feature selection.

ElasticNet: Combines L1 and L2 penalties via a convex combination parameter α ∈ [ 0 , 1 ] \alpha \in [0, 1] α ∈ [ 0 , 1 ] : λ [ α ∥ w ∥ 1 + 1 − α 2 ∥ w ∥ 2 2 ] \lambda [\alpha \|\mathbf{w}\|_1 + \frac{1-\alpha}{2} \|\mathbf{w}\|^2_2] λ [ α ∥ w ∥ 1 ​ + 2 1 − α ​ ∥ w ∥ 2 2 ​ ] . When α = 1 \alpha=1 α = 1 , ElasticNet is equivalent to Lasso; when α = 0 \alpha=0 α = 0 , it is equivalent to Ridge. In PySpark ML, regParam defines λ \lambda λ and elasticNetParam defines α \alpha α .

Logistic Regression: Models the log-odds (logit) of a binary outcome: ln ⁡ ( p 1 − p ) = w T x + b \ln\left(\frac{p}{1-p}\right) = \mathbf{w}^T\mathbf{x} + b ln ( 1 − p p ​ ) = w T x + b . Trained using maximum likelihood estimation (MLE) minimizing binary cross-entropy loss. In PySpark ML, LogisticRegression supports binomial classification, multinomial classification, and ElasticNet regularization.

Decision Trees

Decision trees partition the feature space into orthogonal hyper-rectangles using recursive binary splitting. At each internal node, the algorithm evaluates all candidate split points across all features to maximize criterion purity gain:

Classification Splitting Criteria:

Gini Impurity: I G ( p ) = 1 − ∑ i = 1 C p i 2 I_G(p) = 1 - \sum_{i=1}^C p_i^2 I G ​ ( p ) = 1 − ∑ i = 1 C ​ p i 2 ​

Entropy (Information Gain): H ( p ) = − ∑ i = 1 C p i log ⁡ 2 ( p i ) H(p) = -\sum_{i=1}^C p_i \log_2(p_i) H ( p ) = − ∑ i = 1 C ​ p i ​ lo g 2 ​ ( p i ​ )

Regression Splitting Criteria: Variance reduction / Mean Squared Error reduction.

Behavior: Decision trees are non-parametric, handle non-linear boundaries naturally, and require no feature scaling. However, unconstrained decision trees have high variance and readily overfit training noise.

Random Forests (Bagging Ensemble)

Random Forests reduce the variance of individual decision trees through two orthogonal randomization mechanisms:

Bootstrap Aggregation (Bagging): Each tree is trained on an independently drawn bootstrap sample (sample with replacement of size N N N ) from the training set. Roughly 63.2% of unique records appear in each bootstrap sample; the remaining 36.8% form the Out-of-Bag (OOB) evaluation set.

Feature Subspace Sampling: At every internal node split, only a random subset m ≪ d m \ll d m ≪ d of candidate features is evaluated (typically m = d m = \sqrt{d} m = d ​ for classification, m = d / 3 m = d/3 m = d /3 for regression). This decorrelates individual trees, ensuring that strong dominant features do not dictate every tree's initial splits.

Inference: Class predictions are aggregated via majority voting; regression predictions are averaged across all trees.

Gradient Boosted Trees (Sequential Additive Boosting)

Unlike Random Forests where trees are constructed independently in parallel, Gradient Boosted Trees construct trees sequentially in an additive stage-wise manner: F m ( x ) = F m − 1 ( x ) + η ⋅ h m ( x ) F_m(\mathbf{x}) = F_{m-1}(\mathbf{x}) + \eta \cdot h_m(\mathbf{x}) F m ​ ( x ) = F m − 1 ​ ( x ) + η ⋅ h m ​ ( x )

where h m ( x ) h_m(\mathbf{x}) h m ​ ( x ) is a base weak learner (shallow decision tree) fit to the pseudo-residuals (negative gradients of the loss function L ( y , F m − 1 ( x ) ) \mathcal{L}(y, F_{m-1}(\mathbf{x})) L ( y , F m − 1 ​ ( x )) ), and η ∈ ( 0 , 1 ] \eta \in (0, 1] η ∈ ( 0 , 1 ] is the shrinkage (learning rate) parameter.

Key GBT Implementations on Databricks:

XGBoost ( xgboost.XGBClassifier / XGBRegressor ): Utilizes second-order Taylor expansion of the loss function (gradient and hessian), exact and approximate quantile split finding, built-in L1/L2 tree complexity regularization, and sparsity-aware split routing for missing values.

LightGBM ( lightgbm.LGBMClassifier / LGBMRegressor / synapse.ml.lightgbm ): Implements Gradient-based One-Side Sampling (GOSS) to filter small-gradient instances and Exclusive Feature Bundling (EFB) to bundle mutually exclusive sparse features. Employs leaf-wise (best-first) tree growth rather than depth-wise, achieving superior training speed and lower memory usage.

CatBoost: Implements ordered boosting to combat target leakage in small datasets and provides native, high-performance categorical encoding using target statistics calculated over permutation histories.

Spark ML GBT ( GBTClassifier / GBTRegressor ): Native distributed GBT implementation within pyspark.ml . Implements depth-wise boosting across distributed partitions.

Algorithm Tradeoff Evaluation Matrix

The table below details the performance, operational, and diagnostic tradeoffs across major supervised learning algorithm families:

Evaluation Dimension Linear / Logistic Regression Decision Trees Random Forest Gradient Boosted Trees (XGBoost/LightGBM/GBT)

Model Interpretability High (direct weight coefficients & odds ratios) High (visualizable if depth ≤ 4 \le 4 ≤ 4 ) Moderate (feature importances, SHAP values) Moderate to Low (requires SHAP / partial dependence plots)

Training Speed Extremely Fast (analytical or convex SGD) Fast (single tree greedy splitting) Moderate (embarrassingly parallel across trees) Slow to Moderate (sequential boosting steps)

Inference Latency Sub-millisecond (single dot product w T x \mathbf{w}^T\mathbf{x} w T x ) Sub-millisecond (few pointer checks) Low to Moderate (evaluates T T T trees) Low to Moderate (evaluates M M M boosting trees)

Memory Footprint Minimal (stores d d d float weights) Small (stores tree nodes) Large (stores hundreds of deep trees) Moderate (stores shallow constrained trees)

Non-Linear Relationships Poor (requires explicit polynomial features) Excellent (stepwise orthogonal partitions) Excellent (smooth non-linear approximations) State-of-the-Art (captures complex interactions)

Categorical Features Requires Encoding (One-Hot / Target encoding) Handles Natively (or via integer index) Handles Natively (or via string indexing) Exceptional (CatBoost/LightGBM native categorical bins)

Multicollinearity Sensitivity High (unregularized) to Low (Ridge/ElasticNet) Immune (selects one feature at split) Robust (subspace sampling spreads weight) Robust (splits on highest gain feature)

Outlier Sensitivity High (squared error pulls linear hyperplane) Robust (splits rank-ordered values) Robust (median/majority voting cushions outliers) Moderate (gradients can over-index on outliers if using MSE)

Feature Scaling Needed Mandatory (StandardScaler / MinMaxScaler) Not Required (invariant to monotonic scaling) Not Required (invariant to monotonic scaling) Not Required (invariant to monotonic scaling)

Single-Node vs. Distributed ML Architecture Selection

A critical Databricks Machine Learning Associate competency is recognizing when to execute training on a single virtual machine versus scaling to a multi-node Spark ML cluster. +-----------------------------------------------------------------------------+

  • | SINGLE-NODE VS. DISTRIBUTED ML DECISION |
  • | |
  • | DATASET SIZE ON DISK/RAM |
  • | | |
  • | +--------------------+--------------------+ |
  • | | | |
  • | Data Fits in Driver Memory Data Exceeds Single Machine |
  • | (e.g., < 50 GB - 100 GB) RAM (e.g., > 100 GB to TBs) |
  • | | | |
  • | v v |
  • | +---------------------------+ +---------------------------+ |
  • | | SINGLE-NODE ML LIBRARIES | | DISTRIBUTED SPARK ML | |
  • | | - Scikit-learn | | - pyspark.ml (Spark MLlib)| |
  • | | - Single-Node XGBoost | | - Distributed GBT/RF | |
  • | | - LightGBM / CatBoost | | - SynapseML (Spark LightGBM) |
  • | +---------------------------+ +---------------------------+ |
  • | | Architecture Benefits: | | Architecture Benefits: | |
  • | | - Zero network shuffle | | - Out-of-core scalability | |
  • | | - Ultra-fast iterations | | - In-memory cluster data | |
  • | | - Full Hyperopt/Optuna | | - Native Delta Lake scans | |
  • | | - GPU acceleration (CUDA) | | - Petabyte-scale pipelines| |
  • | +---------------------------+ +---------------------------+ |
  • +-----------------------------------------------------------------------------+
  • Detailed Selection Criteria

Choose Single-Node ML (Scikit-learn, XGBoost, LightGBM) When:

The aggregated training dataset (features + labels) comfortably fits inside single-node driver or single-worker memory (e.g., after feature aggregation, sampling, or filtering).

Model exploration demands rich algorithmic options not present in Spark ML (e.g., specialized loss functions, CatBoost native categorical handling, complex neural architectures).

Single-node training achieves faster wall-clock execution because it avoids Spark distributed network shuffles, serialization overhead, and partition scheduling latency.

Hyperparameter search is scaled across the cluster using hyperopt.SparkTrials , evaluating multiple single-node models concurrently across worker nodes.

Choose Distributed Spark ML ( pyspark.ml ) When:

The raw training dataset is hundreds of gigabytes or terabytes residing in distributed Delta tables, making driver memory collection ( toPandas() ) impossible (causing Out-Of-Memory / OOM crashes).

Feature transformations and modeling must execute within a unified, distributed pipeline ( pyspark.ml.Pipeline ) directly on Spark cluster executors.

End-to-end batch ETL and scoring workflows operate natively on Spark DataFrames without moving data out of the distributed Lakehouse boundary.

  • Implementation Code Examples
  • Single-Node XGBoost with Scikit-learn API import xgboost as xgb
  • from sklearn.model_selection import train_test_split
  • from sklearn.metrics import roc_auc_score
  • # Convert sampled Spark DataFrame to Pandas if memory permits
  • pdf = spark.table("lakehouse_gold.customer_features").sample(0.1, seed=42).toPandas()
  • X = pdf.drop(columns=["customer_id", "churned"])
  • y = pdf["churned"]

X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2, random_state=42, stratify=y)

  • # Instantiate and train single-node XGBoost
  • model = xgb.XGBClassifier(
  • n_estimators=300,
  • learning_rate=0.05,
  • max_depth=5,
  • subsample=0.8,
  • colsample_bytree=0.8,
  • reg_alpha=0.1,
  • reg_lambda=1.0,
  • random_state=42,
  • eval_metric="logloss"
  • )
  • model.fit(
  • X_train, y_train,
  • eval_set=[(X_val, y_val)],
  • verbose=False
  • )
  • val_preds = model.predict_proba(X_val)[:, 1]
  • print(f"Validation ROC-AUC: {roc_auc_score(y_val, val_preds):.4f}")
  • Distributed PySpark ML GBT Classifier from pyspark.ml.classification import GBTClassifier
  • from pyspark.ml.feature import VectorAssembler
  • from pyspark.ml.evaluation import BinaryClassificationEvaluator
  • # Load distributed Delta Lake table
  • df = spark.table("lakehouse_gold.customer_features")
  • feature_cols = ["age", "total_spend", "login_count", "support_tickets"]
  • assembler = VectorAssembler(inputCols=feature_cols, outputCol="features")
  • prepared_df = assembler.transform(df)

train_df, test_df = prepared_df.randomSplit([0.8, 0.2], seed=42)

  • # Distributed Gradient Boosted Tree Classifier
  • gbt = GBTClassifier(
  • featuresCol="features",
  • labelCol="churned",
  • maxIter=50,
  • maxDepth=5,
  • stepSize=0.05,
  • seed=42
  • )
  • gbt_model = gbt.fit(train_df)
  • predictions = gbt_model.transform(test_df)
  • evaluator = BinaryClassificationEvaluator(
  • labelCol="churned",
  • rawPredictionCol="rawPrediction",
  • metricName="areaUnderROC"
  • )
  • auc = evaluator.evaluate(predictions)
  • print(f"Distributed Spark GBT ROC-AUC: {auc:.4f}")

Loading diagram... Supervised Learning Algorithm Selection Workflow