Skip to content

Commit 7048644

Browse files
committed
fixed effect size calculation
1 parent a653ae0 commit 7048644

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

SliceFinder_demo.ipynb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"\n",
1919
" <div class=\"bk-root\">\n",
2020
" <a href=\"https://bokeh.pydata.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
21-
" <span id=\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\">Loading BokehJS ...</span>\n",
21+
" <span id=\"07fc1343-da38-4a49-8f32-95b2c52247b6\">Loading BokehJS ...</span>\n",
2222
" </div>"
2323
]
2424
},
@@ -185,7 +185,7 @@
185185
" \"</div>\"}};\n",
186186
"\n",
187187
" function display_loaded() {\n",
188-
" var el = document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\");\n",
188+
" var el = document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\");\n",
189189
" if (el != null) {\n",
190190
" el.textContent = \"BokehJS is loading...\";\n",
191191
" }\n",
@@ -239,9 +239,9 @@
239239
" console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
240240
" document.getElementsByTagName(\"head\")[0].appendChild(s);\n",
241241
" }\n",
242-
" };var element = document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\");\n",
242+
" };var element = document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\");\n",
243243
" if (element == null) {\n",
244-
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '526f94f3-e4ea-43ec-9ee0-c8b7b4137f40' but no matching script tag was found. \")\n",
244+
" console.log(\"Bokeh: ERROR: autoload.js configured with elementid '07fc1343-da38-4a49-8f32-95b2c52247b6' but no matching script tag was found. \")\n",
245245
" return false;\n",
246246
" }\n",
247247
"\n",
@@ -278,7 +278,7 @@
278278
" console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
279279
" root._bokeh_failed_load = true;\n",
280280
" } else if (force !== true) {\n",
281-
" var cell = $(document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\")).parents('.cell').data().cell;\n",
281+
" var cell = $(document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\")).parents('.cell').data().cell;\n",
282282
" cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
283283
" }\n",
284284
"\n",
@@ -295,7 +295,7 @@
295295
" }\n",
296296
"}(window));"
297297
],
298-
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = js_urls.length;\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var s = document.createElement('script');\n s.src = url;\n s.async = false;\n s.onreadystatechange = s.onload = function() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: all BokehJS libraries loaded\");\n run_callbacks()\n }\n };\n s.onerror = function() {\n console.warn(\"failed to load library \" + url);\n };\n console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.getElementsByTagName(\"head\")[0].appendChild(s);\n }\n };var element = document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '526f94f3-e4ea-43ec-9ee0-c8b7b4137f40' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.13.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"526f94f3-e4ea-43ec-9ee0-c8b7b4137f40\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(js_urls, function() {\n console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
298+
"application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n function now() {\n return new Date();\n }\n\n var force = true;\n\n if (typeof (root._bokeh_onload_callbacks) === \"undefined\" || force === true) {\n root._bokeh_onload_callbacks = [];\n root._bokeh_is_loading = undefined;\n }\n\n \n\n \n if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n root._bokeh_timeout = Date.now() + 5000;\n root._bokeh_failed_load = false;\n }\n\n var NB_LOAD_WARNING = {'data': {'text/html':\n \"<div style='background-color: #fdd'>\\n\"+\n \"<p>\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"</p>\\n\"+\n \"<ul>\\n\"+\n \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n \"<li>use INLINE resources instead, as so:</li>\\n\"+\n \"</ul>\\n\"+\n \"<code>\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"</code>\\n\"+\n \"</div>\"}};\n\n function display_loaded() {\n var el = document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\");\n if (el != null) {\n el.textContent = \"BokehJS is loading...\";\n }\n if (root.Bokeh !== undefined) {\n if (el != null) {\n el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n }\n } else if (Date.now() < root._bokeh_timeout) {\n setTimeout(display_loaded, 100)\n }\n }\n\n\n function run_callbacks() {\n try {\n root._bokeh_onload_callbacks.forEach(function(callback) { callback() });\n }\n finally {\n delete root._bokeh_onload_callbacks\n }\n console.info(\"Bokeh: all callbacks have finished\");\n }\n\n function load_libs(js_urls, callback) {\n root._bokeh_onload_callbacks.push(callback);\n if (root._bokeh_is_loading > 0) {\n console.log(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n return null;\n }\n if (js_urls == null || js_urls.length === 0) {\n run_callbacks();\n return null;\n }\n console.log(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n root._bokeh_is_loading = js_urls.length;\n for (var i = 0; i < js_urls.length; i++) {\n var url = js_urls[i];\n var s = document.createElement('script');\n s.src = url;\n s.async = false;\n s.onreadystatechange = s.onload = function() {\n root._bokeh_is_loading--;\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: all BokehJS libraries loaded\");\n run_callbacks()\n }\n };\n s.onerror = function() {\n console.warn(\"failed to load library \" + url);\n };\n console.log(\"Bokeh: injecting script tag for BokehJS library: \", url);\n document.getElementsByTagName(\"head\")[0].appendChild(s);\n }\n };var element = document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\");\n if (element == null) {\n console.log(\"Bokeh: ERROR: autoload.js configured with elementid '07fc1343-da38-4a49-8f32-95b2c52247b6' but no matching script tag was found. \")\n return false;\n }\n\n var js_urls = [\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.js\", \"https://cdn.pydata.org/bokeh/release/bokeh-gl-0.12.13.min.js\"];\n\n var inline_js = [\n function(Bokeh) {\n Bokeh.set_log_level(\"info\");\n },\n \n function(Bokeh) {\n \n },\n function(Bokeh) {\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-0.12.13.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-widgets-0.12.13.min.css\");\n console.log(\"Bokeh: injecting CSS: https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.css\");\n Bokeh.embed.inject_css(\"https://cdn.pydata.org/bokeh/release/bokeh-tables-0.12.13.min.css\");\n }\n ];\n\n function run_inline_js() {\n \n if ((root.Bokeh !== undefined) || (force === true)) {\n for (var i = 0; i < inline_js.length; i++) {\n inline_js[i].call(root, root.Bokeh);\n }if (force === true) {\n display_loaded();\n }} else if (Date.now() < root._bokeh_timeout) {\n setTimeout(run_inline_js, 100);\n } else if (!root._bokeh_failed_load) {\n console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n root._bokeh_failed_load = true;\n } else if (force !== true) {\n var cell = $(document.getElementById(\"07fc1343-da38-4a49-8f32-95b2c52247b6\")).parents('.cell').data().cell;\n cell.output_area.append_execute_result(NB_LOAD_WARNING)\n }\n\n }\n\n if (root._bokeh_is_loading === 0) {\n console.log(\"Bokeh: BokehJS loaded, going straight to plotting\");\n run_inline_js();\n } else {\n load_libs(js_urls, function() {\n console.log(\"Bokeh: BokehJS plotting callback run at\", now());\n run_inline_js();\n });\n }\n}(window));"
299299
},
300300
"metadata": {},
301301
"output_type": "display_data"
@@ -339,7 +339,7 @@
339339
},
340340
{
341341
"cell_type": "code",
342-
"execution_count": 2,
342+
"execution_count": 3,
343343
"metadata": {},
344344
"outputs": [
345345
{
@@ -397,6 +397,8 @@
397397
"\n",
398398
"X, y = adult_data[adult_data.columns.difference([\"Target\"])], adult_data[\"Target\"]\n",
399399
"\n",
400+
"pickle.dump(encoders, open(\"encoders.pkl\", \"wb\"), protocol=2)\n",
401+
"\n",
400402
"# Train a model\n",
401403
"#lr = LogisticRegression()\n",
402404
"#lr.fit(X, y)\n",
@@ -1500,8 +1502,8 @@
15001502
"\n",
15011503
"=====================\n",
15021504
"Slice description:\n",
1503-
"Hours per week:50 \n",
15041505
"Capital Gain:0 \n",
1506+
"Hours per week:50 \n",
15051507
"---------------------\n",
15061508
"effect_size: 0.479851077333\n",
15071509
"---------------------\n",
@@ -1510,8 +1512,8 @@
15101512
"\n",
15111513
"=====================\n",
15121514
"Slice description:\n",
1513-
"Capital Loss:0 \n",
15141515
"Education:Masters \n",
1516+
"Capital Loss:0 \n",
15151517
"---------------------\n",
15161518
"effect_size: 0.410478506987\n",
15171519
"---------------------\n",
@@ -1520,8 +1522,8 @@
15201522
"\n",
15211523
"=====================\n",
15221524
"Slice description:\n",
1523-
"Capital Loss:0 \n",
15241525
"Education-Num:14 \n",
1526+
"Capital Loss:0 \n",
15251527
"---------------------\n",
15261528
"effect_size: 0.410478506987\n",
15271529
"---------------------\n",
@@ -1539,8 +1541,8 @@
15391541
"\n",
15401542
"=====================\n",
15411543
"Slice description:\n",
1542-
"Capital Gain:0 \n",
15431544
"Education:Masters \n",
1545+
"Capital Gain:0 \n",
15441546
"---------------------\n",
15451547
"effect_size: 0.525841538236\n",
15461548
"---------------------\n",
@@ -1549,8 +1551,8 @@
15491551
"\n",
15501552
"=====================\n",
15511553
"Slice description:\n",
1552-
"Capital Gain:0 \n",
15531554
"Education-Num:14 \n",
1555+
"Capital Gain:0 \n",
15541556
"---------------------\n",
15551557
"effect_size: 0.525841538236\n",
15561558
"---------------------\n",
@@ -1564,6 +1566,15 @@
15641566
"with open('slices.p','rb') as handle:\n",
15651567
" slices = pickle.load(handle)\n",
15661568
"\n",
1569+
"pickle.dump(slices, open('slices_ver2.pkl','wb'), protocol=2)\n",
1570+
"\n",
1571+
"encoders = dict()\n",
1572+
"with open('encoder')\n",
1573+
"\n",
1574+
"slices = list()\n",
1575+
"with open('slices_ver2.pkl','rb') as handle:\n",
1576+
" slices = pickle.load(handle)\n",
1577+
" \n",
15671578
"slices_ = sorted(slices, key=lambda s: s.size, reverse=True) \n",
15681579
"k = 10 \n",
15691580
"for s in slices_[:k]:\n",

encoders.pkl

2.46 KB
Binary file not shown.

risk_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def effect_size(sample_a, reference):
3131
sample_b_var = 0.
3232

3333
diff = np.mean(sample_a) - sample_b_mean
34-
diff /= (np.std(sample_a) + math.sqrt(sample_b_var))/2.
34+
diff /= math.sqrt( (np.std(sample_a) + math.sqrt(sample_b_var))/2. )
3535
return diff

slices_ver2.pkl

2.58 MB
Binary file not shown.

0 commit comments

Comments
 (0)