help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
customer-churn
/
scripts
RSK World
customer-churn
Customer Churn Dataset
scripts
  • __init__.py332 B
  • data_exploration.py7.9 KB
  • data_preprocessing.py9.6 KB
  • feature_selection.py7.5 KB
  • generate_dataset.py5.7 KB
  • hyperparameter_tuning.py8.9 KB
  • model_training.py19.7 KB
generate_dataset.py
scripts/generate_dataset.py
Raw Download
Find: Go to:
"""
Customer Churn Dataset - Dataset Generation Script
==================================================
Provided by: RSK World
Website: https://rskworld.in/
Email: help@rskworld.in
Phone: +91 93305 39277
Contact Page: https://rskworld.in/contact.php

This script generates a comprehensive customer churn dataset with realistic data.
"""

import pandas as pd
import numpy as np
import random
from datetime import datetime, timedelta

def generate_customer_churn_dataset(n_samples=10000, random_seed=42):
    """
    Generate a comprehensive customer churn dataset
    
    Args:
        n_samples (int): Number of customer records to generate
        random_seed (int): Random seed for reproducibility
        
    Returns:
        pd.DataFrame: Generated dataset
    """
    np.random.seed(random_seed)
    random.seed(random_seed)
    
    # Define data options
    genders = ['Male', 'Female']
    cities = ['New York', 'Los Angeles', 'Chicago', 'Houston', 'Phoenix', 
              'Philadelphia', 'San Antonio', 'San Diego', 'Dallas', 'San Jose',
              'Austin', 'Jacksonville', 'Fort Worth', 'Columbus', 'Charlotte',
              'San Francisco', 'Indianapolis', 'Seattle', 'Denver', 'Washington']
    account_types = ['Basic', 'Premium', 'Enterprise']
    payment_methods = ['Credit Card', 'Bank Transfer', 'Other']
    
    data = []
    
    for i in range(1, n_samples + 1):
        gender = random.choice(genders)
        age = np.random.randint(18, 70)
        tenure = np.random.randint(0, 60)
        
        # Account type based on tenure (longer tenure = more likely premium/enterprise)
        if tenure > 36:
            account_type_weights = [0.2, 0.4, 0.4]
        elif tenure > 12:
            account_type_weights = [0.3, 0.5, 0.2]
        else:
            account_type_weights = [0.5, 0.4, 0.1]
        account_type = np.random.choice(account_types, p=account_type_weights)
        
        # Billing amount based on account type
        if account_type == 'Basic':
            billing_amount = round(np.random.normal(49.99, 5), 2)
            monthly_usage = np.random.normal(700, 200)
        elif account_type == 'Premium':
            billing_amount = round(np.random.normal(89.99, 10), 2)
            monthly_usage = np.random.normal(1200, 300)
        else:  # Enterprise
            billing_amount = round(np.random.normal(149.99, 15), 2)
            monthly_usage = np.random.normal(2200, 400)
        
        monthly_usage = max(100, round(monthly_usage, 1))
        billing_amount = max(29.99, billing_amount)
        
        payment_method = random.choice(payment_methods)
        contract_length = random.choice([12, 24, 36])
        
        # Support calls (higher for shorter tenure or higher usage)
        support_calls = max(0, int(np.random.poisson(2 + (6 - tenure // 10) + (monthly_usage > 1500))))
        
        # Last login (recent dates)
        days_ago = np.random.randint(0, 30)
        last_login = (datetime.now() - timedelta(days=days_ago)).strftime('%Y-%m-%d')
        
        # Churn prediction (based on multiple factors)
        churn_probability = 0.05  # Base probability
        if tenure < 6:
            churn_probability += 0.15
        if support_calls > 5:
            churn_probability += 0.20
        if monthly_usage < 500:
            churn_probability += 0.10
        if account_type == 'Basic' and tenure > 12:
            churn_probability += 0.05
        
        churned = np.random.random() < churn_probability
        
        churn = 'Yes' if churned else 'No'
        churn_date = ''
        if churned:
            churn_date = (datetime.now() - timedelta(days=np.random.randint(0, 90))).strftime('%Y-%m-%d')
        
        data.append({
            'CustomerID': i,
            'Gender': gender,
            'Age': age,
            'Tenure': tenure,
            'City': random.choice(cities),
            'AccountType': account_type,
            'MonthlyUsage': monthly_usage,
            'BillingAmount': billing_amount,
            'PaymentMethod': payment_method,
            'ContractLength': contract_length,
            'SupportCalls': support_calls,
            'LastLogin': last_login,
            'Churn': churn,
            'ChurnDate': churn_date
        })
    
    df = pd.DataFrame(data)
    return df

def main():
    """
    Main function to generate and save the dataset
    """
    print("Customer Churn Dataset Generator")
    print("Provided by: RSK World (https://rskworld.in/)")
    print("=" * 60)
    
    # Generate dataset
    print("\nGenerating dataset with 10,000 records...")
    df = generate_customer_churn_dataset(n_samples=10000, random_seed=42)
    
    # Add header comments
    header = """# Customer Churn Dataset
# Provided by: RSK World
# Website: https://rskworld.in/
# Email: help@rskworld.in
# Phone: +91 93305 39277
# Contact Page: https://rskworld.in/contact.php
"""
    
    # Save to CSV
    output_path = '../data/customer_churn.csv'
    df.to_csv(output_path, index=False)
    
    # Add header to file
    with open(output_path, 'r') as f:
        content = f.read()
    
    with open(output_path, 'w') as f:
        f.write(header + content)
    
    print(f"\nDataset saved to: {output_path}")
    print(f"Dataset shape: {df.shape}")
    print(f"Churn distribution:")
    print(df['Churn'].value_counts())
    print(f"\nChurn percentage:")
    print(df['Churn'].value_counts(normalize=True) * 100)
    
    print("\n" + "=" * 60)
    print("DATASET GENERATION COMPLETE")
    print("=" * 60)
    print("\nFor more information, visit: https://rskworld.in/")
    print("Contact: help@rskworld.in | +91 93305 39277")

if __name__ == "__main__":
    main()

167 lines•5.7 KB
python

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer