{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "(activity16_solution)=\n", "\n", "# Activity 16 Solution: Causal Trees\n", "\n", "**2025-04-24**\n", "\n", "---" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from econml.dml import CausalForestDML\n", "from econml.cate_interpreter import SingleTreeCateInterpreter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the cell below to load in the data. We have the following variables:\n", "\n", "- `age`: age of the customer\n", "- `income`: income of the customer, in $100k \n", "- `has_membership`: whether the customer has a membership to the online music platform\n", "- `avg_hours`: average number of hours per week the customer has spent on the platform\n", "- `demand`: outcome variable -- sales of songs on the platform\n", "- `T`: treatment (1 if the customer was given a discount, 0 otherwise)\n" ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | age | \n", "income | \n", "has_membership | \n", "avg_hours | \n", "T | \n", "demand | \n", "
---|---|---|---|---|---|---|
0 | \n", "53 | \n", "0.960863 | \n", "1 | \n", "1.834234 | \n", "0 | \n", "3.917117 | \n", "
1 | \n", "54 | \n", "0.732487 | \n", "0 | \n", "7.171411 | \n", "0 | \n", "11.585706 | \n", "
2 | \n", "33 | \n", "1.130937 | \n", "0 | \n", "5.351920 | \n", "0 | \n", "24.675960 | \n", "
3 | \n", "34 | \n", "0.929197 | \n", "0 | \n", "6.723551 | \n", "0 | \n", "6.361776 | \n", "
4 | \n", "30 | \n", "0.533527 | \n", "1 | \n", "2.448247 | \n", "1 | \n", "12.624123 | \n", "