Examples
Real-world examples demonstrating Pulse capabilities for common ML use cases.
Use Cases
Fraud Detection
Real-time fraud detection for financial transactions with explainable predictions.
classificationreal-timeexplainability
Sentiment Analysis
Analyze customer feedback and reviews with multi-label classification.
nlpclassificationbatch
Image Classification
Classify product images with automatic retraining on new categories.
computer-visionself-retrainingdrift-detection
Demand Forecasting
Predict product demand with time-series models and automatic data snapshots.
time-seriesregressionscheduled-training
Fraud Detection Example
A complete example of building a fraud detection system with Pulse.
1. Model Definition
# models/fraud-detector.model.yaml
model: fraud-detector
version: "1.0.0"
runtime: python3.11
input:
type: object
properties:
transaction_id:
type: string
format: uuid
amount:
type: number
minimum: 0
merchant_category:
type: string
enum: [retail, electronics, travel, food, services]
user_location:
type: object
properties:
lat:
type: number
lng:
type: number
device_fingerprint:
type: string
time_of_day:
type: number
minimum: 0
maximum: 24
output:
type: object
properties:
is_fraud:
type: boolean
confidence:
type: number
minimum: 0
maximum: 1
risk_factors:
type: array
items:
type: string
recommended_action:
type: string
enum: [approve, review, decline]
training:
datasource: transactions-db
snapshot: required
schedule: "0 2 * * *"
validation:
split: 0.2
metrics:
- accuracy
- precision
- recall
- f1_score
- auc_roc
inference:
timeout: 50ms
retries: 2
cache:
enabled: true
ttl: 0 # No caching for fraud detection
drift:
enabled: true
baseline: training
threshold: 0.1
metrics:
- feature_distribution
- prediction_distribution
action: notify2. Datasource Configuration
# datasources/transactions-db.datasource.yaml
datasource: transactions-db
type: postgresql
connection:
host: ${POSTGRES_HOST}
port: 5432
database: fraud_detection
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
ssl: required
schema:
table: transactions
columns:
- name: id
type: uuid
primary: true
- name: amount
type: decimal
- name: merchant_category
type: string
- name: user_lat
type: decimal
- name: user_lng
type: decimal
- name: device_fingerprint
type: string
- name: created_at
type: timestamp
- name: is_fraud
type: boolean
label: true # This is the training label
query:
filter: "created_at >= NOW() - INTERVAL '90 days'"
snapshot:
strategy: incremental
column: created_at
retention: 180d3. Training Script
# training/train.py
import pulse
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.preprocessing import StandardScaler
import joblib
def train(data, config):
"""Train fraud detection model."""
# Prepare features
X = data[['amount', 'merchant_category_encoded',
'user_lat', 'user_lng', 'hour_of_day']]
y = data['is_fraud']
# Scale features
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# Train model
model = GradientBoostingClassifier(
n_estimators=100,
max_depth=6,
learning_rate=0.1,
random_state=42
)
model.fit(X_scaled, y)
# Save artifacts
pulse.save_artifact('model.joblib', model)
pulse.save_artifact('scaler.joblib', scaler)
# Log metrics
pulse.log_metric('accuracy', model.score(X_scaled, y))
return model
def infer(input_data, artifacts):
"""Run inference on new transaction."""
model = artifacts['model.joblib']
scaler = artifacts['scaler.joblib']
# Prepare features
features = prepare_features(input_data)
features_scaled = scaler.transform([features])
# Predict
proba = model.predict_proba(features_scaled)[0]
is_fraud = proba[1] > 0.5
# Get risk factors
risk_factors = explain_prediction(model, features_scaled)
return {
'is_fraud': is_fraud,
'confidence': float(proba[1]),
'risk_factors': risk_factors,
'recommended_action': get_action(proba[1])
}4. Deploy and Test
# Validate configuration
pulse validate
# Create initial snapshot
pulse snapshot transactions-db
# Train the model
pulse train fraud-detector --watch
# Deploy to production
pulse deploy fraud-detector
# Test inference
curl -X POST https://api.pulse.dev/v1/infer/fraud-detector \
-H "Authorization: Bearer $PULSE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"transaction_id": "550e8400-e29b-41d4-a716-446655440000",
"amount": 1500.00,
"merchant_category": "electronics",
"user_location": {"lat": 40.7128, "lng": -74.0060},
"device_fingerprint": "abc123",
"time_of_day": 14.5
}'
# Response
{
"is_fraud": false,
"confidence": 0.12,
"risk_factors": [],
"recommended_action": "approve"
}More Examples
Find more examples in our GitHub repository: