Skip to content

Instantly share code, notes, and snippets.

@Saurabh7
Created April 27, 2017 17:00
Show Gist options
  • Save Saurabh7/66158dd47f48e9bbfdb0607717c83449 to your computer and use it in GitHub Desktop.
Save Saurabh7/66158dd47f48e9bbfdb0607717c83449 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### V0.2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Additions:\n",
"#### - Basic post processing to remove similar paths.\n",
" - Does matching based on spend_prop, metric, num of dimensions and drops similar ones.\n",
" - Contains commented out preprocessing approach which didnt work out very well.\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import plotly.plotly as py\n",
"import plotly as py\n",
"py.offline.init_notebook_mode(connected=True)\n",
"import plotly.graph_objs as go"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import IPython.core.display as di\n",
"\n",
"# This line will hide code by default when the notebook is exported as HTML\n",
"di.display_html('<script>jQuery(function() {if (jQuery(\"body.notebook_app\").length == 0) { jQuery(\".input_area\").toggle(); jQuery(\".prompt\").toggle();}});</script>', raw=True)\n",
"\n",
"# This line will add a button to toggle visibility of code blocks, for use with the HTML export version\n",
"di.display_html('''<button onclick=\"jQuery('.input_area').toggle(); jQuery('.prompt').toggle();\">Toggle code</button>''', raw=True)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.display import display, HTML\n",
"from itertools import combinations, product"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from jarvis.brain.utility.data_preparation import (get_metrics_single_date, get_metrics_date_range, extract_custom_tags)\n",
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn import tree\n",
"import pydotplus\n",
"import operator\n",
"global_metrics = ['ga_cpt', 'fb_spend', 'ga_transactions', 'ga_revenue']\n",
"goal_metric = 'ga_cpt'\n",
"aggregations = {'fb_spend': pd.np.sum,\n",
" 'ga_transactions': pd.np.sum,\n",
" 'ga_revenue': pd.np.sum,\n",
" }"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from jarvis.brain.insights.paths.paths import PathProcessor"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"start = '2017-04-13'\n",
"end = '2017-04-23'\n",
"ad_account = 261\n",
"num_levels = 4\n",
"path_model = PathProcessor(ad_account, start, end, global_metrics, num_levels, aggregations)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Date range: 2017-04-13 to 2017-04-23\n"
]
}
],
"source": [
"print('Date range:', start, 'to', end)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"path_model.get_data()\n",
"df = path_model.df"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df_g = df"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"excluded_tags = ['Campaigns', 'ad_id', 'Adsets', 'start_date', 'Locations', '_id', 'Ads', 'internal_id', 'Publisher Platforms', 'Sale', 'Product - algo',\n",
" 'end_date', 'Active Ads Count in Adset', 'Active Adsets Count in Campaign', 'Labels', 'audience type', 'audience category', 'Product Set',\n",
" 'Prominent Text', 'Dominant Color', 'DominantColor', 'ProminentText', 'NumberofFaces', 'Number of Faces', 'name', 'Carousel Count' , 'Ad Format']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Excluded Dimensions"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Facebook Positions\n"
]
}
],
"source": [
"all_tags = path_model.clean_tags(df, excluded_tags, global_metrics)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Dimensions Looked at"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['Daily Report',\n",
" 'Custom Audiences',\n",
" 'Audience Types',\n",
" 'Campaign Objective',\n",
" 'AdWyZe',\n",
" 'Lookalike Types',\n",
" 'misc',\n",
" 'Billing Event',\n",
" 'Age Range',\n",
" 'Optimization Goal',\n",
" 'Ad Type',\n",
" 'Landing Pages',\n",
" 'Image',\n",
" 'Interests',\n",
" 'CA Daily Report',\n",
" 'FabAlley',\n",
" 'Audience Strategy']"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"path_model.all_tags"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df_org = df.copy()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = df_org#[df_org['App Type'] == 'Web']"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"overall_cpt = df.fb_spend.sum() / df.ga_transactions.sum()"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df_global = df.copy()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"total_spend = df_global.fb_spend.sum()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"path_model.score_tags()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# path_model.score_df.sort_values(by='score')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"path_model.cluster_tags()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"global_tag_list = path_model.tag_list"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# import itertools\n",
"# comb = itertools.combinations(global_tag_list[0], 2)\n",
"# level_list = []\n",
"# for level in range(num_levels):\n",
"# temp_list = []\n",
"# excluded = []\n",
"# comb = itertools.combinations(global_tag_list[level], 2)\n",
"# l = list(comb)\n",
"# for c in l:\n",
"# temp = df.groupby(list(c)).agg(aggregations)\n",
"# num_unique_0 = len(set(temp.index.get_level_values(0).tolist()))\n",
"# num_unique_1 = len(set(temp.index.get_level_values(1).tolist()))\n",
"# if num_unique_0 != num_unique_1:\n",
"# add_list = [val for val in list(c) if val not in excluded]\n",
"# temp_list.extend(add_list)\n",
"# else:\n",
"# if list(c)[0] not in excluded:\n",
"# excluded.append(list(c)[1])\n",
"# temp_list.append(list(c)[0])\n",
"# elif list(c)[1] not in excluded:\n",
"# excluded.append(list(c)[0])\n",
"# temp_list.append(list(c)[1])\n",
"# level_list.append(list(set(temp_list)))\n",
"# # global_tag_list = level_list"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# for level in range(num_levels):\n",
"# print('Level {0}:'.format(level + 1) , global_tag_list[level])"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# global_tag_list = ['Audience Strategy', 'city name', ['custom ad theme', 'Custom Audiences', 'Image', 'Audience Types']]"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"overall = df_global['fb_spend'].sum() / df_global['ga_transactions'].sum()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df_global['ga_cpt'] = df_global['fb_spend'] / df_global['ga_transactions']\n",
"df_global.replace([pd.np.inf, -pd.np.inf, float('inf')], 0, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"overall_dev = df_global.ga_cpt.std()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"P = pd.np.percentile(df_global.fb_spend, [10, 100])"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df_global_true = df_global.copy()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df_global = df_global#[(df_global.fb_spend >= P[0]) & (df_global.fb_spend <= P[1])]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df_global = df_global[df_global.ga_cpt > 0]"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def calculate_global_impacts_good(df_new, filter_df, df, good=True):\n",
" total_transactions = df.ga_transactions.sum()\n",
" total_spend = df.fb_spend.sum()\n",
" total_cpt = total_spend / total_transactions\n",
" \n",
" other_spend = filter_df.fb_spend.sum()\n",
" other_transactions = filter_df.ga_transactions.sum()\n",
" other_cpt = other_spend / other_transactions#filter_df.ga_cpt.mean()\n",
" \n",
" spend = df_new.fb_spend.sum()\n",
" transactions = df_new.ga_transactions.sum()\n",
" cpt = spend / transactions\n",
" \n",
" if good:\n",
" new_transactions = ((other_spend*0.9) / other_cpt) + ((0.1*other_spend + spend) / cpt ) \n",
" proj_transactions = new_transactions\n",
" proj_total_transactions = total_transactions - other_transactions - transactions + new_transactions\n",
"\n",
" new_local_cpt = other_spend + spend / proj_transactions\n",
" new_total_cpt = total_spend / proj_total_transactions\n",
" return new_local_cpt, new_total_cpt\n",
"\n",
" else: \n",
" new_transactions = ((other_spend + 0.1*spend) / other_cpt) + ((0.9*spend) / cpt ) \n",
" proj_transactions = new_transactions\n",
" proj_total_transactions = total_transactions - other_transactions - transactions + new_transactions\n",
"\n",
" new_local_cpt = other_spend + spend / proj_transactions\n",
" new_total_cpt = total_spend / proj_total_transactions\n",
" return new_local_cpt, new_total_cpt"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def check_redundant_paths(new_df, new_tag_value):\n",
" redundant = []\n",
" value = new_tag_value[-1]\n",
" new_df = new_df[np.in1d(new_df.index.get_level_values(-1), [value])]\n",
" size = len(new_df.index.names)\n",
" if size == 1:\n",
" return redundant\n",
" \n",
" for idx in range(0, size-1):\n",
" filtered_df = new_df[np.in1d(new_df.index.get_level_values(idx), ['None'], invert=True)]\n",
" \n",
" if len(filtered_df.iloc[filtered_df.index.get_level_values(idx) == new_tag_value[idx]]) == 1:\n",
" redundant = [i for i in range(0,size-1) if i != idx]\n",
" return redundant\n",
"\n",
" num_unique = len(set(filtered_df.index.get_level_values(idx).tolist()))\n",
"\n",
" if num_unique <= 1:\n",
" redundant.append(idx)\n",
"\n",
" return redundant"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def process_paths(df, tag_list_obj):\n",
" processed_feedbacks = []\n",
" def recurse_paths(tag_list, tag_list_old, tag_values_old):\n",
" if len(tag_list):\n",
" tag_level = tag_list.pop(0)\n",
"\n",
" tags = []\n",
" if isinstance(tag_level, list):\n",
" tags = tags + tag_level\n",
" else:\n",
" tags = tags + [tag_level]\n",
" \n",
" if len(tag_list_old):\n",
" old = df.groupby(tag_list_old).agg(aggregations)\n",
" old['ga_cpt'] = old['fb_spend'] / old['ga_transactions']\n",
" old_cpt = old.loc[tag_values_old]['ga_cpt']\n",
" old_spend = old.loc[tag_values_old]['fb_spend']\n",
" else:\n",
" old = df\n",
" old_cpt = old.fb_spend.sum() / old.ga_transactions.sum()\n",
" old_spend = old.fb_spend.sum()\n",
"\n",
" premature = True\n",
" for tag in tags:\n",
" new_tag_list = tag_list_old + [tag]\n",
"\n",
" new = df.groupby(new_tag_list).agg(aggregations)\n",
" new['ga_cpt'] = new['fb_spend'] / new['ga_transactions']\n",
" prop = new['fb_spend'] / old_spend\n",
" \n",
" if pd.np.max(prop) > 0.95:\n",
" continue\n",
" \n",
" tag_values = set([val[-1] if isinstance(val, tuple) else val for val in new.index.values.tolist()] )\n",
"\n",
" if (tag_values == ['None']):\n",
" continue\n",
" \n",
" for value in tag_values:\n",
" filter_df = new[np.in1d(new.index.get_level_values(-1), [t for t in tag_values if t not in ['None', value]])]\n",
" #old_spend = filter_df.fb_spend.sum()\n",
" try:\n",
" other_cpt = filter_df.fb_spend.sum() / filter_df.ga_transactions.sum()\n",
" except ZeroDivisionError:\n",
" continue\n",
" if value == 'None':\n",
" continue\n",
" new_tag_value = tag_values_old + (value,)\n",
" try:\n",
" new.loc[new_tag_value]\n",
" except:\n",
" continue\n",
" value_df = new.loc[new_tag_value]\n",
" new_cpt = value_df.fb_spend / value_df.ga_transactions\n",
" new_spend = value_df.fb_spend\n",
"\n",
" redundant_path = check_redundant_paths(new, new_tag_value)\n",
" \n",
" if len(redundant_path):\n",
" filtered_tag_list = [new_tag_list[idx] for idx, element in enumerate(new_tag_list) if idx not in redundant_path]\n",
" filtered_tag_value = tuple([new_tag_value[idx] for idx, element in enumerate(new_tag_value) if idx not in redundant_path])\n",
" recurse_paths(tag_list[:], filtered_tag_list[:], filtered_tag_value[:])\n",
" continue\n",
" \n",
" bad_condition = ((new_cpt - old_cpt) / old_cpt ) > 0.1\n",
" good_condition = ((new_cpt - old_cpt) / old_cpt )< -0.1\n",
" spend_prop = value_df.fb_spend*100 / df_global.fb_spend.sum()\n",
" \n",
" single_df = df.groupby(new_tag_list[-1]).agg(aggregations).loc[value]\n",
" single_cpt = single_df.fb_spend.sum() / single_df.ga_transactions.sum()\n",
" if len(new_tag_list) > 1:\n",
" bad_condition_2 = 1#((new_cpt - single_cpt) / single_cpt) > 0.1\n",
" good_condition_2 = 1#((new_cpt - single_cpt) / single_cpt) < -0.1\n",
" else:\n",
" bad_condition_2 = 1\n",
" good_condition_2 = 1\n",
" if bad_condition and bad_condition_2:\n",
" present = check_present(bad, new_tag_value, new_tag_list)\n",
" if present and new_tag_value[-1] not in processed_feedbacks:\n",
" processed_feedbacks.append(new_tag_value[-1])\n",
"# print([[new_tag_list[-1]]], (new_tag_value[-1],))\n",
" recurse_paths(tag_list[:], [new_tag_list[-1]], (new_tag_value[-1],))\n",
" imp_factor = calculate_global_impacts_good(new.loc[tag_values_old], filter_df, df_global, good=False)\n",
"\n",
" if spend_prop > 0.01:\n",
" bad[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
" 'spend_prop':spend_prop,\n",
" 'imp_factor': abs(imp_factor[1] - overall_cpt)*abs(new_cpt - overall_cpt),\n",
" 'other_cpt': other_cpt,\n",
" 'Projected % cpt change': abs(imp_factor[1] - overall_cpt)*100/(overall_cpt),\n",
" 'tag_list': new_tag_list}\n",
"\n",
" if good_condition and good_condition_2:\n",
" present = check_present(good, new_tag_value, new_tag_list)\n",
" if present and new_tag_value[-1] not in processed_feedbacks:\n",
" processed_feedbacks.append(new_tag_value[-1])\n",
"# print([[new_tag_list[-1]]], (new_tag_value[-1],))\n",
" recurse_paths(tag_list[:], [new_tag_list[-1]], (new_tag_value[-1],))\n",
"\n",
" imp_factor = calculate_global_impacts_good(new.loc[tag_values_old], filter_df, df_global, good=True)\n",
" \n",
" if spend_prop > 0.01:\n",
" good[new_tag_value] = {'cpt': value_df.fb_spend / value_df.ga_transactions,\n",
" 'spend_prop': spend_prop,\n",
" 'imp_factor': abs(imp_factor[1] - overall_cpt)*abs(new_cpt - overall_cpt),\n",
" 'other_cpt': other_cpt,\n",
" 'Projected % cpt change': abs(imp_factor[1] - overall_cpt)*100/(overall_cpt),\n",
" 'tag_list': new_tag_list} \n",
" \n",
" premature = False\n",
" recurse_paths(tag_list[:], new_tag_list[:], new_tag_value[:])\n",
" \n",
" if premature and len(tag_list):\n",
" recurse_paths(tag_list[:], tag_list_old, tag_values_old)\n",
" \n",
" recurse_paths(tag_list_obj, [], ())"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def check_present(storage_dict, bad_tag_value, bad_tag_list):\n",
" bad_value = bad_tag_value[-1]\n",
" bad_tag = bad_tag_list[-1]\n",
" \n",
" for key, value in storage_dict.items():\n",
" if key[-1] == bad_value:\n",
" return True\n",
" return False"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"bad = {}\n",
"good = {}\n",
"num=25"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [],
"source": [
"tag_list = global_tag_list\n",
"process_paths(df_global, tag_list[:])\n",
"bad_raw = bad.copy()\n",
"good_raw = good.copy()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def get_filtered_paths(paths, rev=True):\n",
" filtered_paths = {key: value for (key, value) in paths.items() if value['spend_prop'] > 1}\n",
"\n",
" processed_paths = {}\n",
" for key, value in filtered_paths.items():\n",
" l = list(key)\n",
" none_list = ['-']*len(tag_list)\n",
" none_list[:len(l)] = l\n",
" if len(none_list) > 1:\n",
" new_key = tuple(none_list)\n",
" else:\n",
" new_key = none_list[0]\n",
"\n",
" if tuple(value['tag_list']) in processed_paths:\n",
" processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
" else:\n",
" processed_paths[tuple(value['tag_list'])] = {}\n",
" processed_paths[tuple(value['tag_list'])][new_key] = {metric: val for metric, val in value.items() if metric != 'tag_list'}\n",
"\n",
" impact_values = {}\n",
" for key, value in processed_paths.items():\n",
" out_df = pd.DataFrame().from_dict(value, orient='index')\n",
" impact = out_df.imp_factor.abs().max()\n",
" impact_values[key] = impact\n",
"\n",
" impacts = sorted(impact_values.items(), key=operator.itemgetter(1), reverse=rev)\n",
" \n",
" return processed_paths, impacts"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bad_new, bad_impacts = get_filtered_paths(bad_raw, True)\n",
"bad_impacts_list = [value[0] for value in bad_impacts]\n",
"plot_bad = {}\n",
"\n",
"for key in bad_impacts_list[0:num]:\n",
" if key in list(bad_new.keys()):\n",
" value = bad_new[key]\n",
" b = pd.DataFrame().from_dict(value, orient='index')\n",
" none_list = ['-']*len(tag_list)\n",
" l = list(key)\n",
" none_list[:len(l)] = l\n",
" max_imp_val = max(value, key=lambda i: value[i]['imp_factor'])\n",
" max_imp = value[max_imp_val]['imp_factor']\n",
" for tag_values, measures in value.items():\n",
" if measures['imp_factor'] > 0.75*max_imp:\n",
" new_key = [val + ' : ' + tag_values[i] for i, val in enumerate(list(none_list))]\n",
" plot_bad[tuple(new_key)] = measures\n",
" if 1:\n",
" b.index = b.index.set_names(none_list)\n",
" if 1:\n",
" b = b[b['imp_factor'] > 0.75*b.imp_factor.max()]\n",
" #display(b)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"good_new, good_impacts = get_filtered_paths(good_raw, True)\n",
"good_impacts_list = [value[0] for value in good_impacts]\n",
"plot_good = {}\n",
"\n",
"for key in good_impacts_list[:num]:\n",
" if key in list(good_new.keys()):\n",
" value = good_new[key]\n",
" b = pd.DataFrame().from_dict(value, orient='index')\n",
" none_list = ['-']*len(tag_list)\n",
" l = list(key)\n",
" none_list[:len(l)] = l\n",
" max_imp_val = max(value, key=lambda i: value[i]['imp_factor'])\n",
" max_imp = value[max_imp_val]['imp_factor']\n",
" for tag_values, measures in value.items():\n",
" if measures['imp_factor'] > 0.75*max_imp:\n",
" new_key = [val + ' : ' + tag_values[i] for i, val in enumerate(list(none_list))]\n",
" plot_good[tuple(new_key)] = measures\n",
" b.index = b.index.set_names(none_list)\n",
" if 1:\n",
" b = b[b['imp_factor'] > 0.75*b.imp_factor.max()]\n",
" #display(b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Evaluation"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"good_df_multi = pd.DataFrame().from_dict(plot_good, orient='index')\n",
"bad_df_multi = pd.DataFrame().from_dict(plot_bad, orient='index')"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<script>requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min']},});if(!window.Plotly) {{require(['plotly'],function(plotly) {window.Plotly=plotly;});}}</script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%matplotlib inline\n",
"import pylab as plt\n",
"from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot\n",
"import plotly.graph_objs as go\n",
"init_notebook_mode(connected=True)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"good_df = good_df_multi.reset_index()\n",
"bad_df = bad_df_multi.reset_index()"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def find_similar(temp_df):\n",
" to_drop = []\n",
" for i in range(len(temp_df)):\n",
" if i in to_drop:\n",
" continue\n",
" prop = temp_df.iloc[i]['spend_prop']\n",
" cpt = temp_df.iloc[i]['cpt']\n",
" similar_df = temp_df[(temp_df['spend_prop'] == prop) & (temp_df['cpt'] == cpt)]\n",
" if len(similar_df) > 1:\n",
" num_similar = 0\n",
" for level in range(num_levels):\n",
" if similar_df['level_{0}'.format(level)].nunique() == 1:\n",
" num_similar += 1\n",
" if num_similar > 0:\n",
" to_drop.extend([idx for idx in similar_df.index.tolist() if idx != i])\n",
" \n",
" return to_drop\n",
"\n",
"bad_drop = find_similar(bad_df)\n",
"bad_df.drop(bad_df.index[bad_drop], inplace=True)\n",
"bad_df = bad_df.reset_index()\n",
"bad_df.index = bad_df['imp_factor'].rank(ascending=False)\n",
"bad_df.index.rename('rank', inplace=True)\n",
"bad_df.drop(['index'], inplace=True, axis=1)\n",
"\n",
"good_drop = find_similar(good_df)\n",
"good_df.drop(good_df.index[good_drop], inplace=True)\n",
"good_df = good_df.reset_index()\n",
"good_df.index = good_df['imp_factor'].rank(ascending=False)\n",
"good_df.index.rename('rank', inplace=True)\n",
"good_df.drop(['index'], inplace=True, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/vnd.plotly.v1+json": {
"data": [
{
"marker": {
"size": [
19.13066681065225,
37.464398309414904,
1.0784782610524772,
16.19873983978198,
4.275073781253287,
18.296079623724083,
5.636570340903784,
34.939010621094226,
1.802123377452905,
7.912090846940804,
3.2139609778343305,
4.172721232854791,
5.894733281048609,
1.4638491080489922,
1.241142427042954,
2.977098485827258,
1.4269254782576566,
10.990054926229474,
2.250316982525391
],
"sizemode": "area",
"sizeref": 0.05
},
"mode": "markers",
"text": [
"Ad Type : DPA <br>- : - <br>- : - <br>- : - <br>Spend % : 19.13066681065225 <br>Projected % cpt change: 11.958527584823978",
"AdWyZe : Sale campaigns <br>- : - <br>- : - <br>- : - <br>Spend % : 37.464398309414904 <br>Projected % cpt change: 11.718208997255344",
"AdWyZe : Sale campaigns <br>Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 18-35 <br>Spend % : 1.0784782610524772 <br>Projected % cpt change: 11.591201416726266",
"AdWyZe : Sale campaigns <br>Audience Strategy : Retention <br>- : - <br>- : - <br>Spend % : 16.19873983978198 <br>Projected % cpt change: 12.489831783363037",
"AdWyZe : campaigns <br>Audience Strategy : Prospecting <br>FabAlley : Indya <br>Age Range : 21-44 <br>Spend % : 4.275073781253287 <br>Projected % cpt change: 11.104290178901287",
"Audience Strategy : Prospecting <br>FabAlley : Indya <br>- : - <br>- : - <br>Spend % : 18.296079623724083 <br>Projected % cpt change: 11.454068949205308",
"Audience Strategy : Prospecting <br>FabAlley : Indya <br>Age Range : 21-44 <br>- : - <br>Spend % : 5.636570340903784 <br>Projected % cpt change: 11.58910225473005",
"Billing Event : Impressions <br>Audience Strategy : Retention <br>- : - <br>- : - <br>Spend % : 34.939010621094226 <br>Projected % cpt change: 11.345581401303743",
"FabAlley : Indya <br>Age Range : 20-44 <br>- : - <br>- : - <br>Spend % : 1.802123377452905 <br>Projected % cpt change: 12.138676396461259",
"FabAlley : Indya <br>Audience Types : Lookalike <br>- : - <br>- : - <br>Spend % : 7.912090846940804 <br>Projected % cpt change: 11.541583123465495",
"FabAlley : Indya <br>CA Daily Report : Look-a-like 1% <br>- : - <br>- : - <br>Spend % : 3.2139609778343305 <br>Projected % cpt change: 11.269356467399582",
"FabAlley : Indya <br>Custom Audiences : Lookalike (IN, 1%) - All Purchased <br>- : - <br>- : - <br>Spend % : 4.172721232854791 <br>Projected % cpt change: 11.979534466942594",
"FabAlley : Indya <br>Lookalike Types : 1% <br>- : - <br>- : - <br>Spend % : 5.894733281048609 <br>Projected % cpt change: 11.180192629769342",
"FabAlley : Indya <br>Lookalike Types : 1-2% <br>- : - <br>- : - <br>Spend % : 1.4638491080489922 <br>Projected % cpt change: 11.133469852108524",
"FabAlley : dresses <br>Age Range : 18-35 <br>- : - <br>- : - <br>Spend % : 1.241142427042954 <br>Projected % cpt change: 10.937612175719966",
"FabAlley : dresses <br>Audience Types : Interests <br>- : - <br>- : - <br>Spend % : 2.977098485827258 <br>Projected % cpt change: 11.067323900837831",
"FabAlley : tops <br>Audience Types : Interests <br>- : - <br>- : - <br>Spend % : 1.4269254782576566 <br>Projected % cpt change: 10.111842136214346",
"Landing Pages : www.faballey.com/indya <br>Age Range : 21-44 <br>- : - <br>- : - <br>Spend % : 10.990054926229474 <br>Projected % cpt change: 11.393297735552029",
"misc : AdWyzeCampaigns <br>FabAlley : Indya <br>Audience Types : Open Targeting <br>- : - <br>Spend % : 2.250316982525391 <br>Projected % cpt change: 11.012578032559237"
],
"type": "scatter",
"x": [
2,
13,
9,
1,
14,
19,
4,
17,
5,
11,
6,
3,
7,
10,
8,
15,
16,
12,
18
],
"y": [
806.5632110091744,
1094.290974576271,
1062.0364285714286,
821.0476838235296,
1091.455185185185,
1236.470980392157,
914.2228235294119,
1155.1293045563546,
955.5803846153847,
1080.0054455445545,
963.2495652173913,
871.6286363636364,
1015.8515,
1062.1815789473685,
1006.5347058823529,
1109.2962162162162,
1092.9111111111108,
1082.2507142857144,
1149.042222222222
]
},
{
"marker": {
"size": [
45.98947871305775,
1.8620940834251627,
1.5254830275191684,
4.161277482590221,
1.9476230060623358,
7.248697869934872,
1.3592741060274587,
2.6352968691750336,
2.216362910544993,
3.78251814498469,
1.2563144448083081,
4.3852585927789205,
2.369602683609847,
3.6914417924163883,
4.464131034705063,
11.727619391528746
],
"sizemode": "area",
"sizeref": 0.05
},
"mode": "markers",
"text": [
"Ad Type : Carousel <br>misc : AdWyzeCampaigns <br>- : - <br>- : - <br>Spend % : 45.98947871305775 <br>Projected % cpt change: 11.88214351722326",
"AdWyZe : Sale campaigns <br>Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 21-44 <br>Spend % : 1.8620940834251627 <br>Projected % cpt change: 10.817312411662813",
"AdWyZe : campaigns <br>Audience Strategy : Retention <br>FabAlley : Curve <br>- : - <br>Spend % : 1.5254830275191684 <br>Projected % cpt change: 11.189804182293546",
"Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 21-44 <br>- : - <br>Spend % : 4.161277482590221 <br>Projected % cpt change: 10.904708345997472",
"Audience Strategy : Prospecting <br>FabAlley : tops <br>Age Range : 21-44 <br>- : - <br>Spend % : 1.9476230060623358 <br>Projected % cpt change: 10.943198088162198",
"Audience Strategy : Retention <br>FabAlley : tops <br>- : - <br>- : - <br>Spend % : 7.248697869934872 <br>Projected % cpt change: 11.217559027354913",
"FabAlley : Indya <br>Age Range : 20-30 <br>- : - <br>- : - <br>Spend % : 1.3592741060274587 <br>Projected % cpt change: 10.46810862403409",
"FabAlley : Indya <br>Audience Types : Custom <br>- : - <br>- : - <br>Spend % : 2.6352968691750336 <br>Projected % cpt change: 10.476055591732601",
"FabAlley : Indya <br>CA Daily Report : Intrest <br>- : - <br>- : - <br>Spend % : 2.216362910544993 <br>Projected % cpt change: 10.758553698676558",
"FabAlley : Indya <br>CA Daily Report : WCA <br>- : - <br>- : - <br>Spend % : 3.78251814498469 <br>Projected % cpt change: 10.834453310900297",
"FabAlley : Indya <br>Image : 728f8306f1e7dfd190a06c810aa0d2bf <br>- : - <br>- : - <br>Spend % : 1.2563144448083081 <br>Projected % cpt change: 10.464105247163156",
"FabAlley : dresses <br>Lookalike Types : 1% <br>- : - <br>- : - <br>Spend % : 4.3852585927789205 <br>Projected % cpt change: 10.505338968948942",
"FabAlley : tops <br>Age Range : 21-35 <br>- : - <br>- : - <br>Spend % : 2.369602683609847 <br>Projected % cpt change: 11.159098664466283",
"FabAlley : tops <br>Custom Audiences : Retargeting - 2 days or Retargeting 7 days or Targeting Source Medium <br>- : - <br>- : - <br>Spend % : 3.6914417924163883 <br>Projected % cpt change: 11.102266501849893",
"misc : AdWyzeCampaigns <br>FabAlley : Curve <br>- : - <br>- : - <br>Spend % : 4.464131034705063 <br>Projected % cpt change: 10.937196992928433",
"misc : AdWyzeCampaigns <br>FabAlley : tops <br>- : - <br>- : - <br>Spend % : 11.727619391528746 <br>Projected % cpt change: 10.984203990273983"
],
"type": "scatter",
"x": [
16,
10,
1,
8,
13,
7,
2,
12,
6,
4,
15,
9,
3,
5,
11,
14
],
"y": [
1827.1957060518737,
2139.3233333333333,
3505.1949999999997,
2206.527692307692,
2065.463846153846,
2271.241818181818,
3123.286666666667,
2137.1582352941177,
2546.3358333333335,
2744.6278947368423,
1924.4733333333331,
2159.201785714286,
2722.39,
2544.6150000000002,
2122.2424137931043,
1996.0935802469135
]
},
{
"hoverinfo": "none",
"mode": "line",
"name": "Overall CPT",
"text": [
"Overall CPT"
],
"type": "scatter",
"x": [
2,
13,
9,
1,
14,
19,
4,
17,
5,
11,
6,
3,
7,
10,
8,
15,
16,
12,
18
],
"y": [
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782,
1495.7386653771782
]
}
],
"layout": {
"title": "Performance by Paths, Hover to see information",
"xaxis": {
"title": "Rank of sample"
},
"yaxis": {
"title": "CPT"
}
}
},
"text/html": [
"<div id=\"4990dddd-3a3c-49e9-8391-47f1b9911fc3\" style=\"height: 525px; width: 100%;\" class=\"plotly-graph-div\"></div><script type=\"text/javascript\">require([\"plotly\"], function(Plotly) { window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL=\"https://plot.ly\";Plotly.newPlot(\"4990dddd-3a3c-49e9-8391-47f1b9911fc3\", [{\"y\": [806.5632110091744, 1094.290974576271, 1062.0364285714286, 821.0476838235296, 1091.455185185185, 1236.470980392157, 914.2228235294119, 1155.1293045563546, 955.5803846153847, 1080.0054455445545, 963.2495652173913, 871.6286363636364, 1015.8515, 1062.1815789473685, 1006.5347058823529, 1109.2962162162162, 1092.9111111111108, 1082.2507142857144, 1149.042222222222], \"text\": [\"Ad Type : DPA <br>- : - <br>- : - <br>- : - <br>Spend % : 19.13066681065225 <br>Projected % cpt change: 11.958527584823978\", \"AdWyZe : Sale campaigns <br>- : - <br>- : - <br>- : - <br>Spend % : 37.464398309414904 <br>Projected % cpt change: 11.718208997255344\", \"AdWyZe : Sale campaigns <br>Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 18-35 <br>Spend % : 1.0784782610524772 <br>Projected % cpt change: 11.591201416726266\", \"AdWyZe : Sale campaigns <br>Audience Strategy : Retention <br>- : - <br>- : - <br>Spend % : 16.19873983978198 <br>Projected % cpt change: 12.489831783363037\", \"AdWyZe : campaigns <br>Audience Strategy : Prospecting <br>FabAlley : Indya <br>Age Range : 21-44 <br>Spend % : 4.275073781253287 <br>Projected % cpt change: 11.104290178901287\", \"Audience Strategy : Prospecting <br>FabAlley : Indya <br>- : - <br>- : - <br>Spend % : 18.296079623724083 <br>Projected % cpt change: 11.454068949205308\", \"Audience Strategy : Prospecting <br>FabAlley : Indya <br>Age Range : 21-44 <br>- : - <br>Spend % : 5.636570340903784 <br>Projected % cpt change: 11.58910225473005\", \"Billing Event : Impressions <br>Audience Strategy : Retention <br>- : - <br>- : - <br>Spend % : 34.939010621094226 <br>Projected % cpt change: 11.345581401303743\", \"FabAlley : Indya <br>Age Range : 20-44 <br>- : - <br>- : - <br>Spend % : 1.802123377452905 <br>Projected % cpt change: 12.138676396461259\", \"FabAlley : Indya <br>Audience Types : Lookalike <br>- : - <br>- : - <br>Spend % : 7.912090846940804 <br>Projected % cpt change: 11.541583123465495\", \"FabAlley : Indya <br>CA Daily Report : Look-a-like 1% <br>- : - <br>- : - <br>Spend % : 3.2139609778343305 <br>Projected % cpt change: 11.269356467399582\", \"FabAlley : Indya <br>Custom Audiences : Lookalike (IN, 1%) - All Purchased <br>- : - <br>- : - <br>Spend % : 4.172721232854791 <br>Projected % cpt change: 11.979534466942594\", \"FabAlley : Indya <br>Lookalike Types : 1% <br>- : - <br>- : - <br>Spend % : 5.894733281048609 <br>Projected % cpt change: 11.180192629769342\", \"FabAlley : Indya <br>Lookalike Types : 1-2% <br>- : - <br>- : - <br>Spend % : 1.4638491080489922 <br>Projected % cpt change: 11.133469852108524\", \"FabAlley : dresses <br>Age Range : 18-35 <br>- : - <br>- : - <br>Spend % : 1.241142427042954 <br>Projected % cpt change: 10.937612175719966\", \"FabAlley : dresses <br>Audience Types : Interests <br>- : - <br>- : - <br>Spend % : 2.977098485827258 <br>Projected % cpt change: 11.067323900837831\", \"FabAlley : tops <br>Audience Types : Interests <br>- : - <br>- : - <br>Spend % : 1.4269254782576566 <br>Projected % cpt change: 10.111842136214346\", \"Landing Pages : www.faballey.com/indya <br>Age Range : 21-44 <br>- : - <br>- : - <br>Spend % : 10.990054926229474 <br>Projected % cpt change: 11.393297735552029\", \"misc : AdWyzeCampaigns <br>FabAlley : Indya <br>Audience Types : Open Targeting <br>- : - <br>Spend % : 2.250316982525391 <br>Projected % cpt change: 11.012578032559237\"], \"marker\": {\"sizemode\": \"area\", \"size\": [19.13066681065225, 37.464398309414904, 1.0784782610524772, 16.19873983978198, 4.275073781253287, 18.296079623724083, 5.636570340903784, 34.939010621094226, 1.802123377452905, 7.912090846940804, 3.2139609778343305, 4.172721232854791, 5.894733281048609, 1.4638491080489922, 1.241142427042954, 2.977098485827258, 1.4269254782576566, 10.990054926229474, 2.250316982525391], \"sizeref\": 0.05}, \"mode\": \"markers\", \"type\": \"scatter\", \"x\": [2.0, 13.0, 9.0, 1.0, 14.0, 19.0, 4.0, 17.0, 5.0, 11.0, 6.0, 3.0, 7.0, 10.0, 8.0, 15.0, 16.0, 12.0, 18.0]}, {\"y\": [1827.1957060518737, 2139.3233333333333, 3505.1949999999997, 2206.527692307692, 2065.463846153846, 2271.241818181818, 3123.286666666667, 2137.1582352941177, 2546.3358333333335, 2744.6278947368423, 1924.4733333333331, 2159.201785714286, 2722.39, 2544.6150000000002, 2122.2424137931043, 1996.0935802469135], \"text\": [\"Ad Type : Carousel <br>misc : AdWyzeCampaigns <br>- : - <br>- : - <br>Spend % : 45.98947871305775 <br>Projected % cpt change: 11.88214351722326\", \"AdWyZe : Sale campaigns <br>Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 21-44 <br>Spend % : 1.8620940834251627 <br>Projected % cpt change: 10.817312411662813\", \"AdWyZe : campaigns <br>Audience Strategy : Retention <br>FabAlley : Curve <br>- : - <br>Spend % : 1.5254830275191684 <br>Projected % cpt change: 11.189804182293546\", \"Audience Strategy : Prospecting <br>FabAlley : dresses <br>Age Range : 21-44 <br>- : - <br>Spend % : 4.161277482590221 <br>Projected % cpt change: 10.904708345997472\", \"Audience Strategy : Prospecting <br>FabAlley : tops <br>Age Range : 21-44 <br>- : - <br>Spend % : 1.9476230060623358 <br>Projected % cpt change: 10.943198088162198\", \"Audience Strategy : Retention <br>FabAlley : tops <br>- : - <br>- : - <br>Spend % : 7.248697869934872 <br>Projected % cpt change: 11.217559027354913\", \"FabAlley : Indya <br>Age Range : 20-30 <br>- : - <br>- : - <br>Spend % : 1.3592741060274587 <br>Projected % cpt change: 10.46810862403409\", \"FabAlley : Indya <br>Audience Types : Custom <br>- : - <br>- : - <br>Spend % : 2.6352968691750336 <br>Projected % cpt change: 10.476055591732601\", \"FabAlley : Indya <br>CA Daily Report : Intrest <br>- : - <br>- : - <br>Spend % : 2.216362910544993 <br>Projected % cpt change: 10.758553698676558\", \"FabAlley : Indya <br>CA Daily Report : WCA <br>- : - <br>- : - <br>Spend % : 3.78251814498469 <br>Projected % cpt change: 10.834453310900297\", \"FabAlley : Indya <br>Image : 728f8306f1e7dfd190a06c810aa0d2bf <br>- : - <br>- : - <br>Spend % : 1.2563144448083081 <br>Projected % cpt change: 10.464105247163156\", \"FabAlley : dresses <br>Lookalike Types : 1% <br>- : - <br>- : - <br>Spend % : 4.3852585927789205 <br>Projected % cpt change: 10.505338968948942\", \"FabAlley : tops <br>Age Range : 21-35 <br>- : - <br>- : - <br>Spend % : 2.369602683609847 <br>Projected % cpt change: 11.159098664466283\", \"FabAlley : tops <br>Custom Audiences : Retargeting - 2 days or Retargeting 7 days or Targeting Source Medium <br>- : - <br>- : - <br>Spend % : 3.6914417924163883 <br>Projected % cpt change: 11.102266501849893\", \"misc : AdWyzeCampaigns <br>FabAlley : Curve <br>- : - <br>- : - <br>Spend % : 4.464131034705063 <br>Projected % cpt change: 10.937196992928433\", \"misc : AdWyzeCampaigns <br>FabAlley : tops <br>- : - <br>- : - <br>Spend % : 11.727619391528746 <br>Projected % cpt change: 10.984203990273983\"], \"marker\": {\"sizemode\": \"area\", \"size\": [45.98947871305775, 1.8620940834251627, 1.5254830275191684, 4.161277482590221, 1.9476230060623358, 7.248697869934872, 1.3592741060274587, 2.6352968691750336, 2.216362910544993, 3.78251814498469, 1.2563144448083081, 4.3852585927789205, 2.369602683609847, 3.6914417924163883, 4.464131034705063, 11.727619391528746], \"sizeref\": 0.05}, \"mode\": \"markers\", \"type\": \"scatter\", \"x\": [16.0, 10.0, 1.0, 8.0, 13.0, 7.0, 2.0, 12.0, 6.0, 4.0, 15.0, 9.0, 3.0, 5.0, 11.0, 14.0]}, {\"y\": [1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782, 1495.7386653771782], \"text\": [\"Overall CPT\"], \"name\": \"Overall CPT\", \"hoverinfo\": \"none\", \"mode\": \"line\", \"type\": \"scatter\", \"x\": [2.0, 13.0, 9.0, 1.0, 14.0, 19.0, 4.0, 17.0, 5.0, 11.0, 6.0, 3.0, 7.0, 10.0, 8.0, 15.0, 16.0, 12.0, 18.0]}], {\"xaxis\": {\"title\": \"Rank of sample\"}, \"title\": \"Performance by Paths, Hover to see information\", \"yaxis\": {\"title\": \"CPT\"}}, {\"linkText\": \"Export to plot.ly\", \"showLink\": true})});</script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Define a hover-text generating function (returns strings)\n",
"def make_text(X):\n",
" return '{0}\\\n",
" <br>{1}\\\n",
" <br>{2}\\\n",
" <br>{3}\\\n",
" <br>Spend % : {4}\\\n",
" <br>Projected % cpt change: {5}'.format(X['level_0'], X['level_1'], X['level_2'], X['level_3'], X['spend_prop'], X['Projected % cpt change'])\n",
"\n",
"\n",
"\n",
"def build_plotly_trace(df_obj, num, nam):\n",
" df_plotly = df_obj.iloc[0:num].copy()\n",
" df_plotly['idx'] = df_plotly.index\n",
" df_plotly['size'] = df_plotly['spend_prop']\n",
"\n",
" text = []\n",
" for i_trace in range(len(df_plotly)):\n",
" X = df_plotly.iloc[i_trace]\n",
" txt = make_text(X)\n",
" text.append(txt)\n",
" trace = go.Scatter(\n",
" x=df_plotly['idx'].values,\n",
" y=df_plotly['cpt'].values,\n",
" text=text,\n",
" mode='markers',\n",
" marker=dict(\n",
" size=df_plotly['spend_prop'],\n",
" sizeref=0.05,\n",
" sizemode='area',\n",
" )\n",
" )\n",
" return trace\n",
"\n",
"trace1 = build_plotly_trace(good_df, num, 'Better')\n",
"trace2 = build_plotly_trace(bad_df, num, 'Worse')\n",
"trace3 = go.Scatter(\n",
" x=good_df.iloc[0:num].index,\n",
" y=[overall_cpt]*num,\n",
" text=['Overall CPT'],\n",
" hoverinfo='none',\n",
" mode='line',\n",
" name='Overall CPT'\n",
")\n",
"data1 = [trace1, trace2, trace3]\n",
"layout = go.Layout(\n",
" title='Performance by Paths, Hover to see information',\n",
" xaxis=dict(title='Rank of sample'),\n",
" yaxis=dict(title='CPT')\n",
" )\n",
"fig1 = go.Figure(data=data1, layout=layout)\n",
"\n",
"py.offline.iplot(fig1)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# plt.figure(figsize=(10,5))\n",
"# plt.scatter(good_df.iloc[0:num].index, good_df.iloc[0:num]['cpt'], s=good_df.iloc[0:num]['spend_prop']*10, color='b')\n",
"# plt.scatter(bad_df.iloc[0:num].index, bad_df.iloc[0:num]['cpt'], s=bad_df.iloc[0:num]['spend_prop']*10, color='r')\n",
"# plt.axhline(y=overall_cpt, color='g', linestyle='-')\n",
"# plt.xlabel('Rank of sample', fontsize=18)\n",
"# plt.ylabel('CPT', fontsize=18)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"BAD PATHS (RED):\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>level_0</th>\n",
" <th>level_1</th>\n",
" <th>level_2</th>\n",
" <th>level_3</th>\n",
" <th>cpt</th>\n",
" <th>spend_prop</th>\n",
" <th>Projected % cpt change</th>\n",
" <th>imp_factor</th>\n",
" <th>other_cpt</th>\n",
" </tr>\n",
" <tr>\n",
" <th>rank</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1.0</th>\n",
" <td>AdWyZe : campaigns</td>\n",
" <td>Audience Strategy : Retention</td>\n",
" <td>FabAlley : Curve</td>\n",
" <td>- : -</td>\n",
" <td>3505.195000</td>\n",
" <td>1.525483</td>\n",
" <td>11.189804</td>\n",
" <td>336323.164348</td>\n",
" <td>1667.677074</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Age Range : 20-30</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>3123.286667</td>\n",
" <td>1.359274</td>\n",
" <td>10.468109</td>\n",
" <td>254834.220562</td>\n",
" <td>1569.343846</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3.0</th>\n",
" <td>FabAlley : tops</td>\n",
" <td>Age Range : 21-35</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2722.390000</td>\n",
" <td>2.369603</td>\n",
" <td>11.159099</td>\n",
" <td>204741.543791</td>\n",
" <td>1557.182144</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>CA Daily Report : WCA</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2744.627895</td>\n",
" <td>3.782518</td>\n",
" <td>10.834453</td>\n",
" <td>202388.878136</td>\n",
" <td>1515.432581</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5.0</th>\n",
" <td>FabAlley : tops</td>\n",
" <td>Custom Audiences : Retargeting - 2 days or Ret...</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2544.615000</td>\n",
" <td>3.691442</td>\n",
" <td>11.102267</td>\n",
" <td>174177.340566</td>\n",
" <td>1614.134667</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>CA Daily Report : Intrest</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2546.335833</td>\n",
" <td>2.216363</td>\n",
" <td>10.758554</td>\n",
" <td>169061.936058</td>\n",
" <td>1661.176123</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7.0</th>\n",
" <td>Audience Strategy : Retention</td>\n",
" <td>FabAlley : tops</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2271.241818</td>\n",
" <td>7.248698</td>\n",
" <td>11.217559</td>\n",
" <td>130118.081633</td>\n",
" <td>1484.092256</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8.0</th>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>- : -</td>\n",
" <td>2206.527692</td>\n",
" <td>4.161277</td>\n",
" <td>10.904708</td>\n",
" <td>115933.911724</td>\n",
" <td>1577.271710</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9.0</th>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Lookalike Types : 1%</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2159.201786</td>\n",
" <td>4.385259</td>\n",
" <td>10.505339</td>\n",
" <td>104251.563614</td>\n",
" <td>1959.884474</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10.0</th>\n",
" <td>AdWyZe : Sale campaigns</td>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>2139.323333</td>\n",
" <td>1.862094</td>\n",
" <td>10.817312</td>\n",
" <td>104131.178252</td>\n",
" <td>1605.774086</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11.0</th>\n",
" <td>misc : AdWyzeCampaigns</td>\n",
" <td>FabAlley : Curve</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2122.242414</td>\n",
" <td>4.464131</td>\n",
" <td>10.937197</td>\n",
" <td>102490.928744</td>\n",
" <td>1780.336727</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Audience Types : Custom</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>2137.158235</td>\n",
" <td>2.635297</td>\n",
" <td>10.476056</td>\n",
" <td>100506.863695</td>\n",
" <td>1563.157362</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13.0</th>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : tops</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>- : -</td>\n",
" <td>2065.463846</td>\n",
" <td>1.947623</td>\n",
" <td>10.943198</td>\n",
" <td>93253.554807</td>\n",
" <td>1577.271710</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14.0</th>\n",
" <td>misc : AdWyzeCampaigns</td>\n",
" <td>FabAlley : tops</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1996.093580</td>\n",
" <td>11.727619</td>\n",
" <td>10.984204</td>\n",
" <td>82205.803817</td>\n",
" <td>1753.429110</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Image : 728f8306f1e7dfd190a06c810aa0d2bf</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1924.473333</td>\n",
" <td>1.256314</td>\n",
" <td>10.464105</td>\n",
" <td>67103.693022</td>\n",
" <td>1572.478524</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16.0</th>\n",
" <td>Ad Type : Carousel</td>\n",
" <td>misc : AdWyzeCampaigns</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1827.195706</td>\n",
" <td>45.989479</td>\n",
" <td>11.882144</td>\n",
" <td>58908.472646</td>\n",
" <td>1357.350000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" level_0 \\\n",
"rank \n",
"1.0 AdWyZe : campaigns \n",
"2.0 FabAlley : Indya \n",
"3.0 FabAlley : tops \n",
"4.0 FabAlley : Indya \n",
"5.0 FabAlley : tops \n",
"6.0 FabAlley : Indya \n",
"7.0 Audience Strategy : Retention \n",
"8.0 Audience Strategy : Prospecting \n",
"9.0 FabAlley : dresses \n",
"10.0 AdWyZe : Sale campaigns \n",
"11.0 misc : AdWyzeCampaigns \n",
"12.0 FabAlley : Indya \n",
"13.0 Audience Strategy : Prospecting \n",
"14.0 misc : AdWyzeCampaigns \n",
"15.0 FabAlley : Indya \n",
"16.0 Ad Type : Carousel \n",
"\n",
" level_1 level_2 \\\n",
"rank \n",
"1.0 Audience Strategy : Retention FabAlley : Curve \n",
"2.0 Age Range : 20-30 - : - \n",
"3.0 Age Range : 21-35 - : - \n",
"4.0 CA Daily Report : WCA - : - \n",
"5.0 Custom Audiences : Retargeting - 2 days or Ret... - : - \n",
"6.0 CA Daily Report : Intrest - : - \n",
"7.0 FabAlley : tops - : - \n",
"8.0 FabAlley : dresses Age Range : 21-44 \n",
"9.0 Lookalike Types : 1% - : - \n",
"10.0 Audience Strategy : Prospecting FabAlley : dresses \n",
"11.0 FabAlley : Curve - : - \n",
"12.0 Audience Types : Custom - : - \n",
"13.0 FabAlley : tops Age Range : 21-44 \n",
"14.0 FabAlley : tops - : - \n",
"15.0 Image : 728f8306f1e7dfd190a06c810aa0d2bf - : - \n",
"16.0 misc : AdWyzeCampaigns - : - \n",
"\n",
" level_3 cpt spend_prop Projected % cpt change \\\n",
"rank \n",
"1.0 - : - 3505.195000 1.525483 11.189804 \n",
"2.0 - : - 3123.286667 1.359274 10.468109 \n",
"3.0 - : - 2722.390000 2.369603 11.159099 \n",
"4.0 - : - 2744.627895 3.782518 10.834453 \n",
"5.0 - : - 2544.615000 3.691442 11.102267 \n",
"6.0 - : - 2546.335833 2.216363 10.758554 \n",
"7.0 - : - 2271.241818 7.248698 11.217559 \n",
"8.0 - : - 2206.527692 4.161277 10.904708 \n",
"9.0 - : - 2159.201786 4.385259 10.505339 \n",
"10.0 Age Range : 21-44 2139.323333 1.862094 10.817312 \n",
"11.0 - : - 2122.242414 4.464131 10.937197 \n",
"12.0 - : - 2137.158235 2.635297 10.476056 \n",
"13.0 - : - 2065.463846 1.947623 10.943198 \n",
"14.0 - : - 1996.093580 11.727619 10.984204 \n",
"15.0 - : - 1924.473333 1.256314 10.464105 \n",
"16.0 - : - 1827.195706 45.989479 11.882144 \n",
"\n",
" imp_factor other_cpt \n",
"rank \n",
"1.0 336323.164348 1667.677074 \n",
"2.0 254834.220562 1569.343846 \n",
"3.0 204741.543791 1557.182144 \n",
"4.0 202388.878136 1515.432581 \n",
"5.0 174177.340566 1614.134667 \n",
"6.0 169061.936058 1661.176123 \n",
"7.0 130118.081633 1484.092256 \n",
"8.0 115933.911724 1577.271710 \n",
"9.0 104251.563614 1959.884474 \n",
"10.0 104131.178252 1605.774086 \n",
"11.0 102490.928744 1780.336727 \n",
"12.0 100506.863695 1563.157362 \n",
"13.0 93253.554807 1577.271710 \n",
"14.0 82205.803817 1753.429110 \n",
"15.0 67103.693022 1572.478524 \n",
"16.0 58908.472646 1357.350000 "
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print('BAD PATHS (RED):')\n",
"bad_df.sort_index()"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"GOOD PATHS (BLUE):\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>level_0</th>\n",
" <th>level_1</th>\n",
" <th>level_2</th>\n",
" <th>level_3</th>\n",
" <th>cpt</th>\n",
" <th>spend_prop</th>\n",
" <th>Projected % cpt change</th>\n",
" <th>imp_factor</th>\n",
" <th>other_cpt</th>\n",
" </tr>\n",
" <tr>\n",
" <th>rank</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>1.0</th>\n",
" <td>AdWyZe : Sale campaigns</td>\n",
" <td>Audience Strategy : Retention</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>821.047684</td>\n",
" <td>16.198740</td>\n",
" <td>12.489832</td>\n",
" <td>126042.559820</td>\n",
" <td>1550.839913</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2.0</th>\n",
" <td>Ad Type : DPA</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>806.563211</td>\n",
" <td>19.130667</td>\n",
" <td>11.958528</td>\n",
" <td>123271.656326</td>\n",
" <td>1576.959364</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Custom Audiences : Lookalike (IN, 1%) - All Pu...</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>871.628636</td>\n",
" <td>4.172721</td>\n",
" <td>11.979534</td>\n",
" <td>111829.613344</td>\n",
" <td>1736.740098</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4.0</th>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>- : -</td>\n",
" <td>914.222824</td>\n",
" <td>5.636570</td>\n",
" <td>11.589102</td>\n",
" <td>100801.516462</td>\n",
" <td>1577.271710</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Age Range : 20-44</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>955.580385</td>\n",
" <td>1.802123</td>\n",
" <td>12.138676</td>\n",
" <td>98072.691127</td>\n",
" <td>1610.861265</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>CA Daily Report : Look-a-like 1%</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>963.249565</td>\n",
" <td>3.213961</td>\n",
" <td>11.269356</td>\n",
" <td>89756.427698</td>\n",
" <td>1697.017981</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Lookalike Types : 1%</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1015.851500</td>\n",
" <td>5.894733</td>\n",
" <td>11.180193</td>\n",
" <td>80249.833798</td>\n",
" <td>1959.884474</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8.0</th>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Age Range : 18-35</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1006.534706</td>\n",
" <td>1.241142</td>\n",
" <td>10.937612</td>\n",
" <td>80032.835537</td>\n",
" <td>1590.837604</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9.0</th>\n",
" <td>AdWyZe : Sale campaigns</td>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Age Range : 18-35</td>\n",
" <td>1062.036429</td>\n",
" <td>1.078478</td>\n",
" <td>11.591201</td>\n",
" <td>75192.726895</td>\n",
" <td>1709.187388</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Lookalike Types : 1-2%</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1062.181579</td>\n",
" <td>1.463849</td>\n",
" <td>11.133470</td>\n",
" <td>72199.226865</td>\n",
" <td>1557.163256</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11.0</th>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Audience Types : Lookalike</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1080.005446</td>\n",
" <td>7.912091</td>\n",
" <td>11.541583</td>\n",
" <td>71768.824519</td>\n",
" <td>1537.922318</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12.0</th>\n",
" <td>Landing Pages : www.faballey.com/indya</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1082.250714</td>\n",
" <td>10.990055</td>\n",
" <td>11.393298</td>\n",
" <td>70464.118948</td>\n",
" <td>1577.271710</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13.0</th>\n",
" <td>AdWyZe : Sale campaigns</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1094.290975</td>\n",
" <td>37.464398</td>\n",
" <td>11.718209</td>\n",
" <td>70363.255388</td>\n",
" <td>1679.231029</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14.0</th>\n",
" <td>AdWyZe : campaigns</td>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Age Range : 21-44</td>\n",
" <td>1091.455185</td>\n",
" <td>4.275074</td>\n",
" <td>11.104290</td>\n",
" <td>67147.912890</td>\n",
" <td>1605.774086</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15.0</th>\n",
" <td>FabAlley : dresses</td>\n",
" <td>Audience Types : Interests</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1109.296216</td>\n",
" <td>2.977098</td>\n",
" <td>11.067324</td>\n",
" <td>63971.003980</td>\n",
" <td>1632.793038</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16.0</th>\n",
" <td>FabAlley : tops</td>\n",
" <td>Audience Types : Interests</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1092.911111</td>\n",
" <td>1.426925</td>\n",
" <td>10.111842</td>\n",
" <td>60926.351389</td>\n",
" <td>1632.793038</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17.0</th>\n",
" <td>Billing Event : Impressions</td>\n",
" <td>Audience Strategy : Retention</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1155.129305</td>\n",
" <td>34.939011</td>\n",
" <td>11.345581</td>\n",
" <td>57801.492945</td>\n",
" <td>1491.396349</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18.0</th>\n",
" <td>misc : AdWyzeCampaigns</td>\n",
" <td>FabAlley : Indya</td>\n",
" <td>Audience Types : Open Targeting</td>\n",
" <td>- : -</td>\n",
" <td>1149.042222</td>\n",
" <td>2.250317</td>\n",
" <td>11.012578</td>\n",
" <td>57107.625830</td>\n",
" <td>1887.854057</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19.0</th>\n",
" <td>Audience Strategy : Prospecting</td>\n",
" <td>FabAlley : Indya</td>\n",
" <td>- : -</td>\n",
" <td>- : -</td>\n",
" <td>1236.470980</td>\n",
" <td>18.296080</td>\n",
" <td>11.454069</td>\n",
" <td>44418.501528</td>\n",
" <td>1746.014710</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" level_0 \\\n",
"rank \n",
"1.0 AdWyZe : Sale campaigns \n",
"2.0 Ad Type : DPA \n",
"3.0 FabAlley : Indya \n",
"4.0 Audience Strategy : Prospecting \n",
"5.0 FabAlley : Indya \n",
"6.0 FabAlley : Indya \n",
"7.0 FabAlley : Indya \n",
"8.0 FabAlley : dresses \n",
"9.0 AdWyZe : Sale campaigns \n",
"10.0 FabAlley : Indya \n",
"11.0 FabAlley : Indya \n",
"12.0 Landing Pages : www.faballey.com/indya \n",
"13.0 AdWyZe : Sale campaigns \n",
"14.0 AdWyZe : campaigns \n",
"15.0 FabAlley : dresses \n",
"16.0 FabAlley : tops \n",
"17.0 Billing Event : Impressions \n",
"18.0 misc : AdWyzeCampaigns \n",
"19.0 Audience Strategy : Prospecting \n",
"\n",
" level_1 \\\n",
"rank \n",
"1.0 Audience Strategy : Retention \n",
"2.0 - : - \n",
"3.0 Custom Audiences : Lookalike (IN, 1%) - All Pu... \n",
"4.0 FabAlley : Indya \n",
"5.0 Age Range : 20-44 \n",
"6.0 CA Daily Report : Look-a-like 1% \n",
"7.0 Lookalike Types : 1% \n",
"8.0 Age Range : 18-35 \n",
"9.0 Audience Strategy : Prospecting \n",
"10.0 Lookalike Types : 1-2% \n",
"11.0 Audience Types : Lookalike \n",
"12.0 Age Range : 21-44 \n",
"13.0 - : - \n",
"14.0 Audience Strategy : Prospecting \n",
"15.0 Audience Types : Interests \n",
"16.0 Audience Types : Interests \n",
"17.0 Audience Strategy : Retention \n",
"18.0 FabAlley : Indya \n",
"19.0 FabAlley : Indya \n",
"\n",
" level_2 level_3 cpt \\\n",
"rank \n",
"1.0 - : - - : - 821.047684 \n",
"2.0 - : - - : - 806.563211 \n",
"3.0 - : - - : - 871.628636 \n",
"4.0 Age Range : 21-44 - : - 914.222824 \n",
"5.0 - : - - : - 955.580385 \n",
"6.0 - : - - : - 963.249565 \n",
"7.0 - : - - : - 1015.851500 \n",
"8.0 - : - - : - 1006.534706 \n",
"9.0 FabAlley : dresses Age Range : 18-35 1062.036429 \n",
"10.0 - : - - : - 1062.181579 \n",
"11.0 - : - - : - 1080.005446 \n",
"12.0 - : - - : - 1082.250714 \n",
"13.0 - : - - : - 1094.290975 \n",
"14.0 FabAlley : Indya Age Range : 21-44 1091.455185 \n",
"15.0 - : - - : - 1109.296216 \n",
"16.0 - : - - : - 1092.911111 \n",
"17.0 - : - - : - 1155.129305 \n",
"18.0 Audience Types : Open Targeting - : - 1149.042222 \n",
"19.0 - : - - : - 1236.470980 \n",
"\n",
" spend_prop Projected % cpt change imp_factor other_cpt \n",
"rank \n",
"1.0 16.198740 12.489832 126042.559820 1550.839913 \n",
"2.0 19.130667 11.958528 123271.656326 1576.959364 \n",
"3.0 4.172721 11.979534 111829.613344 1736.740098 \n",
"4.0 5.636570 11.589102 100801.516462 1577.271710 \n",
"5.0 1.802123 12.138676 98072.691127 1610.861265 \n",
"6.0 3.213961 11.269356 89756.427698 1697.017981 \n",
"7.0 5.894733 11.180193 80249.833798 1959.884474 \n",
"8.0 1.241142 10.937612 80032.835537 1590.837604 \n",
"9.0 1.078478 11.591201 75192.726895 1709.187388 \n",
"10.0 1.463849 11.133470 72199.226865 1557.163256 \n",
"11.0 7.912091 11.541583 71768.824519 1537.922318 \n",
"12.0 10.990055 11.393298 70464.118948 1577.271710 \n",
"13.0 37.464398 11.718209 70363.255388 1679.231029 \n",
"14.0 4.275074 11.104290 67147.912890 1605.774086 \n",
"15.0 2.977098 11.067324 63971.003980 1632.793038 \n",
"16.0 1.426925 10.111842 60926.351389 1632.793038 \n",
"17.0 34.939011 11.345581 57801.492945 1491.396349 \n",
"18.0 2.250317 11.012578 57107.625830 1887.854057 \n",
"19.0 18.296080 11.454069 44418.501528 1746.014710 "
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print('GOOD PATHS (BLUE):')\n",
"good_df.sort_index()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [jarvis1]",
"language": "python",
"name": "Python [jarvis1]"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment