Machine Learning Project · KNIME Analytics Platform

Predicting Sales Quantity
with Random Forest

Built an end-to-end regression pipeline on live BigQuery data — starting from a baseline linear model and iterating to a 3.5× improvement in predictive accuracy.

Baseline
0.197
Linear Regression
3.5× → better
Final Model
0.685
Random Forest
KNIME Random Forest Regression BigQuery Feature Engineering Model Evaluation

Forecasting units sold from historical order data

The dataset lives in a shared Google BigQuery project — go_explore_project.daily_sales — containing 1,000 sales records across three retailers, multiple product lines, and five order methods spanning 2015–2017.

The goal: given a retailer, product, order method, and sale price, predict how many units will be sold. A working model here enables inventory planning, demand forecasting, and promotional targeting.

BigQuery — daily_sales schema
SELECT retailer_code, -- 3 unique retailers product_number, -- 400+ unique products order_method_code, -- 5 methods (online, phone, etc.) unit_sale_price, -- range: 6 – 54,747 quantity -- TARGET: range 1 – 1,795 FROM `mystical-proj-500509.go_explore_project.daily_sales` LIMIT 1000

A visual ML pipeline built entirely in KNIME

KNIME's node-based interface makes each step of the pipeline explicit and auditable — no hidden transformations, no implicit defaults.

Google Authenticator

Service account JSON → OAuth token

→

BigQuery Connector

JDBC connection via Simba driver

→

DB Query Reader

SQL → KNIME data table

Table Partitioner

70% train / 30% test split

70% training

Random Forest Learner

Target: quantity · Features: all others

30% test

RF Predictor (Regression)

Model + test data → predictions

Numeric Scorer

R², MAE, RMSE evaluation

Key discovery: The first attempt used a DB Table Partitioner (which operates on database connections) instead of a standard Table Partitioner (which operates on KNIME data tables). ML nodes require in-memory data tables — a DB Reader node bridges the two worlds.

Why the first model failed — and what fixed it

The baseline Linear Regression treated retailer_code (values like 1115, 1132, 1133) as continuous numbers, implying that retailer 1133 is "bigger" than 1115. That's meaningless — they're categories. This produced a weak R² of 0.197.

Initial Workflow with Linear Regression

Attempting to fix this with One-Hot Encoding caused the model to explode into astronomically wrong predictions due to multicollinearity across 400+ product dummy variables.

Modified Workflow with One-Hot Encoding

The clean solution was switching to Random Forest, which handles categorical-like integers natively without encoding, and jumped R² to 0.685.

Final Workflow with Random Forest

Model comparison

✗ Linear Regression (baseline)

R² 0.197
MAE 90 units
RMSE 154 units

✓ Random Forest (final)

R² 0.685
MAE 56 units
RMSE 96 units
3.5× R² improvement
−37% Mean absolute error
68.5% Variance explained
±56 Units avg. error

An R² of 0.685 means the model explains 68.5% of the variation in sales quantity using only four input features. The remaining variance is likely driven by factors not in the dataset — seasonal promotions, stockouts, regional events.

What this project taught

🔢

Numeric codes ≠ numeric features

Retailer IDs and order method codes look like numbers but carry no ordinal meaning. Treating them as continuous variables misleads linear models significantly.

🌲

Model selection matters more than tuning

Switching from Linear Regression to Random Forest gave a larger gain than any amount of feature engineering on the linear model would have.

🔌

DB nodes vs. Table nodes are different worlds

KNIME's database nodes operate on SQL connections. ML nodes require in-memory data tables. A DB Reader node is the required bridge between the two.

📊

A bad baseline makes the improvement legible

Starting with a weak model and showing the improvement is a more compelling portfolio narrative than presenting a polished result without context.

Tools used

ToolRole in project
KNIME Analytics Platform End-to-end visual ML pipeline
Google BigQuery Source data — go_explore_project.daily_sales
Random Forest Learner (Regression) Final model — R² 0.685
Linear Regression Learner Baseline model — R² 0.197
Numeric Scorer R², MAE, RMSE evaluation
Table Partitioner 70/30 train-test split

Completion Certificate

Data Science with KNIME Certificate