machine learning
slug: recipe-machine-learning-predict-customer-spending-using-machine-learningcategory: business analytics / predictive modeling
You want to predict spending for new customers based on historical data so that you can:
Train a machine learning model on historical customer data, then apply it to new customers to generate predicted outcomes:
loadInline step → trainModel step → loadInline step → useModel step → print step
Training dataset: Historical records including features and target variable
predicted_<target> (customizable via output_column)| Step | Purpose | Notes |
|---|---|---|
| loadInline step | Load historical training data | Inline data definition for small or test datasets |
| trainModel step | Train ML model | Select target, features, and modelType; store trained model in workflow extras |
| loadInline step | Load new customers | Define dataset for scoring |
| useModel step | Apply trained model | Predictions added as a new column (output_column) |
| print step | Display predictions | Can visualize predicted outcomes or export results |
modelTypetest_size for model evaluationoutput_column to clearly label predicted resultssteps:
- loadInline:
data:
- {age: 22, income: 38000, spend: 800}
- {age: 25, income: 45000, spend: 1200}
- {age: 29, income: 56000, spend: 1800}
output: trainingData
- trainModel:
dataset: trainingData
target: spend
features: [age, income]
modelType: linear
params:
normalize: true
test_size: 0.2
learning_rate: 0.01
max_iterations: 1000
output: spendModel
- loadInline:
data:
- {age: 28, income: 52000}
- {age: 42, income: 81000}
output: newCustomers
- useModel:
dataset: newCustomers
model: spendModel
output_column: predicted_spend
- print:
title: "Predicted Customer Spending"
| age | income | predicted_spend |
|---|---|---|
| 28 | 52000 | 1420 |
| 42 | 81000 | 2800 |