Sub topic 17
Where AI and Machine Learning Fit
This chapter assumes you know the lakehouse idea, the workspace, compute, notebooks, Delta tables, and Unity Catalog from earlier chapters. It is a map of where AI and machine learning (ML) work happens on the platform. It does not teach modeling.
The same platform, one more workload
Databricks does not run AI on a separate system. ML work uses the same pieces you have already met:
- Data is read from Delta tables addressed by their Unity Catalog three-level name.
- Compute is a cluster or serverless compute attached to a notebook.
- Code lives in notebooks and Git folders.
- Governance is Unity Catalog permissions, applied to data and also to models.
The benefit is that training data, features, and models stay under one set of access rules and one audit trail. You avoid copying data into a separate ML tool.
The ML lifecycle on the platform
The table maps each stage of an ML project to the platform capability that handles it.
| Stage | What you do | Platform capability |
|---|---|---|
| Prepare data | Clean and join tables | Spark and SQL on Delta tables |
| Train | Fit a model, compare runs | Notebooks, MLflow experiment tracking |
| Register | Version and store a model | Models in Unity Catalog |
| Serve | Expose a model as an endpoint | Model Serving |
| Monitor and schedule | Retrain or score on a schedule | Jobs |
MLflow is an open source tool for tracking experiments and packaging models. Databricks integrates it, so runs logged from a notebook appear in the workspace without extra setup.
A small example
This notebook cell trains a model on the table from earlier chapters and logs it. It assumes a compute resource with an ML-capable runtime, where mlflow and scikit-learn are preinstalled.
import mlflow
from sklearn.linear_model import LinearRegression
pdf = spark.table("main.tutorial.orders").toPandas()
X = pdf[["customer_id"]]
y = pdf["amount"]
with mlflow.start_run():
model = LinearRegression().fit(X, y)
mlflow.log_metric("r2", model.score(X, y))
mlflow.sklearn.log_model(model, "model")The model is meaningless, since customer ID does not predict amount. The point is the workflow: read a governed table, train, and record the run.
Calling toPandas() pulls all rows onto one machine. For large tables, use Spark-based training libraries instead.
Generative AI
The platform also supports generative AI work: calling hosted large language models, building retrieval and agent applications, and serving your own models. These features share the same governance and billing as the rest of the workspace. Available features vary by cloud and region, so check the current documentation.
Common errors
- Training on an all-purpose cluster without an ML runtime, then finding libraries missing.
- Forgetting that users need privileges on the catalog and schema, not only on the model, to use registered models.
- Collecting large tables to the driver with
toPandas().
Exercise
Why does registering a model in Unity Catalog help compared with saving it to a file share?
Show answer
The model gets the same permissions, versioning, and audit trail as your tables, so access to data and models is controlled in one place.
Exercise
Which platform component would you use to retrain a model every night?
Show answer
Jobs. You schedule the training notebook as a job on job compute.