CertSafari

    Free Databricks Certified Machine Learning Associate - December 9 onwards Sample Questions

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

    1: Databricks Machine Learning

    1.16: Promote a challenger model to a champion model using aliases

    1.The `champion` alias on `ml.prod.churn` was just moved from version 5 to version 7, but the Mosaic AI Model Serving endpoint for the model still answers with version 5 behavior. The endpoint's served entity was configured with an explicit version number. Which TWO actions make the endpoint serve the new champion? (Select all that apply.)(Select 2)

    1. A.Resolve the version with `get_model_version_by_alias("ml.prod.churn", "champion")` and update the endpoint's served entity to that `entity_version`
    2. B.Add the endpoint-update step to the promotion job right after the alias assignment, so serving follows `champion` each time it is moved
    3. C.Wait for the alias change to propagate, because serving endpoints re-read alias assignments automatically once a day without any update
    4. D.Rename the registered model so the endpoint must re-resolve its served entity from the three-level Unity Catalog name on the next request
    5. E.Call `transition_model_version_stage` on version 7 with the Production stage, which causes the endpoint to switch its served version
    Show answer & explanation

    Correct answers: A, B — Resolve the version with `get_model_version_by_alias("ml.prod.churn", "champion")` and update the endpoint's served entity to that `entity_version`; Add the endpoint-update step to the promotion job right after the alias assignment, so serving follows `champion` each time it is moved

    • A. Correct. The endpoint serves the version recorded in its configuration, so the promotion process looks up the version behind the alias and updates the served entity accordingly.
    • B. Correct. Chaining the endpoint update directly after the alias change keeps serving and the alias in step, so a promotion does not leave the endpoint on the old version.
    • C. Incorrect. A served entity pinned to a version number does not follow later alias moves on a timer, so waiting never changes what the endpoint serves.
    • D. Incorrect. Renaming a registered model breaks references and downstream consumers, and does not make an endpoint with a pinned version adopt the champion.
    • E. Incorrect. Unity Catalog models do not support stages, so there is no stage transition to call, and it would not alter the endpoint's configured version anyway.

    1.2: Identify the advantages of using ML runtimes

    2.A data scientist's training notebook fails on a new standard-runtime cluster with `ModuleNotFoundError` for scikit-learn and XGBoost, and the team wants every future cluster to start with these libraries ready without per-notebook installs. What should they do?

    1. A.Turn on Photon for the cluster, which adds an optimized execution layer that ships scikit-learn and XGBoost in the cluster image.
    2. B.Create the cluster with the Machine learning option selected, which runs Databricks Runtime ML with scikit-learn and XGBoost preinstalled.
    3. C.Run `%sh pip install scikit-learn xgboost` on the driver, which places the packages in the Python environment the worker nodes use.
    4. D.Attach the notebook to a serverless SQL warehouse, which provides a managed Python environment with the common ML libraries included.
    Show answer & explanation

    Correct answer: B — Create the cluster with the Machine learning option selected, which runs Databricks Runtime ML with scikit-learn and XGBoost preinstalled.

    • A. Photon is a native vectorized execution engine that speeds up Spark SQL and DataFrame workloads. It does not change which Python packages are in the runtime image, so the import would still fail on a new cluster.
    • B. Choosing the Machine learning option runs Databricks Runtime ML, whose image ships scikit-learn, XGBoost and other common ML libraries. Clusters created this way start with them available, so notebooks need no install step.
    • C. A `%sh pip install` modifies only the driver node's own environment, and workers do not read it. It is also a manual step that is lost on restart and absent from each new cluster, so it does not give a standing setup.
    • D. SQL warehouses are built for SQL queries and do not host Python notebooks for ML model training. They provide no bundled Python ML environment and are not a substitute for choosing the ML runtime on a cluster.

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

    3.A company wants data scientists in several workspaces to discover and reuse features. Which THREE statements describe how Unity Catalog feature tables support this?(Select 3)

    1. A.Feature tables belong to the metastore, so workspaces attached to that metastore can see the same feature tables, limited by privileges.
    2. B.The Features UI can search feature tables and features by table name, feature name, comment, or tag key and value.
    3. C.Tags can be added to feature tables and features through Catalog Explorer or SQL, making them searchable by shared conventions.
    4. D.Views defined over Unity Catalog tables are listed in the Features UI like feature tables, so teams can share logic without storing data.
    5. E.Feature tables are scoped to the workspace that created them, so other workspaces need a copy in a catalog bound to them for discovery.
    Show answer & explanation

    Correct answers: A, B, C — Feature tables belong to the metastore, so workspaces attached to that metastore can see the same feature tables, limited by privileges.; The Features UI can search feature tables and features by table name, feature name, comment, or tag key and value.; Tags can be added to feature tables and features through Catalog Explorer or SQL, making them searchable by shared conventions.

    • A. Correct. Unity Catalog objects belong to the metastore rather than to one workspace, so workspaces attached to it see the same feature tables, filtered by privileges.
    • B. Correct. The Features UI provides search over table names, feature names, comments, and tags, which helps teams find reusable features.
    • C. Correct. Tags on feature tables and features can be managed in Catalog Explorer or with SQL and then used as search terms across workspaces.
    • D. Incorrect. The Features UI lists tables that carry a primary key constraint, and views do not qualify. A view therefore cannot be found there, and logic shared as a view would not be discoverable through feature search.
    • E. Incorrect. A feature table is a Unity Catalog table that belongs to the metastore, not to the workspace that created it. Other workspaces on the metastore discover and read it directly, subject to privileges, so no copy is needed.

    1.6: Train a model with features from a feature store table

    4.A team trains a scikit-learn model on a DataFrame from `load_df()` and logs it with `fe.log_model(model=model, artifact_path='model', flavor=mlflow.sklearn, training_set=training_set, registered_model_name='ml.recsys.rating_model')`. Which TWO outcomes result from passing `training_set`?(Select 2)

    1. A.A snapshot of the training feature values is stored with the model, so scoring replays those saved values even after the feature table is updated.
    2. B.The model is published to an online store at logging time, so serving requests read low-latency storage and skip the Delta feature table.
    3. C.Feature metadata is stored only for pyfunc models, so with `flavor=mlflow.sklearn` the caller must still pass the feature columns to `score_batch`.
    4. D.The model stores the feature lookup definitions, so `score_batch` retrieves feature values from the feature tables given just the lookup keys in the input.
    5. E.The model is linked by lineage to its source feature tables, so Catalog Explorer shows the feature dependencies of the registered model.
    Show answer & explanation

    Correct answers: D, E — The model stores the feature lookup definitions, so `score_batch` retrieves feature values from the feature tables given just the lookup keys in the input.; The model is linked by lineage to its source feature tables, so Catalog Explorer shows the feature dependencies of the registered model.

    • A. Incorrect: the model stores references to the feature lookups, not a copy of the training values. Scoring reads the current feature table contents, which can differ from those at training time.
    • B. Incorrect: logging a model publishes nothing to an online store. Low-latency serving needs a separately configured online table or online store, and the logged model does not create it.
    • C. Incorrect: `fe.log_model` accepts a flavor such as `mlflow.sklearn` and stores the feature metadata with the model in that flavor. Because `training_set` is passed, `score_batch` can look up the features itself.
    • D. Correct: the training set's feature spec is saved with the model, so batch scoring needs only the lookup keys in the input and retrieves the feature values from the feature tables itself.
    • E. Correct: models trained from Unity Catalog feature tables keep lineage to those tables, and Catalog Explorer displays the relationship for governance and impact analysis.

    1.9: Identify the best run using the MLflow Client API

    5.A training loop logs `val_loss` with `mlflow.log_metric("val_loss", loss, step=epoch)` for 50 epochs per run. An engineer ranks runs with `client.search_runs([exp_id], order_by=["metrics.val_loss ASC"])` and is surprised that a run whose best epoch had the lowest loss ranks low. What explains this?

    1. A.Ranking on `metrics.val_loss` compares each run's value at its highest step, so a run whose loss rose in later epochs sorts below runs that ended lower
    2. B.Ranking on `metrics.val_loss` compares each run's mean across its logged steps, so a run with a few noisy epochs sorts below runs with a steadier curve
    3. C.Ranking on `metrics.val_loss` compares each run's value at its first logged step, so runs rank on their starting loss rather than where training ended
    4. D.Ranking on `metrics.val_loss` falls back to `start_time DESC` for step-logged metrics, so the newest runs sort first and loss history has no effect on rank
    Show answer & explanation

    Correct answer: A — Ranking on `metrics.val_loss` compares each run's value at its highest step, so a run whose loss rose in later epochs sorts below runs that ended lower

    • A. Correct: the metric value used for ordering and shown in `run.data.metrics` is the latest one, at the largest step. A run whose loss climbed late is ranked on that final value, not its best epoch; `get_metric_history` returns every step.
    • B. Incorrect: MLflow does not average logged steps when sorting. It keeps one latest value per metric key on the run, so noisy epochs in the middle of training do not change the value that `order_by` uses.
    • C. Incorrect: the first step is not the ranking value. If it were, runs would be compared on near-identical initial losses, which does not fit a run being ranked low because of how its training progressed.
    • D. Incorrect: `order_by` works on metrics logged with `step`, and the sort is applied to the latest value. Results follow `start_time DESC` only when no `order_by` is given, which is not the case in this call.

    1.11: Identify information available in the MLflow UI

    6.A reviewer opens the run page of a completed scikit-learn training run in Databricks and wants to know what information is shown there. Which THREE items can they find on the run page? (Select all that apply.)(Select 3)

    1. A.The run ID, plus the parameter and metric values recorded while the training code executed.
    2. B.An Artifacts tab listing the files saved with the run, such as the logged model folder.
    3. C.Code snippets for generating predictions on Spark and pandas DataFrames from a logged model.
    4. D.Executor stack traces and task-level Spark metrics captured for the stages of the training job.
    5. E.A preview of the training DataFrame's rows, stored with the run by default for later inspection.
    Show answer & explanation

    Correct answers: A, B, C — The run ID, plus the parameter and metric values recorded while the training code executed.; An Artifacts tab listing the files saved with the run, such as the logged model folder.; Code snippets for generating predictions on Spark and pandas DataFrames from a logged model.

    • A. Correct: the run page displays the run ID together with the parameters and metrics logged during the run, which form the core record of what was executed.
    • B. Correct: files saved with the run, including the folder of a logged model, can be browsed in the Artifacts section of the run page.
    • C. Correct: for a logged model, the run page offers ready-made code snippets for making predictions on Spark and pandas DataFrames.
    • D. Incorrect: executor stack traces and task-level Spark metrics belong to the Spark UI and cluster logs. MLflow tracking does not record them on the run page, which shows the run's logged parameters, metrics and artifacts.
    • E. Incorrect: MLflow does not store training rows with a run by default. Dataset logging records only metadata such as the name, digest and schema, unless the data is explicitly saved as an artifact.

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

    7.A model was already trained and logged to MLflow run `abc123` under the artifact path `model`. The team now wants to add it to the Unity Catalog registry as `prod.ml_team.sales` using the MLflow client API, without retraining. Which approaches work? Select all that apply.(Select 2)

    1. A.Call `mlflow.register_model("runs:/abc123/model", "prod.ml_team.sales")` to add a version from the model logged under run abc123.
    2. B.Call `MlflowClient().create_model_version(name="prod.ml_team.sales", source="runs:/abc123/model", run_id="abc123")` to add a version.
    3. C.Call `MlflowClient().create_registered_model("prod.ml_team.sales")` to add the model logged under run abc123 as a version.
    4. D.Call `mlflow.register_model("abc123", "prod.ml_team.sales")` to add a version from the model logged under run abc123.
    5. E.Call `mlflow.sklearn.log_model(...)` with `registered_model_name` set, after refitting the estimator, to add a version.
    Show answer & explanation

    Correct answers: A, B — Call `mlflow.register_model("runs:/abc123/model", "prod.ml_team.sales")` to add a version from the model logged under run abc123.; Call `MlflowClient().create_model_version(name="prod.ml_team.sales", source="runs:/abc123/model", run_id="abc123")` to add a version.

    • A. Correct. `register_model` accepts a `runs:/<run_id>/<path>` URI that points at an already logged model, and registers that artifact as a new version of the named Unity Catalog model without retraining.
    • B. Correct. `create_model_version` is the client-level call that adds a version from a source URI and links it back to the originating run.
    • C. Incorrect. `create_registered_model` only creates the empty model container under that name. It adds no version and does not read the artifacts logged under the run, so the trained model is not registered.
    • D. Incorrect. `register_model` needs a full model URI such as `runs:/<run_id>/<path>` or `models:/<model_id>`. A bare run ID does not identify a model artifact and is not resolved, so the call fails.
    • E. Incorrect. Refitting the estimator and logging it again produces a new, retrained model rather than registering the one already logged under the run, which breaks the requirement not to retrain.

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

    8.A governance lead is reviewing why the ML platform team wants to move from the workspace model registry to the Unity Catalog model registry. Which three capabilities are benefits of registering in Unity Catalog?(Select 3)

    1. A.Privileges on models are granted with SQL `GRANT` at catalog, schema or model level, using the same statements as for tables and volumes.
    2. B.Each model version is linked to the MLflow run and notebook that produced it, giving reviewers a lineage trail back to the source.
    3. C.Registered models appear in Catalog Explorer alongside tables and volumes, under the same catalog.schema hierarchy as other assets.
    4. D.Versions move through Staging and Production stages, with reviewers approving transition requests before a stage changes.
    5. E.Access to models is managed through per-workspace ACLs that workspace admins edit on the model page, separate from account-level policy.
    6. F.Model artifacts are stored in the workspace DBFS root, with storage access granted through instance profiles on the clusters that read them.
    Show answer & explanation

    Correct answers: A, B, C — Privileges on models are granted with SQL `GRANT` at catalog, schema or model level, using the same statements as for tables and volumes.; Each model version is linked to the MLflow run and notebook that produced it, giving reviewers a lineage trail back to the source.; Registered models appear in Catalog Explorer alongside tables and volumes, under the same catalog.schema hierarchy as other assets.

    • A. Correct: registered models are Unity Catalog securables, so privileges are granted with SQL GRANT at catalog, schema or model level, as they are for tables and volumes.
    • B. Correct: each Unity Catalog model version is linked to the MLflow run and notebook that produced it, which gives reviewers a lineage trail back to the source.
    • C. Correct: Unity Catalog models are listed in Catalog Explorer within the catalog.schema hierarchy, next to tables, volumes and other governed assets.
    • D. Stages and approval-gated transition requests belong to the legacy workspace registry. Unity Catalog does not support stages and uses aliases to mark versions instead.
    • E. Per-workspace ACLs on the model page describe the legacy workspace registry. Unity Catalog governs models centrally through privileges and ownership defined in the metastore, shared across workspaces.
    • F. Unity Catalog stores model artifacts in governed managed storage at metastore, catalog or schema level and controls access with its own privileges. It does not use the workspace DBFS root with cluster instance profiles.

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

    9.According to Databricks MLOps guidance, which deployment pattern is recommended in most situations, and what is the unit of work that moves between environments?

    1. A.Deploy endpoints: the serving endpoint definition is promoted from dev to staging to production and points at the same model version
    2. B.Deploy models: the model trained in dev is promoted from dev to staging to production and is not retrained in the later environments
    3. C.Deploy data: the curated training tables are promoted from dev to staging to production and the model is rebuilt when the schema changes
    4. D.Deploy code: the project's training code is promoted from dev to staging to production and the model is trained in each environment
    Show answer & explanation

    Correct answer: D — Deploy code: the project's training code is promoted from dev to staging to production and the model is trained in each environment

    • A. Incorrect. A serving endpoint definition is a deployment detail, not one of the two promotion patterns Databricks describes. The choice is between deploying code and deploying models.
    • B. Incorrect. Deploying models is the alternative pattern, suited to training that is very expensive or hard to reproduce. Databricks recommends deploying code in most situations, so it is not the general answer.
    • C. Incorrect. Promoting data tables is not one of the two patterns Databricks describes; the choice is between deploying code and deploying models. Moving tables also leaves the training code without a reviewed path to production.
    • D. Correct. Databricks recommends deploying code in most situations. The training code is reviewed, tested and promoted through the environments, and the model is trained in each one.

    1.15: Set or remove a tag for a model

    10.Which statement correctly describes a tag on a registered model in the Unity Catalog model registry?

    1. A.A key/value string pair attached to a model as metadata, which can be edited or removed later without changing its artifacts
    2. B.A governed label that marks a model's lifecycle stage such as Staging or Production, which the registry uses to gate promotion
    3. C.A named pointer to a single model version, which can be used in a `models:/<name>@<tag>` URI to resolve and load the model
    4. D.A routing rule that a Model Serving endpoint evaluates, which decides what percentage of traffic each model version receives
    Show answer & explanation

    Correct answer: A — A key/value string pair attached to a model as metadata, which can be edited or removed later without changing its artifacts

    • A. Correct. Tags are free-form key/value string metadata on a registered model. Adding, changing or deleting one leaves the stored model files untouched and creates no new version.
    • B. Incorrect. Tags are free-form key/value pairs, not stage labels. Unity Catalog models have no Staging or Production stages, and a tag does not control promotion between environments.
    • C. Incorrect. That describes an alias, which points to one model version and is used in `models:/<name>@<alias>` URIs. A tag is only descriptive metadata and cannot be used to load a version.
    • D. Incorrect. Traffic percentages between versions are set in the serving endpoint's `traffic_config`. The endpoint does not read model tags when routing requests.

    1.18: Use Autologging to simplify the capture of performance metrics and hyperparameters

    11.A data scientist attaches an interactive Python notebook to a classic cluster running Databricks Runtime 14.3 LTS ML. The notebook calls `RandomForestClassifier(n_estimators=200).fit(X_train, y_train)` from scikit-learn and contains no MLflow code at all. What is recorded in the notebook's experiment?

    1. A.A run is logged in the notebook's experiment with the estimator's hyperparameters, training metrics and fitted model; Databricks Autologging covers scikit-learn on this cluster.
    2. B.No run is logged in the notebook's experiment until the code opens one with `mlflow.start_run()`; the scikit-learn fit alone does not create a tracking run on this cluster.
    3. C.A run is logged in the notebook's experiment with the fitted model artifact only; Databricks Autologging for scikit-learn skips hyperparameters and training metrics.
    4. D.A run is logged in the notebook's experiment only after `mlflow.sklearn.autolog()` is called; the ML runtime ships MLflow but leaves the scikit-learn flavor disabled.
    Show answer & explanation

    Correct answer: A — A run is logged in the notebook's experiment with the estimator's hyperparameters, training metrics and fitted model; Databricks Autologging covers scikit-learn on this cluster.

    • A. Correct: on a Databricks Runtime ML cluster, Databricks Autologging is enabled by default for interactive notebooks. Fitting the scikit-learn estimator therefore creates a run holding its parameters, training metrics and the model.
    • B. Incorrect: an explicit `mlflow.start_run()` is not needed here. The autologging integration opens and closes the run around the `fit` call, so the notebook's experiment gets a run even though the code has no MLflow calls.
    • C. Incorrect: Databricks Autologging for scikit-learn records the estimator's hyperparameters and training metrics in the same run as the model. It does not log the model artifact on its own.
    • D. Incorrect: Databricks Autologging is switched on by default for interactive notebooks on ML runtime clusters. The scikit-learn flavor is already active, so calling `mlflow.sklearn.autolog()` is not a precondition for the run.

    2: Data Processing

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

    12.Which statement correctly distinguishes `DataFrame.summary()` from `DataFrame.describe()` in PySpark?

    1. A.summary() takes statistic names such as "count" or "90%" and adds approximate percentiles, whereas describe() returns count, mean, stddev, min and max
    2. B.describe() adds approximate quartiles and accepts statistic names such as "median", whereas summary() returns only count, mean, stddev, min and max
    3. C.summary() accepts column names to limit which columns are profiled, whereas describe() takes no arguments and profiles each column of the DataFrame
    4. D.describe() computes exact quartiles by sorting each column in full, whereas summary() estimates percentiles from a sampled fraction of the rows
    Show answer & explanation

    Correct answer: A — summary() takes statistic names such as "count" or "90%" and adds approximate percentiles, whereas describe() returns count, mean, stddev, min and max

    • A. This is correct. summary() takes statistic names such as "count" or "90%" as arguments and, by default, adds approximate 25%, 50% and 75% percentiles. describe() produces only count, mean, stddev, min and max.
    • B. This is incorrect because the roles are swapped. describe() offers no quartiles, median or choice of statistics, while summary() is the method that adds approximate percentiles and takes statistic names.
    • C. This is incorrect. describe() is the method that accepts column names, and summary() takes statistic names instead. Each method takes only its own kind of argument.
    • D. This is incorrect. describe() computes no percentiles at all, and summary() derives its approximate percentiles from all rows rather than from a sampled fraction of them.

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

    13.A table of transaction amounts is heavily right-skewed, and a handful of values are about 1000 times the median. A data scientist compares a mean ± 3 × standard deviation filter with 1.5 × IQR fences. Which two statements justify preferring the IQR fences? (Select two.)(Select 2)

    1. A.Quartiles are positions in the sorted data, so a few huge amounts barely move Q1 and Q3, while those same rows pull up the mean and standard deviation and loosen the cutoff.
    2. B.With relativeError set to 0.01, `approxQuantile` returns the exact Q1 and Q3, while `F.stddev` over a distributed DataFrame yields only an approximate standard deviation.
    3. C.The 1.5 multiplier is tuned to each column's skew, so the fences calibrate to this table's tail, while the 3 in the standard-deviation rule is a fixed convention.
    4. D.Fences extend outward from Q1 and Q3, so the limits sit unevenly around the median and follow a long right tail, while a band centred on the mean stays symmetric.
    5. E.The IQR rule drops a stable share of rows, about 0.7%, on skewed and symmetric data alike, so the amount of data removed is predictable, unlike with a 3 × std cutoff.
    Show answer & explanation

    Correct answers: A, D — Quartiles are positions in the sorted data, so a few huge amounts barely move Q1 and Q3, while those same rows pull up the mean and standard deviation and loosen the cutoff.; Fences extend outward from Q1 and Q3, so the limits sit unevenly around the median and follow a long right tail, while a band centred on the mean stays symmetric.

    • A. Q1 and Q3 depend only on rank order, so a few extreme amounts hardly change them. The same rows inflate the mean and standard deviation, which stretches the thresholds so those rows can pass the z-score filter.
    • B. `approxQuantile` returns exact quantiles only when `relativeError` is 0; 0.01 still allows rank error. `F.stddev` is computed exactly, not approximately, so the contrast is false and gives no reason to prefer IQR.
    • C. The 1.5 multiplier is a fixed convention, just like the 3 in the standard-deviation rule. Neither is fitted to a column's skew, so this claim gives no reason to prefer the IQR fences.
    • D. Because the fences are built outward from Q1 and Q3, the lower and upper limits sit at different distances from the median and can follow an asymmetric, long-tailed distribution. A band centred on the mean is symmetric and cannot.
    • E. The roughly 0.7% figure holds only for normally distributed data. On a skewed column the share of rows outside the fences depends on the shape of the distribution, so the rule does not remove a stable share.

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

    14.A retail data scientist is preparing a Spark DataFrame to train a linear regression model with `pyspark.ml`. The `household_income` column is strongly right-skewed because a few very high earners sit far above everyone else, and about 8% of rows are null. The team wants a fill value that those extreme earners do not pull upward. Which `pyspark.ml.feature.Imputer` setting fits best?

    1. A.Set `strategy="mean"` so each null receives the average observed income, which leaves the column's overall mean unchanged after filling
    2. B.Set `strategy="median"` so each null receives the middle observed income, which a few very high incomes barely move in a skewed column
    3. C.Set `strategy="mode"` so each null receives the most frequent observed income, which is the typical level in a skewed column
    4. D.Set `strategy="mean"` after `StandardScaler` so each null receives the average scaled income, which cancels the pull of high incomes on the average
    Show answer & explanation

    Correct answer: B — Set `strategy="median"` so each null receives the middle observed income, which a few very high incomes barely move in a skewed column

    • A. The mean is computed from every observed income, so the few very high earners raise it and each null is filled with an inflated value. Keeping the column's overall mean unchanged only carries that upward pull into the imputed rows.
    • B. The median is the middle observed value, so a few very large incomes barely shift it. It is what `Imputer` computes with `strategy="median"`, and it gives a fill value that high earners do not drag upward.
    • C. On a continuous income column most values are distinct, so the most frequent one is close to arbitrary and does not indicate the center of the distribution. The mode suits categorical or discrete columns, not a skewed numeric one like this.
    • D. Standard scaling is a linear transformation, so the high incomes keep the same relative influence on the average and the fill value is still pulled upward. It rescales the column without removing the effect of the extreme earners.

    2.6: Impute missing values with the mode, mean, or median value

    15.A DataFrame has a string column `payment_method` (values such as `card`, `paypal`, `bank_transfer`) in which about 4% of rows are null. The team wants to replace nulls with the most frequent category, but `Imputer(inputCols=["payment_method"], strategy="mode")` raises an error. Which approach works?

    1. A.Run `df.groupBy("payment_method").count()`, pick the top non-null category, then apply `df.fillna({"payment_method": top_value})`
    2. B.Run `df.na.fill(0, subset=["payment_method"])`, then cast the filled column to string so the placeholder joins the existing categories
    3. C.Cast `payment_method` to double, run `Imputer(strategy="mode")` on it, then map the numeric result back to the category text
    4. D.Run `df.na.fill("unknown", subset=["payment_method"])`, then encode the column so the filled rows form their own category downstream
    Show answer & explanation

    Correct answer: A — Run `df.groupBy("payment_method").count()`, pick the top non-null category, then apply `df.fillna({"payment_method": top_value})`

    • A. Imputer only handles numeric columns, so the mode of a string column has to be found another way. Counting rows per category gives the most frequent non-null value, and the dictionary form of `fillna` writes it into just that column.
    • B. A numeric fill value is applied only to numeric columns, so the string nulls in `payment_method` stay null even with a `subset`. Casting afterwards cannot recover anything, and 0 would not be the most frequent category anyway.
    • C. Strings such as `card` or `paypal` cast to double become null, so the whole column is null. Imputer then has no observed values to compute a mode from, and there is nothing meaningful to map back to category text.
    • D. A string fill on the column does run, but it inserts a new `unknown` label. The nulls are then not replaced with the most frequent category, and the 4% of filled rows form a separate category that can skew later analysis.

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

    16.A scikit-learn `LogisticRegression` model will predict conversion from a customer table. Which two columns are appropriate candidates for one-hot encoding?(Select 2)

    1. A.`payment_type`, a string column with six unordered values such as card, paypal and voucher, each present in thousands of rows
    2. B.`customer_age`, an integer column spanning 18 to 90, with thousands of rows per age and an effect on conversion that changes smoothly
    3. C.`review_stars`, an integer rating from 1 to 5, with thousands of rows per level and conversion rising steadily with each star
    4. D.`store_country`, a string column with twelve unordered values such as Spain, Brazil and Japan, each backed by many customers in training
    5. E.`user_id`, a string identifier with about 400,000 distinct values, most of them seen in only one or two training rows
    Show answer & explanation

    Correct answers: A, D — `payment_type`, a string column with six unordered values such as card, paypal and voucher, each present in thousands of rows; `store_country`, a string column with twelve unordered values such as Spain, Brazil and Japan, each backed by many customers in training

    • A. Correct. Payment type is a nominal feature with few categories and thousands of rows per category. One-hot encoding gives each method its own coefficient in the logistic regression without implying an order.
    • B. Incorrect. Age is a numeric value with a smooth effect on conversion. Even with plenty of rows per age, 73 indicator columns would discard that numeric structure and make the coefficients noisy. A single numeric column keeps it.
    • C. Incorrect. The rating is ordinal and conversion rises steadily with each star. One numeric column captures that trend with one coefficient, whereas indicator columns would discard the ranking and need separate coefficients per level.
    • D. Correct. Store country is a nominal feature with a modest twelve values, and each value has strong support in training. One-hot encoding gives each country its own coefficient, which suits a linear model.
    • E. Incorrect. An identifier with about 400,000 values would create that many sparse columns, most backed by one or two rows. The model would memorise individual customers instead of learning patterns that generalise, and the matrix would be costly to fit.

    2.9: Identify scenarios where log scale transformation is appropriate

    17.An analyst works in a Databricks notebook and must visualize and model business data. Which scenarios are appropriate for a log scale transformation? (Select all that apply.)(Select 2)

    1. A.Plotting ad spend against revenue, where spend runs from $100 to $10M and most points bunch together near zero.
    2. B.Fitting a linear regression of monthly active users on a time index, where users grow about 8% each month for five years.
    3. C.Modeling exam scores with a linear regression, where scores are bell-shaped around a mean of 500 with a standard deviation of 100.
    4. D.Converting a product category column to numeric inputs for a model, where the column holds twelve distinct string values.
    5. E.Rescaling a percentage feature to a unit interval, where values are spread evenly between 0 and 100 across the dataset.
    Show answer & explanation

    Correct answers: A, B — Plotting ad spend against revenue, where spend runs from $100 to $10M and most points bunch together near zero.; Fitting a linear regression of monthly active users on a time index, where users grow about 8% each month for five years.

    • A. Correct. Spend that spans several orders of magnitude leaves most points bunched together on a linear axis. A log scale on spend spreads them out so the relationship becomes visible.
    • B. Correct. Growth of about 8% per month is exponential, so the log of monthly active users rises linearly with time. A linear regression on the time index then fits the logged values well.
    • C. Incorrect. Bell-shaped, symmetric scores have no long right tail or multiplicative spread, so a log transform would only distort them. They can be modeled directly or standardized.
    • D. Incorrect. String categories have no numeric magnitude to take a log of. They need an encoding such as `StringIndexer` followed by `OneHotEncoder` to become numeric inputs.
    • E. Incorrect. Evenly spread values between 0 and 100 are not skewed. Mapping them onto a unit interval is min-max scaling, which a log transform does not do.

    3: Model Development

    3.2: Identify methods to mitigate data imbalance in training data

    18.A team uses scikit-learn and imbalanced-learn to train a gradient boosting classifier on 1 million rows with 0.5% positives. They want SMOTE to help the model learn the minority class while still reporting trustworthy test metrics. Which workflow should they follow?

    1. A.Split into train and test sets, apply SMOTE to the training portion only, and compute metrics on the test portion at its original class ratio
    2. B.Apply SMOTE to the full dataset, split into train and test sets, and compute metrics on the test portion at the balanced class ratio
    3. C.Split into train and test sets, apply SMOTE to the test portion only, and compute metrics on the test portion with extra minority rows added
    4. D.Split into train and test sets, apply SMOTE to each portion separately, and compute metrics on the test portion at a 50/50 class ratio
    Show answer & explanation

    Correct answer: A — Split into train and test sets, apply SMOTE to the training portion only, and compute metrics on the test portion at its original class ratio

    • A. Correct. Synthetic minority rows are generated from training data after the split, so the model learns the minority class and no evaluation row influences training. The test portion keeps the real 0.5% positive rate, so recall and precision reflect production behavior.
    • B. Incorrect. Oversampling before the split creates synthetic points interpolated from rows that later land in the test portion, and near-duplicates end up on both sides. This leakage inflates the metrics, and the balanced test ratio also differs from production.
    • C. Incorrect. The training portion stays at 0.5% positives, so the model never benefits from SMOTE. Evaluating on synthetic rows measures performance on artificial points rather than real observations, so the resulting metrics cannot be trusted.
    • D. Incorrect. Training on a rebalanced portion is correct, but rebalancing the test portion to 50/50 means the metrics are computed on synthetic data with a class ratio the model will never see in production. Only the training portion should be resampled.

    3.3: Compare estimators and transformers

    19.A team is assembling a `pyspark.ml` `Pipeline` for a churn model. Several candidate stages are listed below. Which TWO of them are Estimators that must learn parameters from the training DataFrame through `fit()` before they can transform data?(Select 2)

    1. A.`StandardScaler`, which rescales each numeric column by its standard deviation
    2. B.`Imputer`, which fills missing values in numeric columns with a typical value
    3. C.`VectorAssembler`, which combines several numeric columns into one feature vector
    4. D.`Tokenizer`, which splits each text value in a column into lowercase words
    5. E.`Bucketizer`, which assigns each continuous value to a bin using a list of split points
    Show answer & explanation

    Correct answers: A, B — `StandardScaler`, which rescales each numeric column by its standard deviation; `Imputer`, which fills missing values in numeric columns with a typical value

    • A. Correct: `StandardScaler` is an Estimator. The scale factor depends on the data, so `fit()` must compute the column statistics from the training DataFrame and return a `StandardScalerModel`. That model's `transform()` then applies them.
    • B. Correct: `Imputer` is an Estimator. The replacement value (mean, median or mode) is derived from the data, so `fit()` computes it per column from the training DataFrame and returns an `ImputerModel`. That model fills the missing values.
    • C. Incorrect: `VectorAssembler` is a pure Transformer. Packing columns into one vector needs no statistics from the data, so there is nothing to fit and `transform()` can be called directly.
    • D. Incorrect: `Tokenizer` is a Transformer. It applies the same fixed splitting-and-lowercasing rule to each row, so no parameters are learned from the training DataFrame.
    • E. Incorrect: `Bucketizer` is a Transformer. The split points are a parameter set by the developer, so nothing is learned from the training data. `QuantileDiscretizer` is the Estimator that derives its splits from the data.

    3.4: Develop a training pipeline

    20.A team standardizes features with `StandardScaler` on the full dataset, then calls `randomSplit` and trains a classifier on the training part. Offline accuracy is far higher than accuracy observed on new production data. Which change to the training pipeline removes the leakage?

    1. A.Call randomSplit before scaling, then fit a Pipeline of StandardScaler and the classifier on the training part and run the fitted PipelineModel on the test part.
    2. B.Enable withMean=True on the StandardScaler that runs before randomSplit, then train the classifier on the scaled training part and evaluate on the scaled test part.
    3. C.Fit one StandardScaler on the training DataFrame and another on the test DataFrame, then train on the scaled training part and evaluate on the scaled test part.
    4. D.Cache the scaled DataFrame and call randomSplit with a fixed seed, then fit the classifier on the training part and evaluate on the test part of that split.
    Show answer & explanation

    Correct answer: A — Call randomSplit before scaling, then fit a Pipeline of StandardScaler and the classifier on the training part and run the fitted PipelineModel on the test part.

    • A. Correct. Splitting first and fitting the Pipeline on the training part means the scaler learns its mean and standard deviation from training rows only. The fitted PipelineModel then applies those stored values to held-out rows, as it will to production data.
    • B. Incorrect. withMean only decides whether values are centered. The scaler still runs before the split, so its statistics are computed from rows that later land in the test part. Held-out information still reaches training and the inflated accuracy remains.
    • C. Incorrect. A scaler fitted on the test DataFrame learns from held-out rows. It also standardizes test data with its own statistics, whereas production rows are scaled with values learned in training. The offline evaluation therefore does not match serving.
    • D. Incorrect. Caching and a fixed seed make the split repeatable, but the scaler statistics were still computed on the whole dataset before the split. Test rows have already influenced the training features, so the leakage is unchanged.

    3.5: Perform random or grid search or Bayesian search as a method for tuning hyperparameters

    21.A team calls `optuna.create_study(direction="minimize")` without passing a sampler to tune an XGBoost model, and each trial takes about 40 minutes. Once the study has finished its initial startup trials, how does the default sampler pick the hyperparameters for the next trial?

    1. A.It fits a density to the values of better-scoring trials and another to worse-scoring ones, then proposes values far likelier under the better group.
    2. B.It fits a Gaussian process to the scores of finished trials, then proposes values that maximise an acquisition function over the search space.
    3. C.It keeps a multivariate normal over the search space, updates its mean and covariance from the best trials, then samples values from it.
    4. D.It keeps drawing values uniformly from each range, while a pruner uses earlier scores only to stop weak trials, not to shape proposals.
    Show answer & explanation

    Correct answer: A — It fits a density to the values of better-scoring trials and another to worse-scoring ones, then proposes values far likelier under the better group.

    • A. Correct. With no sampler passed, Optuna uses `TPESampler` (Tree-structured Parzen Estimator). After its startup trials it splits finished trials into better and worse groups, estimates a density for each, and favours values that are much more likely under the better group.
    • B. Incorrect. Fitting a Gaussian process and maximising an acquisition function is how `GPSampler` works, and it is a separate sampler that must be passed explicitly. A plain `create_study` call uses the TPE sampler, which models densities of good and poor trials instead of a surrogate regression of the score.
    • C. Incorrect. Updating a multivariate normal's mean and covariance from the best trials is the behaviour of `CmaEsSampler`, which is opt-in. The default sampler keeps no covariance matrix and instead compares densities of good and poor trials.
    • D. Incorrect. Uniform independent draws describe `RandomSampler`, and the default pruner only decides whether to stop a running trial. The default sampler itself changes behaviour once its startup trials end and uses the scores of completed trials to shape the proposals.

    3.7: Describe the benefits and downsides of using cross-validation over a train-validation split

    22.A retail team forecasts daily demand and tunes a scikit-learn regressor with `GridSearchCV(cv=5)`, which uses unshuffled `KFold`, on three years of date-ordered rows. Cross-validated scores look far better than the model's live performance. What is the downside of plain k-fold here, and what is the fix?

    1. A.Some folds are scored by models trained on rows dated after them, so pass `cv=TimeSeriesSplit(n_splits=5)` to the search in place of the default splitter.
    2. B.Each validation slice is too short to represent three years of daily rows, so raise the search to `cv=20` and average the score over a larger number of folds.
    3. C.The final refit on the full training set inflates the reported score, so set `refit=False` and read the score from held-out folds that the model never saw.
    4. D.Contiguous folds each hold one season and bias the average, so pass `cv=KFold(n_splits=5, shuffle=True, random_state=0)` to mix seasons into each fold.
    Show answer & explanation

    Correct answer: A — Some folds are scored by models trained on rows dated after them, so pass `cv=TimeSeriesSplit(n_splits=5)` to the search in place of the default splitter.

    • A. Correct. Unshuffled k-fold on date-ordered rows puts later dates in the training folds for earlier validation folds, so the model is scored on periods it effectively saw ahead of time. `TimeSeriesSplit` always validates on rows after the training window, which matches how the forecaster is used live.
    • B. Incorrect. The inflated scores come from training on rows dated after the validation rows, not from validation slices being too short. With `cv=20` the splitter is still plain k-fold, so the leakage stays, and the search takes four times as many fits.
    • C. Incorrect. The refit happens after the search has finished and does not touch the cross-validated scores, which were already computed on held-out folds. Setting `refit=False` only leaves the search without a fitted best estimator and leaves the optimistic scores unchanged.
    • D. Incorrect. Shuffling makes the time leakage worse, because every fold then trains on rows from before and after its validation rows, and neighbouring days are highly correlated. Seasonal differences between contiguous folds are not what makes the scores optimistic, and shuffling does not address the real cause.

    3.8: Perform cross-validation as a part of model fitting

    23.A retailer forecasts weekly demand with scikit-learn's `GradientBoostingRegressor` on three years of weekly rows ordered by date. An engineer runs `GridSearchCV(model, grid, cv=KFold(n_splits=5, shuffle=True))` and reports an RMSE far better than the RMSE seen in production. What change best fixes the validation procedure?

    1. A.Set cv=KFold(n_splits=20, shuffle=True), giving each split a larger training set and a smaller validation fold of about eight weeks.
    2. B.Set cv=RepeatedKFold(n_splits=5, n_repeats=3), averaging the RMSE over several different random partitions of the three years of weekly rows.
    3. C.Set cv=TimeSeriesSplit(n_splits=5), fitting each split on an initial block of weeks and scoring it on the weeks that immediately follow.
    4. D.Set cv=StratifiedKFold(n_splits=5, shuffle=True), balancing the spread of weekly demand values across the five validation folds.
    Show answer & explanation

    Correct answer: C — Set cv=TimeSeriesSplit(n_splits=5), fitting each split on an initial block of weeks and scoring it on the weeks that immediately follow.

    • A. Incorrect: with 20 shuffled folds the validation weeks are still scattered among training weeks on both sides, so the model still learns from the future relative to the weeks it is scored on. Smaller folds change the fold size, not the leakage, and the RMSE stays too optimistic.
    • B. Incorrect: repeating KFold only reshuffles the same rows into new random partitions. Each repeat still places validation weeks next to training weeks from both before and after them, so the averaged RMSE is as optimistic as a single run, just less noisy.
    • C. Correct: TimeSeriesSplit keeps the date order and always validates on weeks later than the ones used for training in that split. This matches how the model forecasts in production, and the leakage from neighbouring weeks on both sides of a split disappears.
    • D. Incorrect: StratifiedKFold stratifies on discrete class labels and raises an error for the continuous demand target of a regressor. Even if it ran, shuffle=True would still break the date order and leave the leakage in place.

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

    24.A scikit-learn model routes support tickets into three classes, and the rare 'security' class makes up only 3% of rows. The team wants one F1 number computed per class and then averaged so that every class counts equally, regardless of how many tickets it has. Which `f1_score` call does this?

    1. A.f1_score(y_true, y_pred, average="macro")
    2. B.f1_score(y_true, y_pred, average="weighted")
    3. C.f1_score(y_true, y_pred, average="micro")
    4. D.f1_score(y_true, y_pred, average=None)
    Show answer & explanation

    Correct answer: A — f1_score(y_true, y_pred, average="macro")

    • A. Correct. With `average="macro"` scikit-learn computes F1 for each class and takes the unweighted mean, so the poor performance of the rare security class lowers the score as much as a large class would.
    • B. Incorrect. `average="weighted"` averages the per-class F1 scores weighted by class support, so the 3% security class contributes only a small share and its weak results are largely masked.
    • C. Incorrect. `average="micro"` pools true positives, false positives and false negatives across all classes before computing F1. For single-label multiclass data this equals accuracy and is dominated by the large classes.
    • D. Incorrect. With `average=None` scikit-learn returns an array holding one F1 score per class and performs no averaging. The result is three separate numbers rather than a single score in which each class counts equally.

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

    25.A model evaluated on a validation set has an RMSE of 48.2 and an MAE of 11.9. Which TWO statements are supported by these results?(Select 2)

    1. A.RMSE weights large residuals more heavily than MAE does, which indicates a few very large errors sit among mostly small ones
    2. B.Ranking validation rows by absolute residual is a sensible way to find the outliers or weak segments behind the gap between the two metrics
    3. C.MAE should be at least as large as RMSE on the same predictions, which suggests one metric was computed on different rows or in different units
    4. D.The wide gap shows the model's predictions are systematically biased in one direction, which RMSE exposes while MAE averages it away
    5. E.A validation RMSE this far above MAE shows the model has overfit the training data, which regularization or early stopping should address
    Show answer & explanation

    Correct answers: A, B — RMSE weights large residuals more heavily than MAE does, which indicates a few very large errors sit among mostly small ones; Ranking validation rows by absolute residual is a sensible way to find the outliers or weak segments behind the gap between the two metrics

    • A. Correct. RMSE squares each residual before averaging, so a few very large errors raise it far more than they raise MAE. An RMSE roughly four times the MAE means the error is concentrated in a small number of big misses, a heavy-tailed pattern.
    • B. Correct. The large RMSE-to-MAE gap suggests a few rows contribute most of the error. Sorting rows by absolute residual and examining the top ones is the practical way to see whether outliers or a particular data segment cause it.
    • C. Incorrect. For the same predictions RMSE is always greater than or equal to MAE, and the two are equal only when the absolute errors are all identical. An RMSE of 48.2 against an MAE of 11.9 is therefore a normal pairing and does not point to mismatched rows or units.
    • D. Incorrect. A consistent bias shifts the residuals by a similar amount, which raises MAE and RMSE together and leaves them close. A gap this wide comes from uneven error sizes, meaning a few large errors, and MAE does not average a bias away. The results also show nothing about direction.
    • E. Incorrect. RMSE exceeds MAE for nearly any model on any dataset, so the relationship says nothing about generalisation. Overfitting is diagnosed by comparing training and validation metrics, and only validation figures are given here.

    3.12: Choose the most appropriate metric for a given scenario objective

    26.A bank trains a scikit-learn gradient boosted classifier to flag fraudulent card transactions, and only 0.3% of transactions are fraud. Analysts can review a limited number of alerts per day, so the team wants one threshold-independent number that reflects how precise the flagged transactions stay as recall increases. Which metric best fits this objective when comparing candidate models?

    1. A.Overall accuracy of the predicted fraud labels at the default 0.5 cutoff, computed on the held-out test set
    2. B.Average precision (area under the precision-recall curve) of predicted fraud probabilities, computed on the held-out test set
    3. C.R² (variance explained) of the predicted fraud probabilities against the true 0/1 labels, computed on the held-out test set
    4. D.Mean absolute error between the predicted fraud labels and the true labels, computed on the held-out test set
    Show answer & explanation

    Correct answer: B — Average precision (area under the precision-recall curve) of predicted fraud probabilities, computed on the held-out test set

    • A. Accuracy at a single 0.5 cutoff is a one-point score, not a threshold-independent summary. With 0.3% fraud, a model that labels every transaction legitimate still scores about 99.7%, so the number says almost nothing about how precise the flagged transactions stay as recall grows.
    • B. Average precision summarizes precision across the whole range of recall levels from the ranking of predicted probabilities, so it needs no fixed threshold. It is driven by the rare fraud class, which is what the analysts' limited alert capacity depends on, so it suits comparing candidate models.
    • C. R² is a regression metric for how much variance in a continuous target is explained. Applied to 0/1 labels it scores how close the probabilities sit to 0 and 1, not how precise the flagged transactions are at a given recall, so it does not meet the objective.
    • D. Mean absolute error on hard class labels equals the misclassification rate, so it has the same weakness as accuracy at 0.3% fraud. It also depends on one cutoff and ignores how precision changes as recall increases across thresholds.

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

    27.A scikit-learn `RandomForestRegressor` is trained on `np.log(y_train)` where `y_train` holds house prices in dollars. The team now evaluates it on a test set with `mean_absolute_error` and wants the result to be an error in dollars. Which TWO or THREE steps apply? (Select all that apply.)(Select 3)

    1. A.Apply `np.exp` to the model's predictions on `X_test` before calling `mean_absolute_error`, turning log-prices into dollar-scale values.
    2. B.Pass `y_test` in its original dollar units as the true labels to `mean_absolute_error`, leaving `np.log` off the test targets.
    3. C.Expect the dollar MAE from back-transformed predictions to differ from `np.exp` of the log-scale MAE, since the exponential is nonlinear.
    4. D.Apply `np.log` to `X_test` before calling `predict`, matching the log transform that was applied to the training labels.
    5. E.Compute the MAE on the log scale first, then apply `np.exp` to that single value, giving the average absolute dollar error.
    6. F.Pass the raw `predict` output straight to `mean_absolute_error`, as the forest returns values in the target's original units.
    Show answer & explanation

    Correct answers: A, B, C — Apply `np.exp` to the model's predictions on `X_test` before calling `mean_absolute_error`, turning log-prices into dollar-scale values.; Pass `y_test` in its original dollar units as the true labels to `mean_absolute_error`, leaving `np.log` off the test targets.; Expect the dollar MAE from back-transformed predictions to differ from `np.exp` of the log-scale MAE, since the exponential is nonlinear.

    • A. Correct. The forest was fitted on log-prices, so its raw predictions are log-prices. Applying `np.exp` converts them to dollars before the metric is computed.
    • B. Correct. `mean_absolute_error` subtracts predictions from true values, so both must share one unit. With predictions back in dollars, the true labels must be the original dollar prices, not `np.log(y_test)`.
    • C. Correct. Exponentiation is nonlinear, so a symmetric error on the log scale becomes an asymmetric error in dollars. The dollar MAE must therefore be computed on back-transformed values and cannot be recovered from the log-scale MAE.
    • D. Incorrect. Only the target was log-transformed during training; the features were fitted as they are. Logging `X_test` would give the forest inputs on a scale it never saw and would not touch the scale of its outputs.
    • E. Incorrect. The exponential of an averaged log-scale error is a multiplicative factor (a typical ratio between predicted and actual price), not an amount in dollars. It does not equal the dollar MAE.
    • F. Incorrect. A random forest averages the training labels stored in its leaves, and those labels are log-prices. Its raw output is on the log scale, so comparing it with dollar values mixes units and needs `np.exp` first.

    3.17: Compare the computational requirements, training time, and data needs of deep learning versus traditional machine learning algorithms for a given problem

    28.A retail analytics team has a customer churn table with 40,000 rows and 35 numeric and categorical columns. They must deliver a first model this week on a single-node CPU cluster, and stakeholders want to see which columns drive predictions. Which modeling approach best fits these constraints?

    1. A.Fine-tune a pretrained transformer on rows serialized as text across several GPU nodes, then read attention weights to show which columns drive predictions
    2. B.Train a multi-layer feedforward network in PyTorch with embeddings for the categorical columns on a GPU cluster, then rank columns by first-layer weights
    3. C.Train a gradient-boosted tree ensemble with XGBoost on the CPU cluster, then rank columns by the fitted model's built-in feature importance scores
    4. D.Train a convolutional network on the CPU cluster after arranging the columns into a two-dimensional grid, then rank columns with saliency maps on the grid
    Show answer & explanation

    Correct answer: C — Train a gradient-boosted tree ensemble with XGBoost on the CPU cluster, then rank columns by the fitted model's built-in feature importance scores

    • A. Incorrect. The team has only a single-node CPU cluster, so multi-node GPU fine-tuning is unavailable and a large pretrained transformer is far too heavy for a first model this week. Attention weights over serialized text tokens are also not a dependable measure of which columns drive predictions.
    • B. Incorrect. The environment is a single-node CPU cluster, so a GPU cluster is not available. A feedforward network on 40,000 rows also needs tuning time and can overfit. First-layer weights do not reliably rank column influence once later layers mix the inputs, so the stakeholder need is not met.
    • C. Correct. Gradient-boosted trees perform strongly on structured data of this size, train quickly on CPU, and handle mixed numeric and categorical columns with little preparation. Their built-in feature importance scores answer the stakeholder question about which columns drive predictions.
    • D. Incorrect. Convolutions rely on spatial locality, and neighbouring cells in an arbitrary column grid have no real relationship, so the network learns little from the layout. Training convolutional layers on CPU is also slow, and saliency maps on an artificial grid make a weak explanation of column influence.

    3.15: Use Optuna to perform distributed hyperparameter tuning

    29.A team plans to run distributed Optuna tuning with the default TPE sampler. An engineer proposes that every Spark executor create its own independent study with default in-memory storage and that the results be compared afterwards. A colleague insists on `MlflowStorage` instead. What is the main reason the shared storage matters for this workload?

    1. A.Shared storage keeps finished trials in one place that the workers can query, so TPE builds each new suggestion from the combined history of the run.
    2. B.Shared storage assigns each worker its own slice of the search space, so parallel trials do not repeat the same region and TPE explores more widely.
    3. C.Shared storage lets the tracking server pick the best trial and promote its model to the Unity Catalog registry, so the winning model needs no manual step.
    4. D.Shared storage lets later trials reuse the fitted model from earlier ones as a warm start, so TPE reaches a good configuration with less training time.
    Show answer & explanation

    Correct answer: A — Shared storage keeps finished trials in one place that the workers can query, so TPE builds each new suggestion from the combined history of the run.

    • A. Correct. TPE is a sequential model-based sampler that proposes new parameters from the trials it has already seen. With a common `MlflowStorage` backend, every executor reads and writes the same trial history. With separate in-memory studies, each sampler sees only its own few results, so the parallel search degrades towards independent, mostly random searches.
    • B. Incorrect. Optuna storage does not divide the search space among workers. Each worker samples from the same space defined in the objective function. The storage only shares trial history, which TPE uses to focus on promising regions. It does not partition the space or guarantee that trials avoid overlapping.
    • C. Incorrect. `MlflowStorage` persists Optuna study and trial data in MLflow. It does not choose a best model or register it in Unity Catalog, which needs an explicit registration step in the workflow. Model promotion is not the reason a distributed TPE search needs shared storage.
    • D. Incorrect. Optuna storage records trial parameters, values and states. It does not pass fitted models between trials or warm-start training. Each trial trains from scratch inside the objective function. The storage helps the sampler choose better parameters, not make individual trials cheaper to train.

    3.18: Use SHAP values to explain individual model predictions and identify the most influential features for stakeholder communication

    30.On Databricks, a fraud team has a scikit-learn gradient-boosted tree model trained on 50 million transactions. Analysts need explanations for 1,000 flagged transactions this morning. Which approach explains them without a heavy compute cost?

    1. A.Collect the 1,000 flagged rows to the driver as pandas, run shap.TreeExplainer on them, then plot a waterfall of feature contributions for each row.
    2. B.Collect the full 50 million-row table to the driver as pandas, run shap.TreeExplainer on it, then keep the contribution values for the flagged rows.
    3. C.Collect the 1,000 flagged rows to the driver as pandas, run permutation_importance on them, then give analysts that ranking as the reason for each row.
    4. D.Collect the 1,000 flagged rows to the driver as pandas, call predict_proba on them, then subtract the mean training score to get each feature's contribution.
    Show answer & explanation

    Correct answer: A — Collect the 1,000 flagged rows to the driver as pandas, run shap.TreeExplainer on them, then plot a waterfall of feature contributions for each row.

    • A. Correct. TreeExplainer uses Tree SHAP, which exploits the structure of tree ensembles to give per-feature contributions for individual rows quickly. Running it only on the 1,000 rows analysts need keeps the data small enough for the driver.
    • B. Incorrect. TreeExplainer is the right tool, but converting 50 million rows to pandas on the driver risks exhausting its memory, and computing SHAP values for all of them is heavy compute spent on rows nobody asked about.
    • C. Incorrect. Permutation importance measures how much shuffling a feature degrades the model's score across a dataset. It yields one global ranking for the whole set, not the contributions behind each individual transaction.
    • D. Incorrect. predict_proba returns one score per row, and subtracting the training mean leaves a single number for the transaction. That gap cannot be split into per-feature contributions without a Shapley computation such as Tree SHAP.

    3.16: Assess whether a machine learning approach is appropriate for a business problem based on data availability, baseline performance, and ROI considerations

    31.In deciding whether a machine learning project is justified, what is the role of a baseline?

    1. A.A frozen copy of the current production model's weights, kept as the version to restore when a newer release performs worse in live traffic.
    2. B.A held-out test set kept untouched until the final evaluation, used to report the model's metric on examples it never saw during training.
    3. C.The first hyperparameter configuration tried during tuning, kept as the reference run that later trials are compared against and refined from.
    4. D.A trivial predictor or the current rule-based process, scored on the same data, kept as the bar the model must exceed by a margin worth its cost.
    Show answer & explanation

    Correct answer: D — A trivial predictor or the current rule-based process, scored on the same data, kept as the bar the model must exceed by a margin worth its cost.

    • A. Incorrect. A saved copy of the production weights is a rollback safeguard for deployments. It says nothing about whether the expected gain from ML outweighs its cost, so it cannot support a go/no-go decision on the project.
    • B. Incorrect. A held-out test set is a data split that keeps the final metric free of leakage. It is not a simple solution to outperform, so it gives no benchmark for judging whether ML adds enough value.
    • C. Incorrect. The first tuning configuration is just one trial in a hyperparameter search, so comparing against it shows tuning progress only. It does not show whether a trivial or existing approach would already be good enough.
    • D. Correct. A baseline is a trivial predictor or the existing process, scored on the same data. Its metric is the minimum bar the model must beat by enough to be worth the build and run cost.

    3.19: Use feature importance scores to perform feature selection and reduce model complexity

    32.A team fits a gradient boosted tree model on 80 features. Two near-duplicate columns, `trip_distance_km` and `trip_distance_miles`, each receive importance just below the selection cutoff, although the model clearly relies on the distance signal. Applying the cutoff would drop both. What should the team do?

    1. A.Drop one of the two distance columns, refit the model, and recompute importances before applying the cutoff to the remaining features.
    2. B.Lower the cutoff to zero, refit the model, and rely on built-in regularization to handle the duplicated distance signal.
    3. C.Raise `max_depth`, refit the model, and recompute importances with deeper trees before applying the cutoff to the other features.
    4. D.Standardize both distance columns, refit the model, and recompute importances before applying the cutoff to the remaining features.
    Show answer & explanation

    Correct answer: A — Drop one of the two distance columns, refit the model, and recompute importances before applying the cutoff to the remaining features.

    • A. Correct: the two near-duplicate columns split credit for one signal, so each scores below the cutoff. After one copy is removed and the model is refit, the remaining column carries the full importance and can be judged against the cutoff.
    • B. Incorrect: a zero cutoff abandons the selection step altogether and keeps all 80 features, redundant distance copy included. Regularization shrinks coefficients or limits tree growth, but it does not remove a duplicated column, and it is not a feature-selection mechanism.
    • C. Incorrect: deeper trees do not stop importance from being shared between two interchangeable columns. Splits still alternate between the copies, so each score stays diluted and both can still fall below the cutoff, and the model also gets more complex.
    • D. Incorrect: standardizing is a linear, order-preserving rescale, and tree splits are unaffected by that. The two columns remain perfectly correlated, so splits and credit are divided between them as before and both can still land under the cutoff.

    4: Model Deployment and Monitoring

    4.1: Identify the differences and advantages of model serving approaches: batch, realtime, and streaming

    33.A data scientist is documenting the differences between inference modes on Databricks for new teammates. Which statement correctly contrasts streaming inference with batch inference?

    1. A.Streaming inference picks up newly arrived records and records its progress in checkpoints, while batch inference scores a fixed set of records each time a job is triggered
    2. B.Streaming inference returns a prediction for each HTTP request from a Model Serving endpoint, while batch inference scores arriving records continuously and keeps state between runs
    3. C.Streaming inference loads the model onto the cluster through `spark_udf` in each micro-batch, while batch inference needs a Model Serving endpoint to host the model for scoring
    4. D.Streaming inference runs once a day on a fixed schedule over that day's files, while batch inference reprocesses the full dataset whenever new files land in storage
    Show answer & explanation

    Correct answer: A — Streaming inference picks up newly arrived records and records its progress in checkpoints, while batch inference scores a fixed set of records each time a job is triggered

    • A. Correct. Streaming inference works on an unbounded flow of data, handling only newly arrived records and tracking progress through checkpoints. Batch inference runs over a defined set of records every time the job is triggered.
    • B. Incorrect. Answering individual HTTP requests from a Model Serving endpoint is real-time serving, not streaming inference. Batch jobs do not score records as they arrive or hold state between runs; each run covers a bounded dataset.
    • C. Incorrect. Batch inference does not need a serving endpoint. The model can be loaded onto the job's cluster with `spark_udf` or a pandas UDF and applied to a bounded table. Hosting on an endpoint is the real-time serving pattern.
    • D. Incorrect. Streaming is defined by continuous, incremental handling of new data, not by a once-a-day schedule. Batch inference runs when it is triggered over a bounded dataset; it does not react to new files on its own.

    4.4: Identify how streaming inference is performed with Lakeflow pipelines

    34.An ML engineer is writing Python for a Lakeflow Spark Declarative Pipelines streaming table that applies a registered MLflow model through `mlflow.pyfunc.spark_udf`. Which TWO statements about building this table are correct?(Select 2)

    1. A.Create the scoring UDF from the model's Unity Catalog URI, such as `models:/main.ml.churn_model@champion`, and apply it as a column in the table query.
    2. B.Install `mlflow` in the pipeline's environment and import it in the source file that defines the table, before calling the UDF builder in the query.
    3. C.Load the model with `mlflow.pyfunc.load_model` and call `predict` on the streaming DataFrame inside the table query, then return the result as the table.
    4. D.Set the refresh cadence with `trigger(processingTime='5 seconds')` on the streaming query in the source code, so the pipeline honours that interval.
    5. E.Convert the streaming DataFrame with `toPandas()` inside the table function, score it with the loaded model, and return the output as a DataFrame.
    Show answer & explanation

    Correct answers: A, B — Create the scoring UDF from the model's Unity Catalog URI, such as `models:/main.ml.churn_model@champion`, and apply it as a column in the table query.; Install `mlflow` in the pipeline's environment and import it in the source file that defines the table, before calling the UDF builder in the query.

    • A. Correct. The Spark UDF is built from a model URI, and a Unity Catalog alias such as `@champion` resolves through a `models:/` URI to a registered model version. The UDF is then applied as a column expression in the table query.
    • B. Correct. The pipeline runtime does not guarantee that MLflow is preinstalled, so the library has to be installed in the pipeline's environment and imported in the source file before the UDF is created.
    • C. Incorrect. `predict` on a loaded pyfunc model takes in-memory inputs such as a pandas DataFrame or a NumPy array, not a Spark streaming DataFrame. To score streaming rows the model has to be wrapped as a Spark UDF.
    • D. Incorrect. Lakeflow Spark Declarative Pipelines starts and manages the streaming query itself, so a `trigger` call in the table code does not set the cadence. Timing is controlled through pipeline-level configuration, such as triggered versus continuous update mode.
    • E. Incorrect. `toPandas()` is an action that Spark does not allow on a streaming DataFrame, so the table definition would fail. Even on batch data it would pull all rows onto the driver and give up distributed scoring.

    4.7: Detect various drift types using Databricks Data profiling

    35.A data scientist is creating a data profile on an inference table that stores request timestamps, model version, feature values, predictions and, for some rows, a ground-truth label that arrives weeks later. Which two statements describe how the profile must be configured? (Choose 2)(Select 2)

    1. A.Set the timestamp column in the profile config, which splits the logged requests into windows sized by the chosen granularities.
    2. B.Set the label column in the profile config, which holds off metric computation until ground truth has arrived for the logged rows.
    3. C.Set the model ID column in the profile config, which groups the metrics by model so versions can be compared in one table.
    4. D.Set a baseline table in the profile config, which the profile needs in place before it computes metrics on the logged requests.
    5. E.Point the profile config at an online table copy of the inference table, which lets the profile read the logged requests.
    Show answer & explanation

    Correct answers: A, C — Set the timestamp column in the profile config, which splits the logged requests into windows sized by the chosen granularities.; Set the model ID column in the profile config, which groups the metrics by model so versions can be compared in one table.

    • A. Correct. An inference profile needs a timestamp column; the logged requests are bucketed into windows according to the configured granularities, and profile and drift metrics are produced per window.
    • B. Incorrect. The label column is optional, and the profile does not wait for ground truth. With labels arriving weeks later for only some rows, data quality and drift metrics are computed right away, and model quality metrics appear as labels become available.
    • C. Correct. An inference profile takes a model identifier column, and metrics are computed separately for each model ID, so different model versions can be compared within the same table.
    • D. Incorrect. A baseline table is optional. Without one, the profile is still created and computes metrics, including drift between consecutive windows; only drift against a baseline is unavailable.
    • E. Incorrect. Data profiling reads Delta tables in Unity Catalog, including inference tables, directly. No online table or online store copy is needed.

    Want the full experience?

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