CertSafari

    Free Databricks Certified Machine Learning Associate Sample Questions

    35 free sample questions from our bank of 240+, covering every exam domain, with answers and detailed explanations. Updated August 2026.

    Domain 1: Databricks Machine Learning

    1.14 Register a model using the MLflow Client API in the Unity Catalog registry

    1.Which MLflow Client API function is used to register a new model version to a three-level namespace in Unity Catalog?

    1. A.mlflow.create_registered_model()
    2. B.mlflow.register_model()
    3. C.mlflow.unity_catalog.create_model()
    4. D.mlflow.log_model()
    Show answer & explanation

    Correct answer: Bmlflow.register_model()

    • A. Incorrect. The `mlflow.create_registered_model()` function is used to create a new registered model *name* in the registry. It does not register a specific model *version* from a run, which is what the question asks for. The primary function for registering a version is `mlflow.register_model()`.
    • B. Correct. `mlflow.register_model()` is the function used to create a new model version in the registry from a logged model artifact. It takes a `model_uri` (e.g., `runs:/<run_id>/<artifact_path>`) and a `name`. When using Unity Catalog, this `name` argument accepts the three-level namespace format (`catalog.schema.model`). If the model name does not already exist, this function will create it before creating the new version.
    • C. Incorrect. This is not a valid function in the MLflow Client API. Unity Catalog integration is handled through standard MLflow functions by setting the registry URI to `databricks-uc` and using the three-level namespace in function arguments.
    • D. Incorrect. `mlflow.log_model()` saves a model as an artifact within an MLflow run. While this is a necessary prerequisite for registration, this function itself does not interact with the model registry or create a model version. The resulting `model_uri` from this step is passed to `mlflow.register_model()` to perform the registration.

    1.6 Create a feature store table in Unity Catalog

    2.A retail company wants to build a feature table to store daily aggregated sales data for each product in each store. The raw data has the columns `store_id`, `product_id`, `sales_date`, `total_sales`, and `units_sold`. The combination of `store_id` and `product_id` uniquely identifies the entity for which features are being computed over time. How should the primary key(s) be specified when creating this feature table?

    1. A.primary_keys='store_id'
    2. B.primary_keys=['store_id', 'product_id']
    3. C.primary_keys='sales_date'
    4. D.primary_keys=['store_id', 'product_id', 'sales_date']
    Show answer & explanation

    Correct answer: Bprimary_keys=['store_id', 'product_id']

    • A. Incorrect. Specifying only `store_id` as the primary key is insufficient. The problem states that the entity is uniquely identified by the combination of `store_id` and `product_id`. Using only `store_id` would lead to key collisions for different products within the same store.
    • B. Correct. This option correctly specifies a composite primary key using both `store_id` and `product_id`. This aligns with the requirement that this combination uniquely identifies the entity for which features are being computed. The `sales_date` column represents the time component and is typically specified as a `timeseries_columns` or `timestamp_lookup_key`, not as part of the primary entity key.
    • C. Incorrect. The `sales_date` is a temporal column that indicates when the feature values were recorded. It is not the primary key, which should identify the entity (the store-product combination) for which the features are being tracked over time.
    • D. Incorrect. While this combination would uniquely identify each row in the table, the primary key in a feature table is meant to identify the entity, not the specific observation. The entity is the `store_id`-`product_id` pair. Including the `sales_date` in the primary key conflates the entity key with the timestamp key, which is incorrect for feature store design.

    1.12 Manually log metrics, artifacts, and models in an MLflow Run.

    3.A developer needs to ensure that all parameters, metrics, and artifacts logged within a specific block of their Python script are grouped together into a single, new MLflow run. They also want to ensure that the run is properly terminated, even if an error occurs. What is the standard programmatic construct to achieve this?

    1. A.Calling mlflow.start_run() at the beginning and mlflow.end_run() at the end of the script.
    2. B.Using a `with mlflow.start_run():` context manager to wrap the logging calls.
    3. C.Creating a new MLflow Experiment for each group of logging calls.
    4. D.Calling mlflow.autolog() before the logging calls are made.
    Show answer & explanation

    Correct answer: BUsing a `with mlflow.start_run():` context manager to wrap the logging calls.

    • A. Incorrect. While manually calling `mlflow.start_run()` and `mlflow.end_run()` will create and terminate a run, it is not robust. If an error occurs after `start_run()` but before `end_run()` is called, the run will not be properly terminated and will be left in an 'active' state. This approach does not guarantee cleanup in case of exceptions.
    • B. Correct. Using a `with mlflow.start_run():` statement is the standard and recommended practice. This Python context manager ensures that a new MLflow run is started when entering the block, and it automatically and reliably calls `mlflow.end_run()` upon exiting the block. This guarantees that the run is properly terminated, even if an unhandled error occurs within the `with` block.
    • C. Incorrect. An MLflow Experiment is a higher-level organizational unit used to group multiple runs, typically for a specific project or problem. Creating a new experiment does not group logging calls into a single run; it simply determines where the next run will be logged. The grouping of logs (parameters, metrics, artifacts) happens at the run level.
    • D. Incorrect. `mlflow.autolog()` is a feature that automatically logs parameters, metrics, and models for supported machine learning frameworks. While convenient, it does not manage the lifecycle of a run. It logs to the currently active run, which still needs to be created and terminated properly, for which the `with mlflow.start_run():` context manager is the standard method.

    1.7 Write data to a feature store table

    4.A data science team has prepared a DataFrame `item_features_df` with the columns `item_id`, `category`, `price`, and `last_updated_ts`. They want to create a Feature Store table that will be used for both model training and serving in a low-latency online store. To ensure the online store always serves the most recent feature values for each item, what is the best way to create the table?

    1. A.`fs.create_table(name='fs_db.item_features', primary_keys='item_id', df=item_features_df)`
    2. B.`fs.create_table(name='fs_db.item_features', primary_keys='item_id', partition_cols='category', df=item_features_df)`
    3. C.`fs.create_table(name='fs_db.item_features', primary_keys=['item_id'], timestamp_keys='last_updated_ts', df=item_features_df)`
    4. D.`item_features_df.write.format('feature_store').save('fs_db.item_features')`
    Show answer & explanation

    Correct answer: C`fs.create_table(name='fs_db.item_features', primary_keys=['item_id'], timestamp_keys='last_updated_ts', df=item_features_df)`

    • A. Incorrect. This method is missing the `timestamp_keys` argument. Without a timestamp key, the Feature Store cannot determine which feature value is the most recent for a given primary key, which is a critical requirement for the online store serving use case. Additionally, the `primary_keys` argument should be passed as a list of strings, e.g., `['item_id']`.
    • B. Incorrect. While `partition_cols` can optimize query performance on the offline store, it does not solve the core problem of identifying the latest feature value for online serving. This option is also missing the essential `timestamp_keys` argument needed to track feature history and serve the most recent values.
    • C. Correct. This option correctly specifies `primary_keys=['item_id']` to uniquely identify each entity. Most importantly, it includes `timestamp_keys='last_updated_ts'`. This parameter designates the table as a time-series feature table, enabling the Feature Store to perform point-in-time lookups for training and to correctly retrieve the single most recent value for a given primary key during low-latency online serving.
    • D. Incorrect. This syntax uses the generic DataFrame writer API and is not the proper way to create and register a table with the Feature Store. The Feature Store client method, `fs.create_table`, is required to define essential metadata like `primary_keys` and `timestamp_keys`, which are fundamental to the Feature Store's functionality for both training and serving.

    1.16 Identify scenarios where promoting code is preferred over promoting models and vice versa

    5.A retail company deploys a recommendation engine that must be updated daily to reflect the latest user interactions and product inventory. The performance of the model is highly dependent on being trained on the most current data available. Which promotion strategy best supports this requirement?

    1. A.Promoting the model, to ensure stability and reduce daily computational overhead.
    2. B.Promoting the code, to enable the model to be retrained on fresh production data as part of the daily deployment process.
    3. C.A/B testing different promotion strategies to see which one performs better over time.
    4. D.Promoting the model, because the model architecture is not changing daily.
    Show answer & explanation

    Correct answer: BPromoting the code, to enable the model to be retrained on fresh production data as part of the daily deployment process.

    • A. Incorrect. Promoting a static model artifact prioritizes stability and reduces computational cost by avoiding retraining. This directly contradicts the core requirement of updating the model daily with the latest data, which is essential for the recommendation engine's performance.
    • B. Correct. Promoting the training code (the logic for training) allows the model to be retrained within the production environment using the most recent production data. This CI/CD pattern, often called 'promote code, retrain in prod', is ideal for scenarios where models must be frequently updated with fresh data to maintain accuracy and relevance.
    • C. Incorrect. A/B testing is a method for comparing the performance of different models or strategies in production, not a promotion strategy itself. While it could be used to evaluate the effectiveness of the daily retrained models, it does not describe the mechanism for generating those models.
    • D. Incorrect. While the model architecture might be stable, the model's parameters (weights) need to be updated daily based on new data. Promoting a pre-trained model artifact, even with a stable architecture, would result in a stale model that does not reflect the latest user behavior and inventory, failing to meet the business requirement.

    1.8 Train a model with features from a feature store table.

    6.Which class from the `databricks.feature_store` library is used to define the features to be retrieved from a feature table and joined into a training dataset?

    1. A.`FeatureTable`
    2. B.`FeatureLookup`
    3. C.`TrainingSet`
    4. D.`FeatureStoreClient`
    Show answer & explanation

    Correct answer: B`FeatureLookup`

    • A. Incorrect. While `FeatureTable` is a concept representing a table in the Feature Store, you interact with it via the `FeatureStoreClient`. This class itself is not used to define the specific features to be retrieved and joined for a training set.
    • B. Correct. The `FeatureLookup` class is used to define a join operation. It specifies the feature table to look into, the specific features (columns) to retrieve, and the key(s) to use for joining against the primary DataFrame. A list of `FeatureLookup` objects is passed to the `create_training_set` method.
    • C. Incorrect. The `TrainingSet` class is the object returned by the `create_training_set` method. It represents the final, assembled dataset containing the original data joined with the looked-up features. It is the result of applying one or more `FeatureLookup`s, not the class used to define them.
    • D. Incorrect. The `FeatureStoreClient` is the main client interface for interacting with the Feature Store. You use it to call methods like `create_training_set`, but it is not the class that defines the lookup specifications. The `FeatureLookup` class is passed as an argument to methods on the `FeatureStoreClient`.

    1.1 Identify the best practices of an MLOps strategy

    7.In the context of MLOps, what is the primary function of a feature store?

    1. A.To store and manage only the final trained machine learning models, ensuring they are versioned and deployed consistently across environments.
    2. B.To provide a centralized repository for documenting machine learning experiments and their results, tracking metadata and model lineage across runs.
    3. C.To enable the sharing, discovery, and reuse of features across different models, ensuring consistency between training and serving.
    4. D.To serve as a version control system for Databricks notebooks, managing code revisions and enabling collaborative editing of notebook content.
    Show answer & explanation

    Correct answer: CTo enable the sharing, discovery, and reuse of features across different models, ensuring consistency between training and serving.

    • A. Incorrect. A feature store is designed to manage features, not final trained models. Storing and versioning models for consistent deployment is the role of a model registry, such as the MLflow Model Registry.
    • B. Incorrect. This describes the function of an experiment tracking system like MLflow Tracking, which logs parameters, metrics, and artifacts. A feature store focuses on feature data, not experiment metadata or model lineage.
    • C. Correct. A feature store provides a centralized repository for features, enabling sharing, discovery, and reuse across models. It ensures consistency between training and serving by applying the same feature engineering logic, reducing training-serving skew.
    • D. Incorrect. This describes a version control system like Git, which manages code revisions and collaboration. A feature store is specifically for versioning, managing, and serving feature data, not notebook code.

    1.5 Identify the benefits of creating feature store tables at the account level in Unity Catalog in Databricks vs at the workspace level

    8.A company's compliance team mandates that all data assets, including features used for machine learning, must have a clear lineage trail and be discoverable through a single, central catalog. The company's ML teams work across several Databricks workspaces. Why is a Unity Catalog Feature Store the most suitable option?

    1. A.Because feature tables in Unity Catalog are standard Delta tables, their lineage is automatically captured and visible in Catalog Explorer alongside other data assets.
    2. B.Because workspace-local feature stores encrypt their metadata, the central catalog cannot index or surface feature tables for cross-workspace discovery and lineage tracking.
    3. C.Because Unity Catalog feature stores can automatically generate compliance reports, while workspace-local stores require manual extraction and assembly of lineage data.
    4. D.Because workspace-local feature stores do not support table comments or tags, the central catalog cannot associate feature tables with business metadata for discovery.
    Show answer & explanation

    Correct answer: ABecause feature tables in Unity Catalog are standard Delta tables, their lineage is automatically captured and visible in Catalog Explorer alongside other data assets.

    • A. Correct. Feature tables in Unity Catalog are standard Delta tables, so their lineage is automatically captured and visible in Catalog Explorer alongside other data assets. This provides a single, centralized, and auditable view of all data assets, directly fulfilling the compliance team's requirements for a clear lineage trail and discoverability across multiple workspaces.
    • B. Incorrect. Workspace-local feature stores do not encrypt their metadata in a way that prevents indexing; the real limitation is that their metadata is isolated within a single workspace's Hive metastore. This isolation makes cross-workspace discovery and lineage tracking difficult, unlike the centralized model of Unity Catalog.
    • C. Incorrect. Unity Catalog does not have a built-in feature to automatically generate compliance reports. While it provides the foundational tools for governance, lineage, and auditing, generating specific compliance reports typically requires querying the audit logs and lineage information that Unity Catalog makes available.
    • D. Incorrect. Workspace-local feature stores do support table comments and tags, so the central catalog can associate feature tables with business metadata. The key limitation is that this metadata is siloed within each workspace, preventing the centralized discovery and governance that Unity Catalog provides.

    1.3 Identify how AutoML facilitates model/feature selection.

    9.In the context of Databricks AutoML, which of the following best describes how it assists with feature selection?

    1. A.It requires the user to manually specify which features to include in the model through a configuration file, and then trains models using only those preselected features.
    2. B.It automatically and permanently removes all features with low correlation to the target variable before any models are trained, using a fixed threshold to discard them.
    3. C.It trains models that inherently perform feature selection (like tree-based models) and provides a data exploration notebook with feature importance charts.
    4. D.It only supports datasets with fewer than 10 features to simplify the selection process, and for larger datasets it requires manual feature reduction beforehand.
    Show answer & explanation

    Correct answer: CIt trains models that inherently perform feature selection (like tree-based models) and provides a data exploration notebook with feature importance charts.

    • A. Incorrect. Databricks AutoML is designed to automate the machine learning workflow, including feature selection, without requiring manual specification of features. Requiring a configuration file to preselect features would undermine its goal of reducing manual effort and accelerating experimentation.
    • B. Incorrect. AutoML does not permanently discard features based on a fixed correlation threshold before training. Instead, it evaluates feature importance dynamically during model training, allowing models to learn from all available data and capture complex relationships.
    • C. Correct. AutoML leverages tree-based models like LightGBM and XGBoost that inherently perform feature selection by identifying the most informative splits. Additionally, it generates a data exploration notebook with feature importance charts, giving users clear insights into which features are most impactful.
    • D. Incorrect. Databricks AutoML is built to handle datasets with many features, often numbering in the hundreds or thousands, without requiring manual reduction. Imposing a limit of fewer than 10 features would severely restrict its applicability to real-world, complex datasets.

    1.15 Identify benefits of registering models in the Unity Catalog registry over the workspace registry

    10.A data science team develops models in a dedicated 'dev' workspace and deploys them to a separate 'prod' workspace. Previously, using the workspace model registry, their MLOps process required complex scripts to copy or re-register models between workspaces. How does registering models in Unity Catalog simplify this workflow?

    1. A.Unity Catalog automatically retrains the model in the 'prod' workspace when a new version is registered in 'dev', using the production data sources and compute resources specified in the deployment configuration.
    2. B.Unity Catalog provides a UI button to 'migrate' a model, which automates the copy and re-registration process by transferring the model artifact and its associated metadata between the 'dev' and 'prod' workspaces.
    3. C.Unity Catalog models are registered to a central metastore, allowing the 'prod' workspace to directly access the model version without it being copied, once appropriate permissions are granted.
    4. D.Unity Catalog requires all models to be registered in a single, shared 'mlops' workspace, removing the need for separate environments and enabling direct deployment from the shared registry to production.
    Show answer & explanation

    Correct answer: CUnity Catalog models are registered to a central metastore, allowing the 'prod' workspace to directly access the model version without it being copied, once appropriate permissions are granted.

    • A. Incorrect. Unity Catalog does not automatically retrain models in any workspace. Retraining is a separate MLOps task that must be explicitly orchestrated, and Unity Catalog's role is governance and centralized access, not automated training.
    • B. Incorrect. There is no 'migrate' button in Unity Catalog for models. The simplification comes from the centralized metastore architecture, which allows direct access without copying or re-registration, not from a UI-driven migration tool.
    • C. Correct. Unity Catalog models are registered in a central metastore using a three-level namespace (catalog.schema.model). This allows any workspace attached to that metastore, such as 'prod', to directly access the model version once permissions are granted, eliminating the need for complex copy scripts.
    • D. Incorrect. Unity Catalog does not require a single shared workspace; it enables secure, governed sharing across multiple workspaces. Teams can maintain separate dev and prod environments while accessing the same centrally registered model.

    1.10 Describe the differences between online and offline feature tables

    11.A machine learning team is building a recommendation engine for an e-commerce platform. The model is retrained weekly using the entire customer purchase history. The model is then used to generate product recommendations for all users in a single daily batch job. Which type of feature table is most suitable for both the training and inference stages of this project?

    1. A.An online feature table, because the recommendations must be served to users.
    2. B.An offline feature table suits weekly retraining and daily batch inference.
    3. C.Both an online and an offline table are used to prevent train-serve skew.
    4. D.A streaming feature table to capture real-time user clicks for immediate use.
    Show answer & explanation

    Correct answer: BAn offline feature table suits weekly retraining and daily batch inference.

    • A. Incorrect. An online feature table is designed for low-latency, real-time feature retrieval, which is necessary when serving predictions to users as they interact with an application. Since this scenario describes a daily batch job for generating recommendations, the low-latency capability of an online table is not required.
    • B. Correct. The key characteristic of the described workload is that both model training (weekly) and inference (daily) are performed as large-scale batch jobs. Offline feature tables are specifically designed and optimized for handling large volumes of historical data for such batch processing, making them the most suitable and cost-effective choice.
    • C. Incorrect. Using both an online and an offline feature table is a common pattern to prevent train-serve skew in real-time serving scenarios. However, this is unnecessary here because inference is performed in batch mode, not real-time. The same offline feature table can be used for both training and inference, inherently avoiding train-serve skew.
    • D. Incorrect. A streaming feature table is used to ingest and process data from real-time streams to keep features up-to-date with minimal delay. The described use case involves weekly retraining on historical data and daily batch inference, which does not require real-time feature computation from a live data stream.

    1.2 Identify the advantages of using ML runtimes

    12.What is a primary advantage of using a Databricks Machine Learning (ML) Runtime compared to a standard Databricks Runtime for a machine learning workload?

    1. A.It is the only runtime that allows for the creation of Databricks notebooks.
    2. B.It comes pre-installed with popular, optimized machine learning libraries and frameworks.
    3. C.It automatically scales clusters down to zero workers when idle, reducing costs.
    4. D.It provides a built-in SQL query editor that is not available in the standard runtime.
    Show answer & explanation

    Correct answer: BIt comes pre-installed with popular, optimized machine learning libraries and frameworks.

    • A. Incorrect. Databricks notebooks are a core workspace feature available across all runtimes, including standard Databricks Runtime. The ML Runtime does not provide exclusive notebook creation capabilities.
    • B. Correct. The Databricks ML Runtime includes pre-installed, optimized versions of popular machine learning libraries like TensorFlow, PyTorch, and scikit-learn. This eliminates manual setup, ensures compatibility, and delivers performance improvements for ML workloads.
    • C. Incorrect. Automatic scaling down to zero workers is a cluster configuration option available for any runtime, not exclusive to the ML Runtime. It is not a feature tied to the runtime type.
    • D. Incorrect. The built-in SQL query editor is a workspace-level tool in Databricks and is available regardless of the runtime selected. It is not a feature introduced by the ML Runtime.

    1.17 Set or remove a tag for a model

    13.An MLOps team uses tags in the MLflow Model Registry to track validation status for each model version before promotion. They have registered a new model named `propensity_to_buy`, and version 1 has just passed validation. To comply with their governance process, they must add a tag with the key `status` and value `Validation Passed` to version 1. Which MLflow API call should be used?

    1. A.client.set_registered_model_tag(name='propensity_to_buy', key='validation_status', value='Validation Passed')
    2. B.client.update_registered_model(name='propensity_to_buy', description='Validation Passed')
    3. C.client.set_model_version_tag(name='propensity_to_buy', version='1', key='status', value='Validation Passed')
    4. D.client.log_param(run_id, 'validation_status', 'Validation Passed')
    Show answer & explanation

    Correct answer: Cclient.set_model_version_tag(name='propensity_to_buy', version='1', key='status', value='Validation Passed')

    • A. This sets a tag on the registered model object overall, not on a specific model version. Governance processes typically require validation status at the version level to track which exact version is ready for promotion. The correct API for version-specific metadata is `set_model_version_tag`. Additionally, the key used here (`validation_status`) does not match the required key (`status`).
    • B. This updates the description of the registered model, not a tag. Tags are key-value metadata separate from the description field. Using the description to convey validation status would be ambiguous and does not follow the team’s explicit requirement of using tags for governance.
    • C. This correctly uses the MLflow Client API to attach a custom tag (`status='Validation Passed'`) to a specific model version. According to official Databricks documentation, `set_model_version_tag` is the recommended method for recording validation status at the version level. This aligns with the team’s practice of tagging models with their validation status before promotion.
    • D. `log_param` records a parameter to an MLflow run (experiment), not to a model version in the registry. Parameters are used for experiment tracking and are not accessible as model version tags for governance workflows. Validation status recorded in a run would not be directly queryable or enforceable in the model registry promotion process.

    Domain 2: Data Processing

    2.9 Identify scenarios where log scale transformation is appropriate

    14.A machine learning engineer is building a model to predict customer lifetime value (LTV). A histogram of the LTV feature shows that most customers have a value between $50 and $500, but a small number of customers have values in the thousands, creating a long tail to the right. The engineer is using a linear regression model. Which transformation is most appropriate for the LTV feature to help meet the assumptions of the linear model?

    1. A.Log transformation
    2. B.One-hot encoding
    3. C.Standardization (Z-score scaling)
    4. D.Binarization
    Show answer & explanation

    Correct answer: ALog transformation

    • A. Correct. The description of the LTV feature having a long tail to the right indicates a right-skewed (or positively skewed) distribution. Log transformation is highly effective for this type of data. It compresses the range of the large values, making the distribution more symmetric and closer to a normal distribution. This helps to satisfy key assumptions of linear regression, such as linearity, homoscedasticity (constant variance of residuals), and normality of residuals.
    • B. Incorrect. One-hot encoding is a technique used exclusively for converting categorical features into a numerical format that machine learning models can understand. It is not applicable to continuous numerical variables like LTV and does not address issues of data distribution or skewness.
    • C. Incorrect. Standardization, or Z-score scaling, transforms the data to have a mean of zero and a standard deviation of one. While it is useful for putting features on the same scale, it does not change the fundamental shape of the distribution. A skewed distribution will remain skewed after standardization, so it is not the appropriate choice for correcting the skewness in the LTV feature.
    • D. Incorrect. Binarization converts a continuous numerical feature into a binary (0 or 1) feature based on a specified threshold. This is a drastic simplification that results in a significant loss of granular information about the magnitude of the LTV. It is not suitable for this problem and would severely impair the model's predictive power.

    2.1 Compute summary statistics on a Spark DataFrame using .summary() or dbutils data summaries

    15.An ML engineer is analyzing a massive DataFrame of sensor readings. Running the default `.summary()` method is taking too long to compute because it calculates all default statistics, including percentiles which are computationally expensive. For a specific report, the engineer only needs the total count of records and the standard deviation for the `temperature` column. Which code snippet correctly and efficiently computes only these specific statistics using the summary method?

    1. A.sensor_df.summary('count', 'stddev').show()
    2. B.sensor_df.describe().filter(col('summary').isin('count', 'stddev')).show()
    3. C.dbutils.data.summarize(sensor_df, precise=False)
    4. D.sensor_df.select(count('*'), stddev('temperature')).show()
    Show answer & explanation

    Correct answer: Asensor_df.summary('count', 'stddev').show()

    • A. Correct. The `.summary()` method in PySpark is designed to be flexible. By passing specific statistic names as string arguments ('count', 'stddev'), it computes only those specified statistics. This is highly efficient as it avoids calculating the expensive percentiles and other unneeded metrics mentioned in the problem description, directly addressing the engineer's performance issue while using the required method.
    • B. Incorrect. The `.describe()` method computes a fixed set of statistics (count, mean, stddev, min, max). While it provides the required data, it is inefficient because it calculates the mean, min, and max, which are not needed for the report. Filtering the results after the fact does not prevent the initial, unnecessary computation.
    • C. Incorrect. `dbutils.data.summarize()` is a Databricks-specific utility designed for exploratory data analysis, often producing a visual summary in a notebook. It is not the standard Spark DataFrame `.summary()` method and is not suited for programmatically selecting and returning specific statistics into a new DataFrame.
    • D. Incorrect. While this approach using `.select()` with aggregation functions is a very efficient way to compute these specific statistics in Spark, the question explicitly requires the solution to use the `.summary()` method. This answer fails to meet that specific constraint.

    2.8 Identify and explain the model types or data sets for which one-hot encoding is or is not appropriate.

    16.What is the primary purpose of applying one-hot encoding to a nominal categorical feature before training a linear model?

    1. A.To reduce the number of features and prevent overfitting by mapping the nominal categories to a single, more compact numerical representation.
    2. B.To convert the feature into a numerical format that the model can process without assuming an incorrect ordinal relationship.
    3. C.To scale the feature's values to be between 0 and 1, similar to Min-Max scaling, by converting each category into a binary vector for normalization.
    4. D.To handle missing values by creating a separate category for them, which is then converted into its own binary feature column by the encoder.
    Show answer & explanation

    Correct answer: BTo convert the feature into a numerical format that the model can process without assuming an incorrect ordinal relationship.

    • A. Incorrect. One-hot encoding does not reduce the number of features; it increases dimensionality by creating a new binary column for each category. This expansion can sometimes raise the risk of overfitting rather than prevent it, and it does not produce a single compact numerical representation.
    • B. Correct. Linear models require numerical inputs, and for nominal features with no inherent order, assigning arbitrary integers would imply a false ordinal relationship. One-hot encoding converts each category into a binary vector, enabling the model to process the feature numerically without assuming any incorrect ordering or distance between categories.
    • C. Incorrect. One-hot encoding is not a scaling technique like Min-Max scaling; it transforms categories into binary indicator columns (0 or 1) rather than scaling values to a continuous range. Its purpose is to represent categorical membership, not to normalize feature magnitudes.
    • D. Incorrect. Although missing values can be treated as a separate category and then one-hot encoded, this is a strategy for handling missing data, not the primary purpose of one-hot encoding. The fundamental goal is to appropriately represent existing nominal categories for machine learning algorithms.

    2.5 Compare and contrast imputing missing values with the mean or median or mode value

    17.When preparing a dataset for a regression model, a key numerical feature is found to have a heavily skewed distribution due to the presence of extreme outliers. Why is median imputation generally preferred over mean imputation in this situation?

    1. A.The median is computationally less expensive to calculate than the mean, making it faster to compute on large datasets with many features.
    2. B.The mean can only be used on data that has been scaled to a common range, while the median can be applied directly to raw, unscaled values.
    3. C.The median is robust to outliers and will provide a more representative value for the central tendency of the skewed data.
    4. D.The mean imputation will result in non-numeric values when applied to categorical features, making it incompatible with most regression models.
    Show answer & explanation

    Correct answer: CThe median is robust to outliers and will provide a more representative value for the central tendency of the skewed data.

    • A. Incorrect. The median is not computationally less expensive than the mean; calculating the median typically requires sorting the data (O(n log n)), while the mean can be computed in a single pass (O(n)). The choice between mean and median imputation is based on statistical robustness, not computational speed.
    • B. Incorrect. Both the mean and the median can be computed directly on raw, unscaled numerical data. Scaling is a separate preprocessing step and is not a prerequisite for calculating either measure of central tendency.
    • C. Correct. The median is robust to outliers because it is the middle value of the sorted data, unaffected by extreme values. In a heavily skewed distribution with outliers, the median provides a more representative central tendency than the mean, which can be pulled toward the tail.
    • D. Incorrect. Mean imputation on numerical features always produces numeric values, so it does not introduce non-numeric data. This statement incorrectly conflates mean imputation with categorical feature handling, which is not relevant to the scenario of a skewed numerical feature.

    2.2 Remove outliers from a Spark DataFrame based on standard deviation or IQR

    18.Which statement best describes the Interquartile Range (IQR) used for outlier detection?

    1. A.The range between the 95th percentile (P95) and the 5th percentile (P5) of the data distribution.
    2. B.The difference between the 75th percentile (Q3) and the 25th percentile (Q1) of the data.
    3. C.The absolute difference between the data's mean and its median, a measure often used to assess skew.
    4. D.The range calculated by multiplying the standard deviation by 1.5, a common factor for outlier fences.
    Show answer & explanation

    Correct answer: BThe difference between the 75th percentile (Q3) and the 25th percentile (Q1) of the data.

    • A. Incorrect. This describes a range based on the 5th and 95th percentiles, which covers 90% of the data and is sometimes called the interdecile range. The Interquartile Range (IQR) specifically measures the spread of the middle 50% of the data, not the 90% range.
    • B. Correct. The Interquartile Range (IQR) is defined as the difference between the 75th percentile (Q3) and the 25th percentile (Q1). It measures the dispersion of the middle 50% of the data and is commonly used in robust outlier detection methods, such as Tukey's fences (Q1 - 1.5*IQR and Q3 + 1.5*IQR).
    • C. Incorrect. The absolute difference between the mean and median is a measure of skewness, indicating asymmetry in the distribution. It is not related to the Interquartile Range, which is a measure of statistical dispersion based on quartiles.
    • D. Incorrect. This option confuses the IQR with a standard deviation-based method. The IQR is derived from percentiles, not standard deviation, and while a multiplier of 1.5 is often applied to the IQR to set outlier fences, the IQR itself is not calculated by multiplying the standard deviation by 1.5.

    2.3 Create visualizations for categorical or continuous features

    19.A data scientist is analyzing a categorical feature, `product_category`, which has a large number of unique categories with long names. They want to visualize the frequency count for each category. A standard vertical bar chart generated in a Databricks notebook is difficult to read because the x-axis labels are overlapping. Which is the most practical solution to this visualization problem?

    1. A.Use a pie chart, as its circular layout is better for many category labels.
    2. B.Switch to a horizontal bar chart to provide more space for category labels.
    3. C.Use a scatter plot to show the relationship between category and count.
    4. D.Convert the product categories to integers and create a histogram.
    Show answer & explanation

    Correct answer: BSwitch to a horizontal bar chart to provide more space for category labels.

    • A. Incorrect. Pie charts are generally unsuitable for visualizing data with a large number of categories. As the number of slices increases, it becomes very difficult for a human to distinguish between the sizes of the slices and interpret the chart effectively.
    • B. Correct. Switching to a horizontal bar chart is the most practical and common solution to this problem. This orientation places the long category labels on the vertical y-axis, which provides ample space and prevents them from overlapping, thus greatly improving readability.
    • C. Incorrect. Scatter plots are designed to show the relationship and correlation between two continuous numerical variables. They are not appropriate for visualizing the frequency counts of a single categorical variable.
    • D. Incorrect. Histograms are used to visualize the distribution of a single continuous variable, not categorical data. Converting categories to arbitrary integers and plotting a histogram would obscure the original meaning of the categories and produce a misleading visualization.

    Domain 3: Model Development

    3.1 Use ML foundations to select the appropriate algorithm for a given model scenario

    20.A financial services company wants to create a model to determine whether a loan application should be approved or denied. This is a binary outcome based on labeled historical data. Which of the following models is a suitable choice for this supervised learning problem?

    1. A.K-Means
    2. B.Principal Component Analysis (PCA)
    3. C.Gradient Boosted Trees Classifier
    4. D.K-Nearest Neighbors Regressor
    Show answer & explanation

    Correct answer: CGradient Boosted Trees Classifier

    • A. Incorrect. K-Means is an unsupervised learning algorithm used for clustering. It groups unlabeled data points into distinct clusters and is not suitable for a supervised binary classification task like loan approval, which requires predicting a specific outcome from labeled data.
    • B. Incorrect. Principal Component Analysis (PCA) is an unsupervised dimensionality reduction technique. Its primary purpose is to transform a set of correlated variables into a smaller set of uncorrelated variables, often used for feature extraction or data visualization. It is not a classification algorithm and cannot be used to make predictions.
    • C. Correct. Gradient Boosted Trees Classifier is a powerful supervised learning ensemble method specifically designed for classification tasks. It builds a strong predictive model by sequentially adding weak learners, making it an excellent choice for binary classification problems with labeled historical data, such as predicting loan approvals.
    • D. Incorrect. K-Nearest Neighbors (KNN) Regressor is a supervised learning algorithm used for regression tasks, which involve predicting a continuous numerical value. Since the problem requires predicting a binary categorical outcome (approve/deny), a classification algorithm is needed, making the regressor variant unsuitable.

    3.12 Use common regression metrics: RMSE, MAE, R-squared, etc.

    21.Which statement correctly describes the primary difference between Mean Absolute Error (MAE) and Root Mean Squared Error (RMSE) when evaluating a regression model?

    1. A.MAE is more sensitive to outliers than RMSE.
    2. B.RMSE penalizes large errors more heavily than MAE.
    3. C.MAE is calculated in squared units of the target variable, while RMSE is in the original units.
    4. D.A model with a lower MAE will always have a lower RMSE compared to another model.
    Show answer & explanation

    Correct answer: BRMSE penalizes large errors more heavily than MAE.

    • A. This statement is incorrect. MAE is less sensitive to outliers than RMSE. RMSE squares the difference between the actual and predicted values, which means that larger errors (outliers) have a disproportionately large effect on the final metric. MAE, on the other hand, takes the absolute value of the errors, treating all errors linearly according to their magnitude.
    • B. This statement is correct. Due to the squaring of the error term in its calculation, RMSE gives significantly more weight to large errors than MAE does. An error of 10 is penalized 100 times more than an error of 1 in RMSE, whereas in MAE it is only penalized 10 times more. This makes RMSE particularly useful when large errors are especially undesirable.
    • C. This statement is incorrect. Both MAE and RMSE are expressed in the original units of the target variable, which aids in their interpretation. Mean Squared Error (MSE), from which RMSE is derived, is in squared units. However, the final step in calculating RMSE is to take the square root of the MSE, which returns the metric to the original units.
    • D. This statement is incorrect. A model with a lower MAE will not always have a lower RMSE. Because RMSE is more sensitive to large errors, it is possible for a model with a few large errors to have a higher RMSE but a lower MAE compared to a model with many small-to-medium errors. The choice between them depends on whether large errors should be heavily penalized.

    3.13 Choose the most appropriate metric for a given scenario objective

    22.A real estate company is building a regression model to predict house prices. The dataset contains a few multi-million dollar mansions which are considered outliers. The company wants an evaluation metric that represents the typical prediction error in the original currency (e.g., US Dollars) and is less sensitive to the large errors caused by these outliers. Which metric is most appropriate for this scenario?

    1. A.Mean Squared Error (MSE)
    2. B.R-squared (R²)
    3. C.Root Mean Squared Error (RMSE)
    4. D.Mean Absolute Error (MAE)
    Show answer & explanation

    Correct answer: DMean Absolute Error (MAE)

    • A. Incorrect. Mean Squared Error (MSE) calculates the average of the squared differences between predicted and actual values. Squaring the errors heavily penalizes large errors, making this metric highly sensitive to outliers like the multi-million dollar mansions. Additionally, its units are the square of the original currency (e.g., dollars squared), which does not meet the requirement for interpretability in the original units.
    • B. Incorrect. R-squared (R²) measures the proportion of the variance in the dependent variable that is predictable from the independent variable(s). It is a unitless metric and does not represent the prediction error in the original currency. Therefore, it does not satisfy the core requirements of the scenario.
    • C. Incorrect. Root Mean Squared Error (RMSE) is the square root of MSE. While it addresses the units problem of MSE by being expressed in the original currency, it is still based on squared errors. This means it continues to be sensitive to outliers and gives disproportionate weight to large prediction errors, which is undesirable in this case.
    • D. Correct. Mean Absolute Error (MAE) calculates the average of the absolute differences between the predicted and actual values. It satisfies both requirements: it is expressed in the original currency (e.g., US Dollars), making it easily interpretable, and it is significantly less sensitive to outliers than MSE and RMSE because it does not square the errors. This makes it the most appropriate choice for representing the typical prediction error when outliers are present.

    3.7 Parallelize single node models for hyperparameter tuning

    23.A machine learning team is using Hyperopt with SparkTrials to tune a model. They have configured their cluster with 8 worker nodes. To maximize the use of their cluster, they set the parallelism parameter to 8. However, they observe that the tuning process is running much slower than expected and the cluster utilization is low. What is a likely cause of this issue?

    1. A.The training dataset is too small to benefit from parallelization.
    2. B.The objective function being optimized is not compatible with scikit-learn.
    3. C.The max_evals parameter in the fmin function was set to a value less than the parallelism level.
    4. D.The default Trials class was used instead of SparkTrials in the fmin function call.
    Show answer & explanation

    Correct answer: CThe max_evals parameter in the fmin function was set to a value less than the parallelism level.

    • A. Incorrect. The size of the training dataset affects the duration of each individual trial, but it does not directly limit the ability to run multiple trials in parallel. Even with a small dataset, setting a sufficient number of evaluations (`max_evals`) would allow Hyperopt to utilize all available workers.
    • B. Incorrect. Hyperopt is a general-purpose optimization library and is not tied to any specific machine learning framework like scikit-learn. An incompatibility between the objective function and the ML library would likely result in code errors, not in low cluster utilization during parallel tuning.
    • C. Correct. The `parallelism` parameter in `SparkTrials` specifies the maximum number of trials to run concurrently. The `max_evals` parameter in the `fmin` function specifies the total number of trials to evaluate. If `max_evals` is less than `parallelism` (e.g., `max_evals=4`, `parallelism=8`), Hyperopt will only schedule 4 trials. This means only 4 of the 8 available workers will be used, leading directly to the observed low cluster utilization and inefficient tuning process.
    • D. Incorrect. The question explicitly states that the team is using `SparkTrials`. If they had used the default `Trials` class, the tuning would run serially on the driver node, not in parallel on the workers. This would also result in low cluster utilization but contradicts the premise that `SparkTrials` was configured for parallel execution.

    3.6 Perform random or grid search or Bayesian search as a method for tuning hyperparameters.

    24.Which statement accurately describes a key difference between Grid Search and Random Search for hyperparameter tuning?

    1. A.Grid Search samples parameters from a statistical distribution, while Random Search tests every possible combination.
    2. B.Grid Search exhaustively tries every combination of a predefined set of hyperparameters, while Random Search samples a fixed number of combinations from specified distributions.
    3. C.Random Search is guaranteed to find the optimal hyperparameters, while Grid Search is not.
    4. D.Grid Search is only applicable to models with two or fewer hyperparameters, while Random Search can handle many.
    Show answer & explanation

    Correct answer: BGrid Search exhaustively tries every combination of a predefined set of hyperparameters, while Random Search samples a fixed number of combinations from specified distributions.

    • A. This statement is incorrect as it reverses the definitions of the two methods. Grid Search exhaustively tries every combination from a predefined grid of values, it does not sample from a distribution. Random Search, on the other hand, samples hyperparameter combinations from specified statistical distributions or ranges.
    • B. This statement is correct. Grid Search performs an exhaustive, systematic search over a manually specified subset of the hyperparameter space. It tests every single combination defined in the grid. Random Search, in contrast, samples a fixed number of random combinations from specified distributions or ranges, making it more efficient and often more effective, especially when some hyperparameters are more important than others.
    • C. This statement is incorrect. Neither Grid Search nor Random Search is guaranteed to find the global optimal hyperparameters. Grid Search's optimality is limited to the discrete points defined in its grid, which might miss better values between points. Random Search is a stochastic method and may not happen to sample the optimal combination.
    • D. This statement is incorrect. Grid Search can be applied to models with more than two hyperparameters. However, its practical use is limited by the 'curse of dimensionality,' as the number of combinations to test grows exponentially with the number of hyperparameters, making it computationally infeasible for high-dimensional spaces.

    3.3 Compare estimators and transformers

    25.A data scientist has a dataset with a categorical feature that needs to be converted into a numerical format suitable for a machine learning algorithm. The planned approach is to first map the string categories to numerical indices and then convert these indices into one-hot encoded vectors. Which sequence of Spark MLlib classes should be instantiated in a Pipeline to accomplish this?

    1. A.A `OneHotEncoder` followed by a `StringIndexer`.
    2. B.A `Tokenizer` followed by a `Word2Vec`.
    3. C.A `VectorAssembler` followed by a `StandardScaler`.
    4. D.A `StringIndexer` followed by a `OneHotEncoder`.
    Show answer & explanation

    Correct answer: DA `StringIndexer` followed by a `OneHotEncoder`.

    • A. This option is incorrect because the order of operations is reversed. The `OneHotEncoder` transformer requires a column of numerical category indices as input. Applying it directly to a column of raw strings would result in an error. The `StringIndexer` must be applied first to generate these required indices.
    • B. This option is incorrect. `Tokenizer` and `Word2Vec` are transformers used primarily for Natural Language Processing (NLP) tasks. `Tokenizer` splits text into words (tokens), and `Word2Vec` creates dense vector embeddings to capture semantic meaning, which is a different and more complex process than one-hot encoding a simple categorical feature.
    • C. This option is incorrect. `VectorAssembler` is used to combine multiple feature columns into a single feature vector, and `StandardScaler` is used for scaling numerical features. Neither of these transformers performs the required task of converting categorical string values into a numerical format.
    • D. This is the correct sequence. The `StringIndexer` estimator first scans the data to create a mapping from string categories to numerical indices (e.g., 'red' -> 0.0, 'blue' -> 1.0). Subsequently, the `OneHotEncoder` transformer takes this column of indices and converts each index into a binary sparse vector, which is the standard one-hot encoding format required by many machine learning algorithms in Spark MLlib.

    3.10 Identify the number of models being trained in conjunction with a grid-search and cross-validation process.

    26.A data scientist is performing a grid search to tune a machine learning model. The parameter grid includes 4 different values for the learning rate and 5 different values for the number of estimators. If the data scientist uses 3-fold cross-validation, how many total models will be trained?

    1. A.12
    2. B.20
    3. C.23
    4. D.60
    Show answer & explanation

    Correct answer: D60

    • A. Incorrect. This value is the product of the number of learning rates and the number of folds (4 * 3). This calculation incorrectly omits the 5 different values for the number of estimators.
    • B. Incorrect. This value represents the total number of unique hyperparameter combinations (4 learning rates * 5 estimators = 20). However, it fails to account for the cross-validation process, where each of these combinations is trained 3 times.
    • C. Incorrect. This value does not correspond to any logical combination or product of the given parameters (4, 5, and 3) and is therefore not a plausible result.
    • D. Correct. The total number of models trained during a grid search with cross-validation is the product of the number of values for each hyperparameter and the number of cross-validation folds. The calculation is: (4 learning rates) * (5 estimators) * (3 folds) = 60.

    3.11 Use common classification metrics: F1, Log Loss, ROC/AUC, etc

    27.A machine learning engineer is building a model to detect a rare disease. The cost of a false negative (failing to detect the disease) is extremely high, while the cost of a false positive (incorrectly flagging a healthy patient) is relatively low. Which metric should be prioritized when evaluating the model's performance?

    1. A.Precision
    2. B.Accuracy
    3. C.Recall (Sensitivity)
    4. D.Specificity
    Show answer & explanation

    Correct answer: CRecall (Sensitivity)

    • A. Incorrect. Precision measures the proportion of true positives among all predicted positives (TP / (TP + FP)). It answers the question 'Of all the patients we flagged with the disease, how many actually had it?'. Prioritizing precision aims to minimize false positives, but the scenario states that the cost of false positives is low. Focusing on precision could lead to a model that is overly cautious, missing actual positive cases and increasing costly false negatives.
    • B. Incorrect. Accuracy measures the overall proportion of correct predictions ((TP + TN) / Total). For imbalanced datasets, like rare disease detection, accuracy can be a highly misleading metric. A model could achieve very high accuracy by simply predicting every patient as negative (the majority class), while failing to identify any of the actual positive cases.
    • C. Correct. Recall, also known as sensitivity or the True Positive Rate, measures the proportion of actual positives that were correctly identified by the model (TP / (TP + FN)). It answers the question 'Of all the patients that actually have the disease, how many did we correctly identify?'. Since the cost of a false negative (failing to detect the disease) is extremely high, the primary goal is to minimize these misses. Prioritizing recall directly addresses this by rewarding the model for finding as many true positive cases as possible.
    • D. Incorrect. Specificity, or the True Negative Rate, measures the proportion of actual negatives that were correctly identified (TN / (TN + FP)). It answers the question 'Of all the healthy patients, how many did we correctly identify as healthy?'. Prioritizing specificity aims to minimize false positives. While this is generally desirable, the scenario explicitly states that the cost of a false positive is low compared to the extremely high cost of a false negative, making specificity a lower priority than recall.

    3.9 Perform cross-validation as a part of model fitting.

    28.An ML team has built a complete ML `Pipeline` in Spark MLlib which includes feature transformation stages and a final `LogisticRegression` estimator. They want to use `CrossValidator` to tune the `regParam` of the `LogisticRegression` model. How should they configure the `CrossValidator` to prevent data leakage from the feature transformation steps?

    1. A.First, run the feature transformation stages on the entire dataset, and then pass the transformed data to the `CrossValidator` with the `LogisticRegression` estimator.
    2. B.Manually split the data into training and validation sets before creating the `CrossValidator` instance.
    3. C.Set the entire `Pipeline` object (including feature transformers and the model) as the `estimator` for the `CrossValidator`.
    4. D.Apply the `CrossValidator` only to the feature transformation stages and ignore the `LogisticRegression` estimator.
    Show answer & explanation

    Correct answer: CSet the entire `Pipeline` object (including feature transformers and the model) as the `estimator` for the `CrossValidator`.

    • A. Incorrect. This approach is the primary cause of data leakage. By fitting feature transformers (like a scaler or imputer) on the entire dataset before cross-validation, information from the validation and test sets influences the training process. For example, the mean and standard deviation calculated by a scaler would be based on all data, contaminating the folds and leading to overly optimistic performance metrics.
    • B. Incorrect. `CrossValidator` is designed to perform the data splitting into K-folds internally. Manually splitting the data beforehand circumvents this core functionality and does not solve the underlying data leakage problem within the cross-validation process itself.
    • C. Correct. This is the canonical method in Spark MLlib to prevent data leakage during hyperparameter tuning. By passing the entire `Pipeline` object to the `CrossValidator`'s `estimator` parameter, the `CrossValidator` will, for each fold, fit the *entire pipeline* (including all feature transformation estimators) on only the training data for that fold. The resulting fitted pipeline is then used to transform the validation data for that fold to compute the evaluation metric. This ensures a strict separation between training and validation data at every stage.
    • D. Incorrect. The goal is to tune the `regParam` hyperparameter of the `LogisticRegression` model. Applying `CrossValidator` only to the feature transformation stages would not allow for the evaluation and tuning of the model itself. The `CrossValidator` must evaluate the performance of the entire workflow to select the best hyperparameters for the final estimator.

    3.14 Identify the need to exponentiate log-transformed variables before calculating evaluation metrics or interpreting predictions

    29.A data science team is comparing two models (Model A and Model B) for a house price prediction task. Both models were trained on the log-transformed price. On the log-transformed test data, Model A has a Root Mean Squared Error (RMSE) of 0.11 and Model B has an RMSE of 0.14. What is the most reliable next step to determine which model performs better in terms of actual prediction error in dollars?

    1. A.Select Model A, as its lower RMSE on the log-transformed data ensures a smaller prediction error in dollars after the required back-transformation.
    2. B.Select Model B, since a higher log-scale RMSE can signal better predictions for expensive homes and result in a lower overall error in dollars.
    3. C.Exponentiate the predictions from both models, and then re-calculate the RMSE using the original, non-transformed house prices.
    4. D.Retrain both models using the original, non-transformed house prices as the target variable, then calculate and compare their RMSE values directly.
    Show answer & explanation

    Correct answer: CExponentiate the predictions from both models, and then re-calculate the RMSE using the original, non-transformed house prices.

    • A. Incorrect. A lower RMSE on the log-transformed scale does not guarantee a smaller prediction error in dollars after back-transformation. The non-linear nature of the log transformation means that errors in log-space do not directly translate to errors in the original dollar scale, so selecting Model A based solely on its log-scale RMSE is unreliable.
    • B. Incorrect. A higher log-scale RMSE generally indicates worse performance on that scale, and there is no reliable principle suggesting it would lead to a lower overall error in dollars. This statement is misleading and not supported by the properties of log-transformed error metrics.
    • C. Correct. Since the models were trained to predict the log of the price, the predictions must be back-transformed to the original dollar scale using the exponential function. After exponentiating the predictions from both models, the RMSE should be recalculated using these back-transformed predictions and the original, non-transformed house prices. This is the only way to obtain a direct and reliable comparison of the models' performance in terms of actual prediction error in dollars.
    • D. Incorrect. Retraining the models is inefficient and unnecessary. The log transformation was likely applied for a valid reason, such as handling a skewed target distribution. The correct approach is to evaluate the existing models' predictions in the original scale, not to alter the training process.

    3.8 Describe the benefits and downsides of using cross-validation over a train-validation split.

    30.An ML team has developed a model and evaluated it using a single 80/20 train-validation split, reporting a high accuracy score. However, upon retraining and splitting the data again with a different random seed, the accuracy on the new validation set drops significantly. What benefit of cross-validation would have helped identify this performance instability earlier?

    1. A.Cross-validation trains the model faster by reusing the same data splits across epochs, allowing for more experiments.
    2. B.Cross-validation averages performance across multiple different splits, providing a more stable and reliable metric.
    3. C.Cross-validation uses less data for validation by holding out a single fold at a time, so the training set is always larger.
    4. D.Cross-validation is uniquely suited for distributed frameworks like Spark by partitioning the dataset into fully independent folds.
    Show answer & explanation

    Correct answer: BCross-validation averages performance across multiple different splits, providing a more stable and reliable metric.

    • A. Incorrect. Cross-validation does not train the model faster; it is computationally more expensive because it requires training and evaluating the model multiple times (once per fold). Reusing data splits across epochs is not a feature of cross-validation and would not help identify performance instability.
    • B. Correct. The scenario shows that a single train-validation split can produce highly variable accuracy depending on the random seed. Cross-validation mitigates this by averaging performance across multiple different splits, yielding a more stable and reliable metric that would have revealed the model's sensitivity to data partitioning.
    • C. Incorrect. While cross-validation does hold out one fold at a time for validation, the training set size per fold is not always larger than in a single split (e.g., in 5-fold CV, each training set is 80% of the data, same as an 80/20 split). More importantly, this property does not directly address the problem of performance instability across different random splits.
    • D. Incorrect. Cross-validation is a general evaluation technique and is not uniquely suited to distributed frameworks like Spark; both cross-validation and simple train-validation splits can be implemented in such environments. The ability to partition data into independent folds does not inherently detect performance instability caused by random split variation.

    3.4 Develop a training pipeline

    31.An ML engineer is working to improve a model's performance by searching for the optimal combination of hyperparameters. The team needs to run many training jobs in parallel to explore the hyperparameter space efficiently on their Databricks cluster. Which tool is specifically designed for managing and distributing this hyperparameter tuning process within the Databricks environment?

    1. A.A standard Python `for` loop that iterates through a predefined list of hyperparameter values on the driver node.
    2. B.The Hyperopt library, used with `SparkTrials` to distribute tuning runs across the cluster's worker nodes.
    3. C.The MLflow UI, which can be used to manually trigger and compare new training runs with different hyperparameters.
    4. D.Manually running multiple notebooks in parallel, each with a different set of hardcoded hyperparameters.
    Show answer & explanation

    Correct answer: BThe Hyperopt library, used with `SparkTrials` to distribute tuning runs across the cluster's worker nodes.

    • A. Incorrect. A standard Python `for` loop that iterates through a predefined list of hyperparameter values on the driver node runs sequentially and does not distribute work across the cluster. This approach fails to leverage Databricks' parallel processing capabilities, making it inefficient for large hyperparameter searches.
    • B. Correct. The Hyperopt library, used with `SparkTrials` to distribute tuning runs across the cluster's worker nodes, is specifically designed for parallel hyperparameter optimization in Databricks. It automates the search and efficiently scales across the cluster, significantly reducing tuning time.
    • C. Incorrect. The MLflow UI, which can be used to manually trigger and compare new training runs with different hyperparameters, is a tracking and comparison tool, not a distributed tuning orchestrator. It does not manage parallel execution or automate the hyperparameter search process across a cluster.
    • D. Incorrect. Manually running multiple notebooks in parallel, each with a different set of hardcoded hyperparameters, is an ad-hoc and unscalable method. It lacks the automation, coordination, and intelligent search algorithms provided by dedicated libraries like Hyperopt, and does not efficiently utilize cluster resources for a unified tuning job.

    Domain 4: Model Deployment

    4.5 Deploy and query a model for realtime inference

    32.When querying a Databricks Model Serving endpoint via its REST API, how must a client authenticate its request?

    1. A.By providing a Databricks workspace ID in the request header
    2. B.By passing the MLflow run ID as a query parameter
    3. C.By including a Databricks Personal Access Token (PAT) in the Authorization header
    4. D.By using the cluster ID where the model was trained for authentication
    Show answer & explanation

    Correct answer: CBy including a Databricks Personal Access Token (PAT) in the Authorization header

    • A. Incorrect. The Databricks workspace ID is an identifier for the specific workspace instance, but it is not a security credential and is not used for authenticating API requests.
    • B. Incorrect. An MLflow run ID uniquely identifies a model training run and its associated artifacts within the MLflow Tracking service. It is not an authentication token and cannot be used to authorize API calls.
    • C. Correct. Databricks REST APIs, including Model Serving, use token-based authentication. A client must include a valid Databricks Personal Access Token (PAT) in the `Authorization` header of the request (e.g., `Authorization: Bearer <token>`) to securely prove its identity and authorization.
    • D. Incorrect. The cluster ID identifies a specific computational resource used for tasks like model training, but it is entirely separate from the Model Serving infrastructure and plays no role in authenticating inference requests.

    4.2 Deploy a custom model to a model endpoint

    33.A data science team has logged a custom `pyfunc` model to the MLflow Model Registry. The model requires several specific Python libraries, including `scikit-learn==1.2.0`, `pandas==2.0.1`, and a custom internal library packaged as a wheel file. Which file within the logged MLflow model artifact is primarily used by Databricks Model Serving to create the correct environment and install these dependencies for the endpoint?

    1. A.`requirements.txt`
    2. B.`MLmodel`
    3. C.`model.pkl`
    4. D.`conda.yaml`
    Show answer & explanation

    Correct answer: D`conda.yaml`

    • A. Incorrect. While `requirements.txt` is a standard file for specifying Python dependencies, MLflow's `pyfunc` model flavor prioritizes the `conda.yaml` file for defining the execution environment. Databricks Model Serving relies on this `conda.yaml` file to ensure a reproducible environment, rather than `requirements.txt`.
    • B. Incorrect. The `MLmodel` file is a metadata file that defines the model's configuration, such as its flavors (e.g., `python_function`, `sklearn`), creation timestamp, and signature. It contains a reference to the environment file (like `conda.yaml`) but does not contain the list of dependencies itself.
    • C. Incorrect. The `model.pkl` file is the serialized model object itself. It contains the learned parameters and logic of the model but holds no information about the software dependencies required to run it.
    • D. Correct. The `conda.yaml` file is the primary file used by MLflow and Databricks Model Serving to create a reproducible environment for the model. It specifies the necessary channels, conda packages, and pip packages. This file can precisely define versions (`scikit-learn==1.2.0`, `pandas==2.0.1`) and can also include references to local wheel files for custom libraries, making it the definitive source for environment creation.

    4.4 Identify how streaming inference is performed with Delta Live Tables

    34.A machine learning engineer has an MLflow model named customer_churn_predictor in the Production stage of the Model Registry. They need to create a Lakeflow Spark Declarative Pipeline (SDP) that reads a continuous stream of customer activity and enriches it with a churn prediction. Which code snippet correctly defines the SDP pipeline for performing this inference?

    1. A.``` from pyspark import pipelines as dp import mlflow model_uri = "models:/customer_churn_predictor/Production" predict_udf = mlflow.pyfunc.spark_udf(spark, model_uri, result_type='boolean') @dp.table() def customer_predictions(): return ( spark.readStream.table("raw.customer_activity") .withColumn("predicted_churn", predict_udf("features")) ) ```
    2. B.``` import dlt import mlflow model_uri = "models:/customer_churn_predictor/Production" predict_udf = mlflow.pyfunc.spark_udf(spark, model_uri, result_type='boolean') @dlt.table def customer_predictions(): return ( dlt.read_stream("raw.customer_activity") .withColumn("predicted_churn", predict_udf("features")) ) ```
    3. C.``` from pyspark import pipelines as dp import mlflow model = mlflow.pyfunc.load_model("models:/customer_churn_predictor/Production") @dp.table() def customer_predictions(): return ( spark.readStream.table("raw.customer_activity") .withColumn("predicted_churn", model.predict("features")) ) ```
    4. D.``` from pyspark import pipelines as dp @dp.table() def apply_churn_model(): return spark.sql("APPLY MODEL customer_churn_predictor AS SELECT *, PREDICT(features) FROM raw.customer_activity") ```
    Show answer & explanation

    Correct answer: A``` from pyspark import pipelines as dp import mlflow model_uri = "models:/customer_churn_predictor/Production" predict_udf = mlflow.pyfunc.spark_udf(spark, model_uri, result_type='boolean') @dp.table() def customer_predictions(): return ( spark.readStream.table("raw.customer_activity") .withColumn("predicted_churn", predict_udf("features")) ) ```

    • A. This uses the Lakeflow SDP API correctly. It imports pyspark.pipelines as dp, creates a Spark UDF with mlflow.pyfunc.spark_udf() for distributed inference, reads the stream with spark.readStream.table("raw.customer_activity"), applies the UDF with .withColumn(), and defines the streaming table with @dp.table(). The table is materialized when the pipeline runs.
    • B. It uses the older Delta Live Tables API (import dlt, @dlt.table, dlt.read_stream). The question asks for a Lakeflow SDP pipeline, which uses from pyspark import pipelines as dp, @dp.table(), and spark.readStream.table() for external sources. dlt.read_stream() is for reading from other pipeline tables, not from an external table like raw.customer_activity.
    • C. mlflow.pyfunc.load_model() loads the model on the driver only. model.predict() cannot be used directly on a Spark DataFrame column for distributed inference. For scalable streaming inference, the model must be wrapped in a Spark UDF with mlflow.pyfunc.spark_udf().
    • D. APPLY MODEL and PREDICT() are Databricks SQL features, not valid inside a PySpark pipeline function. For SDP, use mlflow.pyfunc.spark_udf() to apply the model in Python.

    4.3 Use pandas to perform batch inference

    35.What is a key advantage of using the `mlflow.pyfunc` model flavor for performing batch inference with pandas DataFrames?

    1. A.It provides a standard, framework-agnostic interface, allowing models from different ML libraries (e.g., scikit-learn, TensorFlow) to be used for prediction with the same API.
    2. B.It automatically distributes the pandas DataFrame across multiple worker nodes for faster, parallelized inference, handling data partitioning and aggregating predictions from each worker.
    3. C.It is the only MLflow flavor that natively accepts pandas DataFrames as input, which simplifies deployment by avoiding manual serialization or conversion to other formats like NumPy.
    4. D.It automatically validates the input data against a linked Feature Store to prevent data drift, comparing input schema and statistics against training data before making predictions.
    Show answer & explanation

    Correct answer: AIt provides a standard, framework-agnostic interface, allowing models from different ML libraries (e.g., scikit-learn, TensorFlow) to be used for prediction with the same API.

    • A. Correct. The `mlflow.pyfunc` flavor provides a standard, framework-agnostic interface that wraps models from different ML libraries (e.g., scikit-learn, TensorFlow) into a consistent format. This allows batch inference jobs to use the same `predict` API on pandas DataFrames regardless of the underlying model implementation, simplifying deployment and maintenance.
    • B. Incorrect. The `mlflow.pyfunc` flavor does not automatically distribute pandas DataFrames across multiple worker nodes for parallelized inference. While it can be used to create a Spark UDF for distributed processing on Spark DataFrames, the `pyfunc` flavor itself executes predictions in a single process when used directly with pandas DataFrames.
    • C. Incorrect. The `mlflow.pyfunc` flavor is not the only MLflow flavor that natively accepts pandas DataFrames as input. Many native flavors, such as `mlflow.sklearn` and `mlflow.xgboost`, also accept pandas DataFrames directly, so manual serialization or conversion is not required for those flavors either.
    • D. Incorrect. The `mlflow.pyfunc` flavor does not automatically validate input data against a linked Feature Store to detect data drift. It focuses on providing a standard prediction interface, and any data validation or drift detection must be implemented as separate steps in the MLOps workflow before calling the model.

    Want the full experience?

    These are just samples. Practice the full Databricks Certified Machine Learning Associate question bank in quiz mode — free, no signup, with domain practice and exam simulation.