Introduction To Machine Learning
What is the machine learning lifecycle on Databricks?
- Machine learning (ML) trains models on examples to make predictions or discover patterns in new data. The lifecycle is iterative, not a one-time sequence.
- Data preparation: ingest, clean, join and validate source data; prevent data leakage and establish access controls.
- Exploratory data analysis (EDA): inspect distributions, missing values, outliers, correlations and potential biases using SQL, notebooks and visualizations.
- Feature engineering: convert raw columns into useful model inputs (features), such as customer tenure or 30-day purchase totals.
- Training: choose an algorithm, fit it on training data and log experiments, parameters and metrics with MLflow.
- Validation: evaluate on held-out data using task-appropriate metrics (e.g., precision/recall for classification, MAE/RMSE for regression); compare with a baseline.
- Deployment: package and register a selected model in Unity Catalog, then run batch predictions via scheduled jobs or real-time predictions through Model Serving.
- Monitoring: track input-data drift, prediction distributions, operational performance and model quality; retrain or roll back when necessary.
- Recommended practice: automate reproducible pipelines and deployments as code rather than relying on manually repeated notebook steps.
Who is responsible for each part of an ML project?
- Business stakeholders: define the problem, target outcome, success criteria and constraints; review whether predictions are useful.
- Data governance officers: set access, privacy, retention and compliance policies and govern data/model assets.
- Data engineers: ingest and transform reliable data; build production data pipelines and feature sources.
- Data scientists: explore data, engineer features, train and validate models, and explain findings.
- ML engineers: package, deploy, automate, scale, monitor and maintain models and inference systems.
- Responsibilities overlap: production ML needs collaboration throughout the lifecycle, not a one-way handoff.
How does the Databricks Data Intelligence Platform support ML?
- Delta Lake: reliable lakehouse tables with ACID transactions, schema enforcement/evolution, version history and batch/streaming support. Delta tables are useful for repeatable training datasets.
- Unity Catalog: centralized discovery, permissions, lineage and governance for tables, volumes, functions, features and registered models. Use fully qualified names such as
catalog.schema.table. - Notebooks and compute: use Python, SQL and supported ML libraries for EDA, feature creation and model development. Databricks Runtime for Machine Learning bundles common frameworks where supported; serverless environments have their own dependency-management approach.
- MLflow: track experiment runs, parameters, metrics, artifacts and model versions; register governed models in Unity Catalog.
- Lakeflow Jobs: schedule and orchestrate data preparation, training, validation and batch inference tasks.
- Mosaic AI Model Serving: deploy supported models behind managed real-time endpoints with scalable inference and operational controls.
- Intelligence Engine and automation: Databricks offers automatic performance optimization and assistance across parts of the platform, but do not assume every optimization, data-quality check or remediation is enabled by default.
What are features, and why use the Databricks Feature Store?
- A feature is a model input derived from data, such as
days_since_last_order,average_basket_valueorcustomer_region. - Feature engineering includes handling nulls, encoding categories, aggregating historical events, normalizing values where appropriate and avoiding future information in training data.
- The Feature Store / Feature Engineering in Unity Catalog makes features discoverable and reusable across projects, with governance and lineage back to source tables.
- A feature table is generally a Unity Catalog Delta table with a primary key identifying each feature record; time-series features may also use a timestamp key for point-in-time lookups.
- Training-serving skew happens when features are calculated differently during training and inference. Reusable feature definitions and logged feature lookups help reduce this risk.
- MLflow can package feature lookup specifications with compatible models so the same feature sources are used at inference. This is not a blanket guarantee: confirm online feature availability, point-in-time correctness and serving compatibility.
- Distinguish offline features (historical training and batch use) from online features (low-latency serving); not every feature table is automatically available for online lookup.
How do you start a basic ML workflow in Databricks?
- 1. Find data: open Catalog Explorer, locate a governed table, inspect its schema and verify permissions.
- 2. Explore: create a notebook and use SQL to check volume, nulls and distributions:
SELECT COUNT(*) AS row_count FROM catalog.schema.training_data;
SELECT target, COUNT(*) AS examples
FROM catalog.schema.training_data
GROUP BY target;- Replace
catalog.schema.training_dataandtargetwith your real table and label column. Check whether the target is missing or imbalanced. - 3. Prepare: create reproducible transformations, split training/validation/test data (chronologically for time-dependent predictions), and fit preprocessing only on training data.
- 4. Train and log: use MLflow to record experiments. Minimal Python example for an already prepared
X_train,y_train,X_validandy_valid:
import mlflow
import mlflow.sklearn
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
with mlflow.start_run():
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
predictions = model.predict(X_valid)
mlflow.log_metric("validation_accuracy", accuracy_score(y_valid, predictions))
mlflow.sklearn.log_model(model, name="model")- 5. Validate: inspect the run in Experiments, compare against baselines and check errors across important data segments.
- 6. Deploy: register the selected model in Unity Catalog, then use a scheduled job for batch inference or Model Serving for real-time predictions, subject to workspace capabilities and quotas.
- 7. Monitor: collect predictions, inputs and (when available) actual outcomes; compare performance and drift with a reference period.
How does model monitoring work, and what should you measure?
- Lakehouse Monitoring (also described in newer documentation as data profiling) can profile Unity Catalog tables, calculate statistics and drift metrics, and produce monitoring tables and dashboard visualizations, subject to workspace support.
- Data drift: shifts in input distributions, missingness or categories compared with a baseline; drift does not automatically mean predictions are wrong.
- Prediction drift: changes in the distribution of model outputs; investigate possible changes in inputs or behavior.
- Model quality: compare predictions with observed labels when ground truth becomes available, using accuracy, F1, precision/recall, RMSE or business-specific measures.
- Operational health: measure inference latency, errors, throughput, endpoint availability and cost.
- Custom metrics: where supported, use SQL expressions to monitor business-specific conditions and data-quality checks.
- Inference tables: capture supported serving request/response data for analysis; configure carefully to protect sensitive information and control storage costs.
- Monitoring is useful only when paired with ownership, alert thresholds, investigation and a retraining or rollback process.
What should you know about Databricks Free Edition?
- Free Edition has limits on compute, serving endpoints and other resources; features can differ from paid workspaces.
- Before deploying a model, inspect existing Serving endpoints and reuse course resources where appropriate. Avoid creating duplicate endpoints.
- If an endpoint fails to provision, check quotas, permissions, supported model types and endpoint logs. Scale-to-zero may be relevant for supported deployments but can cause a cold-start delay.
- If a course references a feature unavailable in Free Edition, focus on the underlying concept and follow the current workspace-specific documentation.