Exams / DBX-MLA / D1 Model Development
D1.1
Model Development
- Exam domain: Model Development
You are reading a free preview. The rest of the DBX-MLA course unlocks with an Exam pass or All access.See plans
AutoML on Databricks
| Item | Fact |
|---|---|
| Primary metric | "The evaluation metric is the primary metric used to score the runs." Default is f1 for classification and r2 for regression. |
| Best model | "When a run completes, the top row shows the best model based on the primary metric." |
| Source code | Select View notebook for best model to review and edit the notebook that created the best model. Each trial's notebook is also in the run's Artifacts. |
| Early stopping | Classification and regression experiments stop when the validation metric no longer improves. |
Metric families: F1, precision, recall, accuracy are classification metrics. R2, MAE, MSE, RMSE are regression metrics.
Evaluation metrics
| Need | Metric |
|---|---|
| Maximize detected positives (few false negatives) | Recall = TP / (TP + FN) |
| Error magnitude of a regression | RMSE (lower is better) |
| Goodness of fit of a regression | R2 |
| Multiclass accuracy in Spark ML | MulticlassClassificationEvaluator(metricName="accuracy").evaluate(df) |
- RMSE of models trained on
log(price)must be computed after exponentiating predictions, so both models are compared on the original price scale. - Overall cross-validation error is the mean of the fold errors: (10 + 12 + 17) / 3 = 13.
- Overfitting (high variance): high training accuracy, low test accuracy.
Splitting and cross-validation
| Approach | Cost | Estimate quality |
|---|---|---|
| Train-validation split | 1 fit per combination | Depends on one split |
| k-fold CV | k fits per combination | More reliable |
- Number of models = (product of grid sizes) x k. Example: 4 x 3 x 2 = 24 combinations x 5 folds = 120 fits.
- Time series: keep chronological order and use rolling (forward-chaining) cross-validation; never random splits.
- Spark:
DataFrame.randomSplit([0.8, 0.2], seed)splits randomly into train/test DataFrames.
Hyperparameter tuning with Hyperopt
fmin()runs Hyperopt;algo=tpe.suggest(Tree of Parzen Estimators) uses past results;max_evalsis the number of settings tried.SparkTrialsdistributes trials to Spark workers; use it for single-machine libraries such as scikit-learn. For MLlib or Horovod models, do not use SparkTrials (use defaultTrials).- "Because Hyperopt proposes new trials based on past results, there is a trade-off between parallelism and adaptivity."
- For a fixed
max_evals, more parallelism = faster; lower parallelism may give better results. - More evaluations (
max_evals) raise the chance of a better model.
Spark ML building blocks
| Concept | Meaning |
|---|---|
| Transformer | transform(): one DataFrame into another (e.g. VectorAssembler, fitted models) |
| Estimator | fit(): learns from a DataFrame and returns a Model (e.g. StandardScaler, LogisticRegression, LinearRegression) |
| Pipeline | Chains Transformers and Estimators |
LinearRegressiontakes one vector column asfeaturesCol; build it withVectorAssemblerand setlabelCol.- Linear regression: solved directly when practical, otherwise by iterative optimization (L-BFGS) for many features.
- Spark ML trees bin continuous features (
maxBins), so results can differ from sklearn. - Random forest = bagging; gradient boosted trees = boosting. Combining several models = ensemble learning (stacking uses a meta-model).
Compute and Git
- Spark ML after Spark SQL ingestion: all-purpose (standard) cluster. SQL warehouses run SQL and Markdown cells only.
- Single node compute is for small data or non-distributed workloads.
- Git folders: enter a message and use Commit & Push in the Git dialog.
- MLflow run: "Start Time" column in the experiment page gives the run date and time.
Exam traps
- F1 is NOT a regression metric.
- Grid + CV: fits = combinations x folds (not just combinations).
- Log-label models: exponentiate predictions before RMSE; lower RMSE is better.
- SparkTrials is for single-node training libraries, not for distributed MLlib.
- Do not confuse Transformer (transform) and Estimator (fit).
- Time series: random splits leak the future.
Docs
- https://docs.databricks.com/aws/en/machine-learning/automl/classification
- https://docs.databricks.com/aws/en/machine-learning/automl/automl-api-reference
- https://docs.databricks.com/aws/en/machine-learning/automl-hyperparam-tuning/hyperopt-concepts
- https://docs.databricks.com/aws/en/machine-learning/automl-hyperparam-tuning/hyperopt-best-practices
- https://docs.databricks.com/aws/en/mlflow/runs
- https://docs.databricks.com/aws/en/notebooks/notebook-compute
- https://docs.databricks.com/aws/en/repos/git-operations-with-repos
- https://docs.databricks.com/aws/en/compute/configure
- https://docs.aws.amazon.com/machine-learning/latest/dg/cross-validation.html
- https://docs.aws.amazon.com/sagemaker/latest/dg/autopilot-metrics-validation.html