Skip to main content
Welcome to this guide on how to generate a synthetic healthcare claims dataset for your project. In this tutorial, you’ll learn how to set up your development environment, create realistic synthetic data with anomalies, and export it to a CSV file for further analysis or model training.

Step 1: Installing Required Packages

Begin by creating a new file named requirements.txt in your VS Code editor. Add the following package list to the file:
Save the file and open your terminal. Then run the command below to install all required packages:
The command above installs all dependencies mentioned in your requirements.txt file. Once the installation is complete, you are ready to move on to generating synthetic data.

Step 2: Generating Synthetic Health Claims Data

Create a new Python file named synthetic_health_claims.py. This script generates a synthetic dataset with both normal claims and anomalous claims to simulate outlier events.

How the Script Works

  • Imports necessary libraries and sets a random seed for reproducibility.
  • Generates 1,000 normal claim records with fields such as claim_id, claim_amount, num_services, patient_age, provider_id, and days_since_last_claim.
  • Introduces 50 anomalous entries with significantly higher claim amounts and additional service counts.
  • Combines, shuffles, and exports the dataset to a CSV file.

Code Implementation

To run the script, execute the following command in your terminal:
This script creates a balanced dataset containing both normal and anomalous data points, ideal for training and testing anomaly detection models.

Step 3: Preparing Data for Model Experiment

After generating the initial synthetic dataset, you might want to simulate a different testing scenario by modifying the dataset. In this step, we introduce a smaller set of anomalies (5 records) and omit the num_services field to tailor the dataset for a specific model experiment.

Code Implementation for Model Experiment

Run the updated script with the command below:
The modified dataset now includes an updated anomaly configuration, which is useful for various experimental setups in model validation.

In this guide, we demonstrated how to create a comprehensive synthetic dataset with both normal and anomalous healthcare claims. The resulting CSV file, synthetic_health_claims.csv, can now be used in your data analysis or machine learning projects. For more insights on data preparation and anomaly detection, explore our related articles and documentation.

Watch Video