Uploaded September 2026 | Updated September 2026, 1 week ago
Description:
**Learn how to predict customer spending using Linear Regression with Db2's built-in machine learning stored procedures. No external tools required.**
In this demo, I walk through training a regression model entirely inside the database using Db2's ML stored procedures. Starting with 48,202 customer records, I show the full pipeline: data preprocessing, model training, prediction generation, and evaluation.
**What you'll learn:**
- How to split datasets into training and test partitions (80/20 split)
- Data cleaning with Db2 stored procedures (handling missing values like customer age)
- Training a linear regression model directly in SQL
- Generating real-time predictions by changing customer attributes
- Evaluating model quality with MAE and MAPE
**What's covered:**
The problem of predicting customer spend. The dataset and what we know about each customer. Training a linear regression model with Db2 stored procedures. Data preprocessing steps: splitting, cleaning, imputation. Running the training pipeline. Making predictions with different customer attributes. The prediction SQL behind the scenes. Model evaluation metrics (MAE, MAPE).
**Resources:**
Full setup steps and code in the Db2 AI Cookbook repo:
github.com/IBM/db2-ai-cookbook/tree/main/07-in-database-ml/gosales-linear-regression
Like and subscribe for more Db2, SQL, and AI tutorials. Drop questions in the comments.
Description:
**Learn how to predict customer spending using Linear Regression with Db2's built-in machine learning stored procedures. No external tools required.**
In this demo, I walk through training a regression model entirely inside the database using Db2's ML stored procedures. Starting with 48,202 customer records, I show the full pipeline: data preprocessing, model training, prediction generation, and evaluation.
**What you'll learn:**
- How to split datasets into training and test partitions (80/20 split)
- Data cleaning with Db2 stored procedures (handling missing values like customer age)
- Training a linear regression model directly in SQL
- Generating real-time predictions by changing customer attributes
- Evaluating model quality with MAE and MAPE
**What's covered:**
The problem of predicting customer spend. The dataset and what we know about each customer. Training a linear regression model with Db2 stored procedures. Data preprocessing steps: splitting, cleaning, imputation. Running the training pipeline. Making predictions with different customer attributes. The prediction SQL behind the scenes. Model evaluation metrics (MAE, MAPE).
**Resources:**
Full setup steps and code in the Db2 AI Cookbook repo:
github.com/IBM/db2-ai-cookbook/tree/main/07-in-database-ml/gosales-linear-regression
Like and subscribe for more Db2, SQL, and AI tutorials. Drop questions in the comments.


