Building Your First Model

This tutorial guides you through the process of building your first conversion flow model using the ConversionFlow library.

Prerequisites

Before starting, make sure you have:

Dataset Preparation

The ConversionFlow library expects your data to contain information about user interactions with different touchpoints in the customer journey. The data should be in a format where:

  • Each row represents a user interaction

  • Columns represent different touchpoints or events

  • Values indicate whether a user interacted with a particular touchpoint (1/0 or True/False)

Example structure:

user_id, car_configuration, brochure_request, test_drive, purchase
user1, 1, 1, 0, 0
user2, 1, 0, 0, 0
user3, 1, 1, 1, 1
...

Defining Your Model Structure

The first step is to define the structure of your Bayesian Network model in the configuration file. This includes specifying the nodes (touchpoints) and the directed edges (relationships) between them.

model:
  name: "my_first_model"
  description: "A simple conversion flow model"
  nodes:
    stage1:
      - website_visit
      - car_configuration
    stage2:
      - brochure_request
      - dealer_search
    final:
      - test_drive
      - purchase
  edges:
    - [website_visit, car_configuration]
    - [car_configuration, brochure_request]
    - [car_configuration, dealer_search]
    - [brochure_request, test_drive]
    - [dealer_search, test_drive]
    - [test_drive, purchase]

Running the Model

With your data prepared and model structure defined, you can now run the full pipeline:

from conversionflow import ConversionFlow

# Initialize with your configuration
cf = ConversionFlow(config_path="config.yml")

# Load your data
cf.load_data("path/to/your/data.csv")

# Run the estimation stage
estimation_results = cf.run_estimation()

# Run the optimization stage
optimization_results = cf.run_optimization()

# Generate reports and visualizations
cf.generate_reports()

Understanding the Results

After running the model, you will find several output files in the specified output directory:

  1. Parameter Summaries: Contains the estimated parameters for your model, including the beta coefficients that represent the strength of relationships between touchpoints.

  2. Model Diagnostics: Includes convergence diagnostics and model quality metrics.

  3. Optimal Budget Allocation: Provides the recommended budget allocation across touchpoints based on the optimization stage.

  4. Model Analysis: A text file with a detailed analysis of the model results.

Visualizing the Model

ConversionFlow provides built-in visualization capabilities for the Bayesian Network and optimization results:

# Plot the Bayesian Network structure
cf.plot_network()

# Plot the parameter distributions
cf.plot_parameters()

# Plot the optimal budget allocation
cf.plot_optimization_results()

Next Steps

Now that you’ve built your first model, you can:

  1. Refine the model structure based on domain knowledge

  2. Experiment with different priors and model configurations

  3. Incorporate more data or additional touchpoints

  4. Apply the optimization results to your marketing strategy

See the How-to Guides for more advanced usage scenarios.