From 6bad5cb57e08dc096885f51a844315a00d414c03 Mon Sep 17 00:00:00 2001 From: "Justin J. Wang" Date: Thu, 14 Dec 2017 15:27:06 -0800 Subject: [PATCH] update --- ...onships as Markov Chains-checkpoint.ipynb} | 379 ++++++++++++++---- ...tomer Relationships as Markov Chains.ipynb | 379 ++++++++++++++---- 2 files changed, 604 insertions(+), 154 deletions(-) rename .ipynb_checkpoints/{Markov Chain-checkpoint.ipynb => Modeling Customer Relationships as Markov Chains-checkpoint.ipynb} (80%) rename Markov Chain.ipynb => Modeling Customer Relationships as Markov Chains.ipynb (80%) diff --git a/.ipynb_checkpoints/Markov Chain-checkpoint.ipynb b/.ipynb_checkpoints/Modeling Customer Relationships as Markov Chains-checkpoint.ipynb similarity index 80% rename from .ipynb_checkpoints/Markov Chain-checkpoint.ipynb rename to .ipynb_checkpoints/Modeling Customer Relationships as Markov Chains-checkpoint.ipynb index 8a21f61..ca8ae10 100644 --- a/.ipynb_checkpoints/Markov Chain-checkpoint.ipynb +++ b/.ipynb_checkpoints/Modeling Customer Relationships as Markov Chains-checkpoint.ipynb @@ -1785,21 +1785,9 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 70, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'starting_state_counts' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m19\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minitial_counter\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mstarting_state\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstarting_state_counts\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mstarting_state\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'starting_state_counts' is not defined" - ] - } - ], + "outputs": [], "source": [ "# build starting state vector\n", "\n", @@ -1807,7 +1795,8 @@ "\n", "for i in range(1, 19):\n", " if i in initial_counter:\n", - " starting_state.append(starting_state_counts[i])\n", + "# starting_state.append(starting_state_counts[i])\n", + " starting_state.append(initial_counter[i])\n", " else:\n", " starting_state.append(0)\n", "\n", @@ -1816,18 +1805,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 833, 402, 437, 2129, 1336, 2581, 213, 136, 219, 2473, 2281,\n", + " 5763, 0, 0, 0, 806, 961, 3039])" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "starting_state" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 75, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0., 0., 0., 511., 460., 1173., 0., 0.,\n", + " 0., 0., 0., 0., 0., 0., 0., 0.,\n", + " 0., 0.])" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "new_customer_state_counts = Counter(state_df['2005'])\n", "\n", @@ -1835,32 +1851,50 @@ "\n", "for individual_state_df in state_dataframes:\n", " new_customer_state_counts += Counter(individual_state_df[individual_state_df.columns[0]])\n", - " \n", + "\n", " total_new_customers.append(individual_state_df.shape[0])\n", "\n", - "average_new_customers = np.mean(total_new_customers)//1\n", + "average_new_customers = np.mean(total_new_customers) // 1\n", "\n", "new_customer_state_dist = {}\n", "\n", "for state, state_count in new_customer_state_counts.items():\n", - " new_customer_state_dist[state] = state_count/np.sum(total_new_customers)\n", - " \n", - "new_customer_state_dist\n", + " new_customer_state_dist[state] = state_count / np.sum(total_new_customers)\n", "\n", + "new_customer_state_dist" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0., 0., 0., 511., 460., 1173., 0., 0.,\n", + " 0., 0., 0., 0., 0., 0., 0., 0.,\n", + " 0., 0.])" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ "new_state_vector_each_year = np.zeros(18)\n", - "new_state_vector_each_year[3] = average_new_customers*new_customer_state_dist[4]//1\n", - "new_state_vector_each_year[4] = average_new_customers*new_customer_state_dist[5]//1\n", - "new_state_vector_each_year[5] = average_new_customers*new_customer_state_dist[6]//1\n", + "new_state_vector_each_year[3] = average_new_customers * new_customer_state_dist[4] // 1\n", + "new_state_vector_each_year[4] = average_new_customers * new_customer_state_dist[5] // 1\n", + "new_state_vector_each_year[5] = average_new_customers * new_customer_state_dist[6] // 1\n", "\n", "new_state_vector_each_year" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 77, + "metadata": {}, "outputs": [], "source": [ "# build the reward vector\n", @@ -1871,67 +1905,144 @@ "\n", "for i in range(6):\n", " reward_vector[i] = avg_purchase_amt - 25\n", - " \n", + "\n", "for i in range(6, 12):\n", " reward_vector[i] = - 25\n", - " \n", + "\n", "for i in range(12, 18):\n", " reward_vector[i] = 0" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 159.14211651],\n", + " [ 154.022231 ],\n", + " [ 133.06375833],\n", + " [ 113.8820981 ],\n", + " [ 108.77766952],\n", + " [ 84.30834718],\n", + " [ 2.91701705],\n", + " [ 3.1785518 ],\n", + " [ -12.15984091],\n", + " [ -15.7199454 ],\n", + " [ -19.61056092],\n", + " [ -30.12109561],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "I_18 = np.identity(18)\n", + "d = .2 # discount rate\n", + "CLV = (np.linalg.inv(I_18 - (1 + d) ** (-1) * RFM_transition_matrix)).dot(reward_vector)\n", "\n", - "CLV = (np.linalg.inv(I_18 - (1+d)**(-1)*RFM_transition_matrix)).dot(reward_vector)\n", - "\n", - "CLV.reshape(len(CLV),1)" + "CLV.reshape(len(CLV), 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[148713.2146689537,\n", + " 245277.07984708826,\n", + " 274705.03597826493,\n", + " 266706.73232970835,\n", + " 251447.07983963928,\n", + " 237185.76537106108,\n", + " 225628.47407888254,\n", + " 216672.59572615713,\n", + " 209825.78460564278,\n", + " 204600.18899193767]" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# without policy\n", "\n", "revenue_no_policy = []\n", "\n", - "total_reward = reward_vector*(((1+d)**-1)*RFM_transition_matrix).dot(starting_state)+new_state_vector_each_year\n", + "total_reward = reward_vector * (((1 + d) ** -1) * RFM_transition_matrix).dot(\n", + " starting_state) + new_state_vector_each_year\n", "new_state = starting_state.copy()\n", "\n", "revenue_no_policy.append(np.sum(total_reward))\n", "\n", "for i in range(9):\n", - " new_state = (((1+d)**-1)*RFM_transition_matrix).dot(new_state)+new_state_vector_each_year\n", - " reward_this_year = reward_vector*new_state\n", - " \n", + " new_state = (((1 + d) ** -1) * RFM_transition_matrix).dot(new_state) + new_state_vector_each_year\n", + " reward_this_year = reward_vector * new_state\n", + "\n", " revenue_no_policy.append(np.sum(reward_this_year))\n", - " \n", + "\n", " total_reward += reward_this_year\n", - " \n", + "\n", "revenue_no_policy" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2280761.9514373359" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(revenue_no_policy)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2016\t148713.214669\n", + "2017\t245277.079847\n", + "2018\t274705.035978\n", + "2019\t266706.73233\n", + "2020\t251447.07984\n", + "2021\t237185.765371\n", + "2022\t225628.474079\n", + "2023\t216672.595726\n", + "2024\t209825.784606\n", + "2025\t204600.188992\n" + ] + } + ], "source": [ "for year, rev in enumerate(revenue_no_policy, 2016):\n", " print(str(year) + \"\\t\" + str(rev))" @@ -1939,11 +2050,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2016\t334786.057137\n", + "2017\t431349.922316\n", + "2018\t418106.563984\n", + "2019\t383602.358018\n", + "2020\t349896.26675\n", + "2021\t322041.043505\n", + "2022\t300205.533857\n", + "2023\t283390.943334\n", + "2024\t270503.207027\n", + "2025\t260618.696498\n" + ] + } + ], "source": [ "# with policy\n", "\n", @@ -1954,34 +2082,55 @@ "# set all the negative CLVs to zero\n", "reward_vector_with_policy[8:] = 0\n", "\n", - "total_reward = reward_vector_with_policy*(((1+d)**-1)*RFM_transition_matrix).dot(starting_state)+new_state_vector_each_year\n", + "total_reward = reward_vector_with_policy * (((1 + d) ** -1) * RFM_transition_matrix).dot(\n", + " starting_state) + new_state_vector_each_year\n", "new_state = starting_state.copy()\n", "\n", "revenue_with_policy.append(np.sum(total_reward))\n", "\n", "for i in range(9):\n", - " new_state = (((1+d)**-1)*RFM_transition_matrix).dot(new_state)+new_state_vector_each_year\n", - " reward_this_year = reward_vector_with_policy*new_state\n", - " \n", + " new_state = (((1 + d) ** -1) * RFM_transition_matrix).dot(new_state) + new_state_vector_each_year\n", + " reward_this_year = reward_vector_with_policy * new_state\n", + "\n", " revenue_with_policy.append(np.sum(reward_this_year))\n", - " \n", + "\n", " total_reward += reward_this_year\n", - " \n", + "\n", "money = []\n", - " \n", + "\n", "for year, rev in enumerate(revenue_with_policy, 2016):\n", " print(str(year) + \"\\t\" + str(rev))\n", - " money.append(str(year) + \"\\t\" + str(rev))\n", - " \n" + " money.append(str(year) + \"\\t\" + str(rev))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAFNCAYAAAC0ZpNRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHaxJREFUeJzt3XuYZVV95vHvKwgoIBdpEbnYqKhBEyHTEhTNkBCVBDPA\nxBDwhs+o6KhEc3PAOMYkgyGJwTjjiEE0YiQgNxGUeEOU4KjYIMpNAhEQkKZbFAE1SMNv/t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fAlsDm\n3B8gvwJ8NMmpDIN3wxB+fiHJVC/YFgw9Wt8A/qH1yp1ZVd9aTZ13A19r9W3AMHD7lNUdq1/l/mP9\nsyRnA7TQuCdw+jB8JeDve2md4n+wkibllQwh5peramWSG4FN1rDN1DVo90mykgderrEJsHJk/ifT\n9rGq8e3uGpm+h/t/N34U+M2quqydstyztb8W+BXgxcDFSXZnCFFvqKpzp+88yd7Afgyh7m+q6sTV\nfL6TgVOBt09rf6jHKsAPph8rSesOr0GTNNf+FTgwyaOSbAbs39ruYOiFmrIFwynBlUleAGy/lu+3\nDHhCkq1aL9V+M6x7Hu1GhSQbJHnMGva9KbCsnVJ96Uj7k6rqa8D/BH7Uav8s8IapmxGSPK0dgycC\ny6rqOOAfgd1neL8vMVyr9/Fp7as7VuczHOtN2md5MUBV/Qi4OcmBrZZHJHnWGj6rpI7YgyZpTlXV\nhUlOYji1B3Ds1OnDdsH6pcCngWOAs9v8hcDVa/l+/5HkXcBS4CbgihlWfxPwwSSvY+hlex3wwxnW\nf0f7HCtajVO9Vu9JsjNDT9XnWg/blcBOwCXttOJyhnC6D/CHSe5mCKmvmOGz3Av8LTzortN/YhXH\nqh3rTwDfBm5py6YcDByb5J0M16d9DFjd6VVJnclwM5QkSZJ64SlOSZKkzhjQJEmSOmNAkyRJ6owB\nTZIkqTMGNEmSpM4Y0CRJkjpjQJMkSeqMAU2SJKkz/x/ghd95LceEsAAAAABJRU5ErkJggg==\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "fig, axs = plt.subplots(1,1, figsize = (10,5))\n", + "fig, axs = plt.subplots(1, 1, figsize=(10, 5))\n", "\n", "total_purchases = boolean_matrix_restricted.apply(lambda x: sum(x), axis=1)\n", "\n", @@ -1994,38 +2143,116 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3354500.5924256132" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(revenue_with_policy)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "reward_vector.reshape(18, 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 159.14211651],\n", + " [ 154.022231 ],\n", + " [ 133.06375833],\n", + " [ 113.8820981 ],\n", + " [ 108.77766952],\n", + " [ 84.30834718],\n", + " [ 2.91701705],\n", + " [ 3.1785518 ],\n", + " [ -12.15984091],\n", + " [ -15.7199454 ],\n", + " [ -19.61056092],\n", + " [ -30.12109561],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "CLV.reshape(18,1)" + "CLV.reshape(18, 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2144.0" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(new_state_vector_each_year)" ] @@ -2033,9 +2260,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } diff --git a/Markov Chain.ipynb b/Modeling Customer Relationships as Markov Chains.ipynb similarity index 80% rename from Markov Chain.ipynb rename to Modeling Customer Relationships as Markov Chains.ipynb index 8a21f61..ca8ae10 100644 --- a/Markov Chain.ipynb +++ b/Modeling Customer Relationships as Markov Chains.ipynb @@ -1785,21 +1785,9 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 70, "metadata": {}, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'starting_state_counts' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m19\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0minitial_counter\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m \u001b[0mstarting_state\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstarting_state_counts\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 8\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mstarting_state\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mNameError\u001b[0m: name 'starting_state_counts' is not defined" - ] - } - ], + "outputs": [], "source": [ "# build starting state vector\n", "\n", @@ -1807,7 +1795,8 @@ "\n", "for i in range(1, 19):\n", " if i in initial_counter:\n", - " starting_state.append(starting_state_counts[i])\n", + "# starting_state.append(starting_state_counts[i])\n", + " starting_state.append(initial_counter[i])\n", " else:\n", " starting_state.append(0)\n", "\n", @@ -1816,18 +1805,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 833, 402, 437, 2129, 1336, 2581, 213, 136, 219, 2473, 2281,\n", + " 5763, 0, 0, 0, 806, 961, 3039])" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "starting_state" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 75, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0., 0., 0., 511., 460., 1173., 0., 0.,\n", + " 0., 0., 0., 0., 0., 0., 0., 0.,\n", + " 0., 0.])" + ] + }, + "execution_count": 75, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "new_customer_state_counts = Counter(state_df['2005'])\n", "\n", @@ -1835,32 +1851,50 @@ "\n", "for individual_state_df in state_dataframes:\n", " new_customer_state_counts += Counter(individual_state_df[individual_state_df.columns[0]])\n", - " \n", + "\n", " total_new_customers.append(individual_state_df.shape[0])\n", "\n", - "average_new_customers = np.mean(total_new_customers)//1\n", + "average_new_customers = np.mean(total_new_customers) // 1\n", "\n", "new_customer_state_dist = {}\n", "\n", "for state, state_count in new_customer_state_counts.items():\n", - " new_customer_state_dist[state] = state_count/np.sum(total_new_customers)\n", - " \n", - "new_customer_state_dist\n", + " new_customer_state_dist[state] = state_count / np.sum(total_new_customers)\n", "\n", + "new_customer_state_dist" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "array([ 0., 0., 0., 511., 460., 1173., 0., 0.,\n", + " 0., 0., 0., 0., 0., 0., 0., 0.,\n", + " 0., 0.])" + ] + }, + "execution_count": 76, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ "new_state_vector_each_year = np.zeros(18)\n", - "new_state_vector_each_year[3] = average_new_customers*new_customer_state_dist[4]//1\n", - "new_state_vector_each_year[4] = average_new_customers*new_customer_state_dist[5]//1\n", - "new_state_vector_each_year[5] = average_new_customers*new_customer_state_dist[6]//1\n", + "new_state_vector_each_year[3] = average_new_customers * new_customer_state_dist[4] // 1\n", + "new_state_vector_each_year[4] = average_new_customers * new_customer_state_dist[5] // 1\n", + "new_state_vector_each_year[5] = average_new_customers * new_customer_state_dist[6] // 1\n", "\n", "new_state_vector_each_year" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, + "execution_count": 77, + "metadata": {}, "outputs": [], "source": [ "# build the reward vector\n", @@ -1871,67 +1905,144 @@ "\n", "for i in range(6):\n", " reward_vector[i] = avg_purchase_amt - 25\n", - " \n", + "\n", "for i in range(6, 12):\n", " reward_vector[i] = - 25\n", - " \n", + "\n", "for i in range(12, 18):\n", " reward_vector[i] = 0" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 159.14211651],\n", + " [ 154.022231 ],\n", + " [ 133.06375833],\n", + " [ 113.8820981 ],\n", + " [ 108.77766952],\n", + " [ 84.30834718],\n", + " [ 2.91701705],\n", + " [ 3.1785518 ],\n", + " [ -12.15984091],\n", + " [ -15.7199454 ],\n", + " [ -19.61056092],\n", + " [ -30.12109561],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "I_18 = np.identity(18)\n", + "d = .2 # discount rate\n", + "CLV = (np.linalg.inv(I_18 - (1 + d) ** (-1) * RFM_transition_matrix)).dot(reward_vector)\n", "\n", - "CLV = (np.linalg.inv(I_18 - (1+d)**(-1)*RFM_transition_matrix)).dot(reward_vector)\n", - "\n", - "CLV.reshape(len(CLV),1)" + "CLV.reshape(len(CLV), 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[148713.2146689537,\n", + " 245277.07984708826,\n", + " 274705.03597826493,\n", + " 266706.73232970835,\n", + " 251447.07983963928,\n", + " 237185.76537106108,\n", + " 225628.47407888254,\n", + " 216672.59572615713,\n", + " 209825.78460564278,\n", + " 204600.18899193767]" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# without policy\n", "\n", "revenue_no_policy = []\n", "\n", - "total_reward = reward_vector*(((1+d)**-1)*RFM_transition_matrix).dot(starting_state)+new_state_vector_each_year\n", + "total_reward = reward_vector * (((1 + d) ** -1) * RFM_transition_matrix).dot(\n", + " starting_state) + new_state_vector_each_year\n", "new_state = starting_state.copy()\n", "\n", "revenue_no_policy.append(np.sum(total_reward))\n", "\n", "for i in range(9):\n", - " new_state = (((1+d)**-1)*RFM_transition_matrix).dot(new_state)+new_state_vector_each_year\n", - " reward_this_year = reward_vector*new_state\n", - " \n", + " new_state = (((1 + d) ** -1) * RFM_transition_matrix).dot(new_state) + new_state_vector_each_year\n", + " reward_this_year = reward_vector * new_state\n", + "\n", " revenue_no_policy.append(np.sum(reward_this_year))\n", - " \n", + "\n", " total_reward += reward_this_year\n", - " \n", + "\n", "revenue_no_policy" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2280761.9514373359" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(revenue_no_policy)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2016\t148713.214669\n", + "2017\t245277.079847\n", + "2018\t274705.035978\n", + "2019\t266706.73233\n", + "2020\t251447.07984\n", + "2021\t237185.765371\n", + "2022\t225628.474079\n", + "2023\t216672.595726\n", + "2024\t209825.784606\n", + "2025\t204600.188992\n" + ] + } + ], "source": [ "for year, rev in enumerate(revenue_no_policy, 2016):\n", " print(str(year) + \"\\t\" + str(rev))" @@ -1939,11 +2050,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2016\t334786.057137\n", + "2017\t431349.922316\n", + "2018\t418106.563984\n", + "2019\t383602.358018\n", + "2020\t349896.26675\n", + "2021\t322041.043505\n", + "2022\t300205.533857\n", + "2023\t283390.943334\n", + "2024\t270503.207027\n", + "2025\t260618.696498\n" + ] + } + ], "source": [ "# with policy\n", "\n", @@ -1954,34 +2082,55 @@ "# set all the negative CLVs to zero\n", "reward_vector_with_policy[8:] = 0\n", "\n", - "total_reward = reward_vector_with_policy*(((1+d)**-1)*RFM_transition_matrix).dot(starting_state)+new_state_vector_each_year\n", + "total_reward = reward_vector_with_policy * (((1 + d) ** -1) * RFM_transition_matrix).dot(\n", + " starting_state) + new_state_vector_each_year\n", "new_state = starting_state.copy()\n", "\n", "revenue_with_policy.append(np.sum(total_reward))\n", "\n", "for i in range(9):\n", - " new_state = (((1+d)**-1)*RFM_transition_matrix).dot(new_state)+new_state_vector_each_year\n", - " reward_this_year = reward_vector_with_policy*new_state\n", - " \n", + " new_state = (((1 + d) ** -1) * RFM_transition_matrix).dot(new_state) + new_state_vector_each_year\n", + " reward_this_year = reward_vector_with_policy * new_state\n", + "\n", " revenue_with_policy.append(np.sum(reward_this_year))\n", - " \n", + "\n", " total_reward += reward_this_year\n", - " \n", + "\n", "money = []\n", - " \n", + "\n", "for year, rev in enumerate(revenue_with_policy, 2016):\n", " print(str(year) + \"\\t\" + str(rev))\n", - " money.append(str(year) + \"\\t\" + str(rev))\n", - " \n" + " money.append(str(year) + \"\\t\" + str(rev))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 91, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 91, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmgAAAFNCAYAAAC0ZpNRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHaxJREFUeJzt3XuYZVV95vHvKwgoIBdpEbnYqKhBEyHTEhTNkBCVBDPA\nxBDwhs+o6KhEc3PAOMYkgyGJwTjjiEE0YiQgNxGUeEOU4KjYIMpNAhEQkKZbFAE1SMNv/tir4FB0\nVxdNnTqru76f56nn7L325fzOPk3Vy9qXlapCkiRJ/XjEpAuQJEnSAxnQJEmSOmNAkyRJ6owBTZIk\nqTMGNEmSpM4Y0CRJkjpjQJPWY0kuT7L3pOuYpCQHJrkhyZ1Jdp9gHU9PsnJS7z9Sx8lJ3j7pOiTN\nzIAmraOSXJfkN6a1vSrJBVPzVfWMqvrSGvazOEkl2XBMpU7au4E3VdVmVfXNqcYkO7XQNvVTSX4y\nMv/8mXaa5PVJvjBXRSZZluSn7b2XJTk+yaPnav+S1i0GNElj1UHweyJw+fTGqvpeC22bVdVmrflZ\nI23/Or9lAvDCVssewPOBtz7UHXRwvCXNAQOatB4b7WVLskeSpUluT3JLkmPaaue319ta781zkjwi\nyduTXJ9keZKPJtliZL+vbMt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7as7VuczHOtN2md5MUBV/Qi4OcmBrZZHJHnWGj6rpI7YgyZpTlXV\nhUlOYji1B3Ds1OnDdsH6pcCngWOAs9v8hcDVa/l+/5HkXcBS4CbgihlWfxPwwSSvY+hlex3wwxnW\nf0f7HCtajVO9Vu9JsjNDT9XnWg/blcBOwCXttOJyhnC6D/CHSe5mCKmvmOGz3Av8LTzortN/YhXH\nqh3rTwDfBm5py6YcDByb5J0M16d9DFjd6VVJnclwM5QkSZJ64SlOSZKkzhjQJEmSOmNAkyRJ6owB\nTZIkqTMGNEmSpM4Y0CRJkjpjQJMkSeqMAU2SJKkz/x/ghd95LceEsAAAAABJRU5ErkJggg==\n", + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ - "fig, axs = plt.subplots(1,1, figsize = (10,5))\n", + "fig, axs = plt.subplots(1, 1, figsize=(10, 5))\n", "\n", "total_purchases = boolean_matrix_restricted.apply(lambda x: sum(x), axis=1)\n", "\n", @@ -1994,38 +2143,116 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3354500.5924256132" + ] + }, + "execution_count": 92, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(revenue_with_policy)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 93, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [ 46.03911622],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [-25. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 93, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "reward_vector.reshape(18, 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 94, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 159.14211651],\n", + " [ 154.022231 ],\n", + " [ 133.06375833],\n", + " [ 113.8820981 ],\n", + " [ 108.77766952],\n", + " [ 84.30834718],\n", + " [ 2.91701705],\n", + " [ 3.1785518 ],\n", + " [ -12.15984091],\n", + " [ -15.7199454 ],\n", + " [ -19.61056092],\n", + " [ -30.12109561],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ],\n", + " [ 0. ]])" + ] + }, + "execution_count": 94, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "CLV.reshape(18,1)" + "CLV.reshape(18, 1)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "2144.0" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "np.sum(new_state_vector_each_year)" ] @@ -2033,9 +2260,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] }