{
  "id": 557357,
  "title": "Solution Overview",
  "content": "<h1>Solution Overview</h1>\n<p>Hey everyone! We wanted to share how we approached this customer experience prediction challenge. Let us walk you through what we did:</p>\n<h2>Our Approach</h2>\n<p>For this challenge, we selected <strong>XGBoost</strong> as our primary model. XGBoost's ability to handle both numerical and categorical data, coupled with its robust performance, made it a natural choice for the structured dataset we worked with.</p>\n<h2>Data Preprocessing</h2>\n<p>We dedicated significant effort to understanding and preparing the data. Below are the key steps we followed:</p>\n<h3>1. Handling Missing Values</h3>\n<ul>\n<li><strong>Numeric Columns:</strong> Filled with the median.</li>\n<li><strong>Categorical Columns:</strong> Filled with the mode.</li>\n</ul>\n<pre><code>\n col  numeric_cols:\n    data[col] = data[col].fillna(data[col].median())\n\n\n col  categorical_cols:\n    data[col] = data[col].fillna(data[col].mode()[])\n</code></pre>\n<h3>2. Date Features</h3>\n<p>We engineered date-related features, breaking down date columns into components like year, month, day, and weekend indicators. Additionally, we calculated meaningful time differences:</p>\n<pre><code>data[] = data[col].dt.year.fillna(-).astype()\ndata[] = data[col].dt.month.fillna(-).astype()\ndata[] = (data[col].dt.dayofweek &gt;= ).astype()\n</code></pre>\n<h3>3. Feature Engineering</h3>\n<p>To enhance the dataset, we created new features:</p>\n<ul>\n<li><strong>Pricing Features:</strong><ul>\n<li>Discount amounts and percentages:<br>\n<code>python\ndata['discount_amount'] = data['Product_value'] - data['final_payment']\ndata['discount_percentage'] = (data['discount_amount'] / data['Product_value'] * 100).clip(0, 100)\n</code></li></ul></li>\n<li><strong>Loyalty Program Features:</strong><ul>\n<li>Indicators for redeemed points and their value ratio:<br>\n<code>python\ndata['has_redeemed_points'] = (data['loyalty_points_redeemed'] &gt; 0).astype(int)\ndata['points_to_value_ratio'] = data['loyalty_points_redeemed'] / (data['Product_value'] + 1)\n</code></li></ul></li>\n</ul>\n<h3>4. Encoding Categorical Variables</h3>\n<p>We converted text-based categories into numeric representations using label encoding and one-hot encoding.</p>\n<h2>Modeling</h2>\n<h3>1. Model Selection</h3>\n<p>We utilized <strong>XGBoost</strong>, a gradient boosting algorithm, for its suitability to structured datasets.</p>\n<h3>2. Hyperparameter Tuning</h3>\n<p>We optimized the following hyperparameters through trial and error:</p>\n<pre><code>params = {\n    : ,\n    : ,\n    : ,\n    : ,\n    : ,\n    : ,\n    : \n}\n</code></pre>\n<h3>3. Cross-Validation</h3>\n<p>To validate the model's performance, we implemented 5-fold stratified cross-validation:</p>\n<pre><code>skf = StratifiedKFold(n_splits=, shuffle=, random_state=)\n train_idx, val_idx  skf.split(X_train, y_train):\n    model = xgb.XGBClassifier(**params)\n    model.fit(X_train[train_idx], y_train[train_idx],\n              eval_set=[(X_train[val_idx], y_train[val_idx])],\n              early_stopping_rounds=, verbose=)\n</code></pre>\n<h3>4. PCA Features</h3>\n<p>We applied Principal Component Analysis (PCA) to capture latent patterns in the data:</p>\n<pre><code>pca = PCA(n_components=)\npca_features = pca.fit_transform(X_numeric_transformed)\n i  (pca_features.shape[]):\n    X[] = pca_features[:, i]\n</code></pre>\n<h3>5. Early Stopping</h3>\n<p>To prevent overfitting, we used early stopping based on validation loss during training.</p>\n<h2>How We Evaluated It</h2>\n<p>Our primary evaluation metric was the <strong>weighted F1 score</strong> to account for imbalanced class distributions. We also:</p>\n<ul>\n<li>Reviewed the classification report to analyze predictions for each category.</li>\n<li>Used cross-validation to ensure stability across data splits.</li>\n</ul>\n<pre><code>weighted_f1 = f1_score(y_val, y_pred, average=)\n</code></pre>\n<h2>Biggest Challenges</h2>\n<ol>\n<li><strong>Date Handling:</strong> Engineering meaningful features from date columns required careful thought.</li>\n<li><strong>Categorical Variables:</strong> Balancing effective encoding with model performance.</li>\n<li><strong>Feature Selection:</strong> Ensuring that all new features contributed positively to predictions.</li>\n</ol>\n<h2>What We Learned</h2>\n<ol>\n<li><strong>Feature Engineering:</strong> Time spent on creating meaningful features, especially around dates and loyalty programs, greatly improved model performance.</li>\n<li><strong>Importance of Pricing Features:</strong> Discount-related features were highly predictive.</li>\n<li><strong>Cross-Validation:</strong> Ensured that our model was generalizable.</li>\n<li><strong>PCA Features:</strong> Helped uncover patterns missed by manual feature creation.</li>\n</ol>",
  "comments": [],
  "comment_count": 0,
  "messages": [
    {
      "id": 3099970,
      "postDate": "2025-01-18T15:32:07.020Z",
      "content": "<h1>Solution Overview</h1>\n<p>Hey everyone! We wanted to share how we approached this customer experience prediction challenge. Let us walk you through what we did:</p>\n<h2>Our Approach</h2>\n<p>For this challenge, we selected <strong>XGBoost</strong> as our primary model. XGBoost's ability to handle both numerical and categorical data, coupled with its robust performance, made it a natural choice for the structured dataset we worked with.</p>\n<h2>Data Preprocessing</h2>\n<p>We dedicated significant effort to understanding and preparing the data. Below are the key steps we followed:</p>\n<h3>1. Handling Missing Values</h3>\n<ul>\n<li><strong>Numeric Columns:</strong> Filled with the median.</li>\n<li><strong>Categorical Columns:</strong> Filled with the mode.</li>\n</ul>\n<pre><code>\n col  numeric_cols:\n    data[col] = data[col].fillna(data[col].median())\n\n\n col  categorical_cols:\n    data[col] = data[col].fillna(data[col].mode()[])\n</code></pre>\n<h3>2. Date Features</h3>\n<p>We engineered date-related features, breaking down date columns into components like year, month, day, and weekend indicators. Additionally, we calculated meaningful time differences:</p>\n<pre><code>data[] = data[col].dt.year.fillna(-).astype()\ndata[] = data[col].dt.month.fillna(-).astype()\ndata[] = (data[col].dt.dayofweek &gt;= ).astype()\n</code></pre>\n<h3>3. Feature Engineering</h3>\n<p>To enhance the dataset, we created new features:</p>\n<ul>\n<li><strong>Pricing Features:</strong><ul>\n<li>Discount amounts and percentages:<br>\n<code>python\ndata['discount_amount'] = data['Product_value'] - data['final_payment']\ndata['discount_percentage'] = (data['discount_amount'] / data['Product_value'] * 100).clip(0, 100)\n</code></li></ul></li>\n<li><strong>Loyalty Program Features:</strong><ul>\n<li>Indicators for redeemed points and their value ratio:<br>\n<code>python\ndata['has_redeemed_points'] = (data['loyalty_points_redeemed'] &gt; 0).astype(int)\ndata['points_to_value_ratio'] = data['loyalty_points_redeemed'] / (data['Product_value'] + 1)\n</code></li></ul></li>\n</ul>\n<h3>4. Encoding Categorical Variables</h3>\n<p>We converted text-based categories into numeric representations using label encoding and one-hot encoding.</p>\n<h2>Modeling</h2>\n<h3>1. Model Selection</h3>\n<p>We utilized <strong>XGBoost</strong>, a gradient boosting algorithm, for its suitability to structured datasets.</p>\n<h3>2. Hyperparameter Tuning</h3>\n<p>We optimized the following hyperparameters through trial and error:</p>\n<pre><code>params = {\n    : ,\n    : ,\n    : ,\n    : ,\n    : ,\n    : ,\n    : \n}\n</code></pre>\n<h3>3. Cross-Validation</h3>\n<p>To validate the model's performance, we implemented 5-fold stratified cross-validation:</p>\n<pre><code>skf = StratifiedKFold(n_splits=, shuffle=, random_state=)\n train_idx, val_idx  skf.split(X_train, y_train):\n    model = xgb.XGBClassifier(**params)\n    model.fit(X_train[train_idx], y_train[train_idx],\n              eval_set=[(X_train[val_idx], y_train[val_idx])],\n              early_stopping_rounds=, verbose=)\n</code></pre>\n<h3>4. PCA Features</h3>\n<p>We applied Principal Component Analysis (PCA) to capture latent patterns in the data:</p>\n<pre><code>pca = PCA(n_components=)\npca_features = pca.fit_transform(X_numeric_transformed)\n i  (pca_features.shape[]):\n    X[] = pca_features[:, i]\n</code></pre>\n<h3>5. Early Stopping</h3>\n<p>To prevent overfitting, we used early stopping based on validation loss during training.</p>\n<h2>How We Evaluated It</h2>\n<p>Our primary evaluation metric was the <strong>weighted F1 score</strong> to account for imbalanced class distributions. We also:</p>\n<ul>\n<li>Reviewed the classification report to analyze predictions for each category.</li>\n<li>Used cross-validation to ensure stability across data splits.</li>\n</ul>\n<pre><code>weighted_f1 = f1_score(y_val, y_pred, average=)\n</code></pre>\n<h2>Biggest Challenges</h2>\n<ol>\n<li><strong>Date Handling:</strong> Engineering meaningful features from date columns required careful thought.</li>\n<li><strong>Categorical Variables:</strong> Balancing effective encoding with model performance.</li>\n<li><strong>Feature Selection:</strong> Ensuring that all new features contributed positively to predictions.</li>\n</ol>\n<h2>What We Learned</h2>\n<ol>\n<li><strong>Feature Engineering:</strong> Time spent on creating meaningful features, especially around dates and loyalty programs, greatly improved model performance.</li>\n<li><strong>Importance of Pricing Features:</strong> Discount-related features were highly predictive.</li>\n<li><strong>Cross-Validation:</strong> Ensured that our model was generalizable.</li>\n<li><strong>PCA Features:</strong> Helped uncover patterns missed by manual feature creation.</li>\n</ol>",
      "rawMarkdown": "# Solution Overview\n\nHey everyone! We wanted to share how we approached this customer experience prediction challenge. Let us walk you through what we did:\n\n\n## Our Approach\n\nFor this challenge, we selected **XGBoost** as our primary model. XGBoost's ability to handle both numerical and categorical data, coupled with its robust performance, made it a natural choice for the structured dataset we worked with.\n\n\n## Data Preprocessing\n\nWe dedicated significant effort to understanding and preparing the data. Below are the key steps we followed:\n\n### 1. Handling Missing Values\n- **Numeric Columns:** Filled with the median.\n- **Categorical Columns:** Filled with the mode.\n```python\n# Fill numeric columns with median\nfor col in numeric_cols:\n    data[col] = data[col].fillna(data[col].median())\n\n# Fill categorical columns with mode\nfor col in categorical_cols:\n    data[col] = data[col].fillna(data[col].mode()[0])\n```\n\n### 2. Date Features\nWe engineered date-related features, breaking down date columns into components like year, month, day, and weekend indicators. Additionally, we calculated meaningful time differences:\n```python\ndata[f'{col}_year'] = data[col].dt.year.fillna(-1).astype(int)\ndata[f'{col}_month'] = data[col].dt.month.fillna(-1).astype(int)\ndata[f'{col}_is_weekend'] = (data[col].dt.dayofweek >= 5).astype(int)\n```\n\n### 3. Feature Engineering\nTo enhance the dataset, we created new features:\n- **Pricing Features:**\n    - Discount amounts and percentages:\n    ```python\n    data['discount_amount'] = data['Product_value'] - data['final_payment']\n    data['discount_percentage'] = (data['discount_amount'] / data['Product_value'] * 100).clip(0, 100)\n    ```\n- **Loyalty Program Features:**\n    - Indicators for redeemed points and their value ratio:\n    ```python\n    data['has_redeemed_points'] = (data['loyalty_points_redeemed'] > 0).astype(int)\n    data['points_to_value_ratio'] = data['loyalty_points_redeemed'] / (data['Product_value'] + 1)\n    ```\n\n### 4. Encoding Categorical Variables\nWe converted text-based categories into numeric representations using label encoding and one-hot encoding.\n\n\n## Modeling\n\n### 1. Model Selection\nWe utilized **XGBoost**, a gradient boosting algorithm, for its suitability to structured datasets.\n\n### 2. Hyperparameter Tuning\nWe optimized the following hyperparameters through trial and error:\n```python\nparams = {\n    'n_estimators': 1000,\n    'max_depth': 9,\n    'learning_rate': 0.02,\n    'subsample': 0.9,\n    'colsample_bytree': 0.9,\n    'min_child_weight': 1,\n    'gamma': 0.04\n}\n```\n\n### 3. Cross-Validation\nTo validate the model's performance, we implemented 5-fold stratified cross-validation:\n```python\nskf = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)\nfor train_idx, val_idx in skf.split(X_train, y_train):\n    model = xgb.XGBClassifier(**params)\n    model.fit(X_train[train_idx], y_train[train_idx],\n              eval_set=[(X_train[val_idx], y_train[val_idx])],\n              early_stopping_rounds=50, verbose=False)\n```\n\n### 4. PCA Features\nWe applied Principal Component Analysis (PCA) to capture latent patterns in the data:\n```python\npca = PCA(n_components=10)\npca_features = pca.fit_transform(X_numeric_transformed)\nfor i in range(pca_features.shape[1]):\n    X[f'pca_feature_{i}'] = pca_features[:, i]\n```\n\n### 5. Early Stopping\nTo prevent overfitting, we used early stopping based on validation loss during training.\n\n\n## How We Evaluated It\n\nOur primary evaluation metric was the **weighted F1 score** to account for imbalanced class distributions. We also:\n- Reviewed the classification report to analyze predictions for each category.\n- Used cross-validation to ensure stability across data splits.\n```python\nweighted_f1 = f1_score(y_val, y_pred, average='weighted')\n```\n\n\n## Biggest Challenges\n\n1. **Date Handling:** Engineering meaningful features from date columns required careful thought.\n2. **Categorical Variables:** Balancing effective encoding with model performance.\n3. **Feature Selection:** Ensuring that all new features contributed positively to predictions.\n\n\n## What We Learned\n\n1. **Feature Engineering:** Time spent on creating meaningful features, especially around dates and loyalty programs, greatly improved model performance.\n2. **Importance of Pricing Features:** Discount-related features were highly predictive.\n3. **Cross-Validation:** Ensured that our model was generalizable.\n4. **PCA Features:** Helped uncover patterns missed by manual feature creation.\n\n\n\n",
      "votes": 2
    }
  ],
  "complete": true,
  "source": "live",
  "fetched_at": "2026-10-19T13:43:46Z",
  "competition_id": 90922,
  "competition_slug": "Predict-the-Customer-Satisfaction-CSE-22",
  "team_id": 13197363,
  "solution_url": "/competitions/Predict-the-Customer-Satisfaction-CSE-22/writeups/sd-solution-overview"
}