code: def create_customer_journeys(
      n_samples: int = 100,
      conversion_rate: float = 0.3,
      product_view_rate: float = 0.6,
      max_product_view: int = 5,
      random_generator: Optional[np.random.Generator] = None,
  ) -> pd.DataFrame:
      """Creates synthetic data of customer product views and conversions.
  
      Args:
        n_samples: Number of samples to be generated.
        conversion_rate: Assumed conversion rate, i.e. probability that customer
          makes a purchase. Needs to be between 0-1.
        product_view_rate: Assumed probability that customer views a product. Needs
          to be between 0-1.
        max_product_view: Upper limit of possible product views. Needs to be >0. The
          expected number of viewed products is product_view_rate *
          max_product_view. For instance, if product_view_rate is .50 and
          max_product_view is 4, a customer will on minimum view two products.
        random_generator: Random generator that can be passed to make outputs
          reproducible.
  
      Returns:
        DataFrame of synthetic data.
  
      Raises:
        UserWarning: if either conversion_rate or product_view_rate is 0.
        ValueError: if max_product_view is 0.
      """
      all_customer_journeys = []
  
      if conversion_rate == 0 or product_view_rate == 0:
          raise UserWarning(
              "Setting conversion_rate or product_view_rate to 0 implies that no conversions can occur."
          )
  
      if max_product_view <= 0:
          raise ValueError(
              f"max_product_view needs to be larger 0, but is {max_product_view}"
          )
  
      if not random_generator:
          random_generator = np.random.default_rng()
  
      for _ in range(n_samples):
          n_products_viewed = np.sum(
              random_generator.binomial(
                  1, p=product_view_rate, size=max_product_view
              )
          )
          which_products_viewed = random_generator.integers(
              1,
              len(list(AvailableProducts)) + 1,
              size=n_products_viewed,
          )
          is_conversion = random_generator.binomial(
              1, p=conversion_rate
          )
          products_viewed = {}
          basket_value = 0
          for index, product_id in enumerate(which_products_viewed):
              product = Product(product=AvailableProducts(product_id))
              products_viewed[f"product_view_{index}"] = product.name
              if is_conversion:
                  basket_value += product.cost(
                      random_generator=random_generator
                  )
  
          products_viewed["conversion_value"] = basket_value
          all_customer_journeys.append(products_viewed)
      data = pd.DataFrame(all_customer_journeys)
      data.replace({"t_shirt": "t-shirt"}, inplace=True)
      return data.reindex(sorted(data.columns), axis=1)
  
file_path: pipelinedp/examples/codelab/generate_customer_journeys.py
imports: from absl import app
  from absl import flags
  import enum
  from typing import Optional
  import numpy
  import pandas
label_desc: Use image node_id 1 for calling a global function with example usage: create_customer_journeys(n_samples, conversion_rate, product_view_rate, max_product_view, random_generator) and returns: data