input: Write a function to preprocess a text dataset for logistic regression, including creating a bag of words model.
  assert preprocess_text_data('spam_emails.csv') == (X_expected, y_expected)
  assert preprocess_text_data('ham_emails.csv') == (X_expected, y_expected)
  assert preprocess_text_data('mixed_emails.csv') == (X_expected, y_expected)
output: import pandas as pd
  from sklearn.feature_extraction.text import CountVectorizer
  from sklearn.preprocessing import LabelEncoder
  
  def preprocess_text_data(filename):
      # Load the dataset
      df = pd.read_csv(filename)
      
      # Check if the necessary columns are present
      if 'text' not in df.columns or 'label' not in df.columns:
          raise ValueError("The input file must contain 'text' and 'label' columns.")
      
      # Extract features and labels
      texts = df['text'].values
      labels = df['label'].values
      
      # Create a bag of words model
      vectorizer = CountVectorizer()
      X = vectorizer.fit_transform(texts)
      
      # Encode the labels
      label_encoder = LabelEncoder()
      y = label_encoder.fit_transform(labels)
      
      return X, y