Citi boss Jane Fraser says 2 AI races will decide banking’s future
Back to Tutorials
financeTutorialintermediate

Citi boss Jane Fraser says 2 AI races will decide banking’s future

July 5, 202616 views4 min read

Learn how to build a machine learning model to classify banking customers into segments based on transaction behavior, a key capability for banks navigating AI-driven competition.

Introduction

In the financial sector, AI is transforming how banks operate, compete, and serve customers. As Citi CEO Jane Fraser highlighted, the banking industry is engaged in two simultaneous AI races: one focused on revenue growth and innovation, and another on defensive strategies to maintain competitive advantage. This tutorial will teach you how to implement a machine learning model that can help banks analyze customer behavior and predict potential service needs—key to both races. We'll use Python with scikit-learn to build a predictive model that can classify customer segments based on transaction data.

Prerequisites

  • Basic knowledge of Python programming
  • Understanding of machine learning concepts (classification, features, labels)
  • Installed Python libraries: pandas, scikit-learn, numpy
  • Sample transaction dataset (we'll generate one for demonstration)

Step-by-Step Instructions

1. Set Up Your Environment

First, ensure you have the required Python libraries installed. Run the following command in your terminal or command prompt:

pip install pandas scikit-learn numpy

This installs the necessary tools to handle data and build machine learning models.

2. Generate Sample Customer Transaction Data

We'll create a synthetic dataset that mimics real-world customer transaction data. This will include features like transaction amounts, frequency, and types of services used.

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

# Generate sample data
np.random.seed(42)
num_customers = 1000

# Create synthetic data
data = {
    'customer_id': range(1, num_customers + 1),
    'avg_transaction': np.random.normal(500, 200, num_customers),
    'transaction_frequency': np.random.poisson(5, num_customers),
    'online_services_used': np.random.randint(0, 10, num_customers),
    'account_balance': np.random.normal(5000, 2000, num_customers)
}

df = pd.DataFrame(data)

# Create a target variable (customer segment)
df['segment'] = np.where(df['account_balance'] > 5000, 'Premium', 'Standard')
df['segment'] = np.where(df['transaction_frequency'] > 8, 'High-Value', df['segment'])

print(df.head())

This code creates a dataset with 1000 customers and assigns them to segments based on their account balance and transaction frequency. This simulates how banks might categorize customers for targeted services.

3. Prepare the Data for Training

Before training the model, we need to split the data into features and labels, and then into training and testing sets.

# Define features and target
features = ['avg_transaction', 'transaction_frequency', 'online_services_used', 'account_balance']
X = df[features]
y = df['segment']

# Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

print("Training set size:", X_train.shape)
print("Testing set size:", X_test.shape)

We separate the features (what we use to predict) from the target (what we're trying to predict). This step is crucial for building a model that generalizes well to new data.

4. Train the Machine Learning Model

We'll use a Random Forest classifier, which is effective for classification tasks and handles mixed data types well.

# Initialize and train the model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)

# Make predictions
y_pred = model.predict(X_test)

print("Model trained successfully!")

The Random Forest algorithm combines multiple decision trees to make predictions. It's robust to outliers and overfitting, making it ideal for financial data analysis.

5. Evaluate Model Performance

After training, we evaluate how well the model performs on unseen data.

# Evaluate the model
print(classification_report(y_test, y_pred))

This output shows precision, recall, and F1-score for each customer segment, helping us understand where the model excels and where it may need improvement.

6. Predict New Customer Segments

Now that the model is trained, we can use it to classify new customers based on their transaction data.

# Create a new customer record
new_customer = [[600, 7, 5, 6000]]  # avg_transaction, transaction_frequency, online_services_used, account_balance

# Predict the segment
predicted_segment = model.predict(new_customer)
print(f"Predicted customer segment: {predicted_segment[0]}")

This step demonstrates how the model can be used in practice to categorize new customers and tailor banking services accordingly.

Summary

This tutorial showed how to build a machine learning model that can help banks classify customers into segments based on transaction behavior. By leveraging data like transaction frequency and account balance, financial institutions can better understand their customer base and personalize services—key to both AI races identified by Citi CEO Jane Fraser. This model can be expanded with more features, different algorithms, and real-world data to improve its predictive power and business impact.

Source: TNW Neural

Related Articles