blob: c06ae0f056a8233f4efe59827da931eef8f74ef8 [file]
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Hamilton notebook extension\n",
"This notebook allows to load Hamilton dataflow definition from files and edit them interactively. It uses [Hamilton Jupyter Magics](https://hamilton.dagworks.io/en/latest/how-tos/use-in-jupyter-notebook/#use-hamilton-jupyter-magic)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports\n",
"Import modules and load Jupyter magics"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from hamilton import driver\n",
"%load_ext hamilton.plugins.jupyter_magic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dataflow definition\n",
"The next two cells use `%insert_module` to load source code and insert it in a cell. The inserted cells use `%%cell_to_module` to register the cell as a Python module. \n",
"\n",
"Execute each cell once before going to the next section."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>\n",
"\n",
" if (document.getElementById('notebook-container')) {\n",
" //console.log('Jupyter Notebook');\n",
" allCells = document.getElementById('notebook-container').children;\n",
" selectionClass = /\\bselected\\b/;\n",
" jupyter = 'notebook';\n",
" }\n",
" else if (document.getElementsByClassName('jp-Notebook-cell').length){\n",
" //console.log('Jupyter Lab');\n",
" allCells = document.getElementsByClassName('jp-Notebook-cell');\n",
" selectionClass = /\\bjp-mod-selected\\b/;\n",
" jupyter = 'lab';\n",
" }\n",
" else {\n",
" console.log('Unknown Environment');\n",
" }\n",
"\n",
" if (typeof allCells !== 'undefined') {\n",
" for (i = 0; i < allCells.length - 1; i++) {\n",
" if(selectionClass.test(allCells[i].getAttribute('class'))){\n",
" allCells[i + 1].remove();\n",
"\n",
" // remove output indicators of current cell\n",
" window.setTimeout(function(){\n",
" if(jupyter === 'lab') {\n",
" allCells[i].setAttribute('class', allCells[i].getAttribute('class') + ' jp-mod-noOutputs');\n",
" allCells[i].getElementsByClassName('jp-OutputArea jp-Cell-outputArea')[0].innerHTML = '';\n",
" } else if(jupyter === 'notebook'){\n",
" allCells[i].getElementsByClassName('output')[0].innerHTML = '';\n",
" }\n",
" }, 20);\n",
"\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" </script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%insert_module ../src/hamilton_code/data_processing.py"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<script>\n",
"\n",
" if (document.getElementById('notebook-container')) {\n",
" //console.log('Jupyter Notebook');\n",
" allCells = document.getElementById('notebook-container').children;\n",
" selectionClass = /\\bselected\\b/;\n",
" jupyter = 'notebook';\n",
" }\n",
" else if (document.getElementsByClassName('jp-Notebook-cell').length){\n",
" //console.log('Jupyter Lab');\n",
" allCells = document.getElementsByClassName('jp-Notebook-cell');\n",
" selectionClass = /\\bjp-mod-selected\\b/;\n",
" jupyter = 'lab';\n",
" }\n",
" else {\n",
" console.log('Unknown Environment');\n",
" }\n",
"\n",
" if (typeof allCells !== 'undefined') {\n",
" for (i = 0; i < allCells.length - 1; i++) {\n",
" if(selectionClass.test(allCells[i].getAttribute('class'))){\n",
" allCells[i + 1].remove();\n",
"\n",
" // remove output indicators of current cell\n",
" window.setTimeout(function(){\n",
" if(jupyter === 'lab') {\n",
" allCells[i].setAttribute('class', allCells[i].getAttribute('class') + ' jp-mod-noOutputs');\n",
" allCells[i].getElementsByClassName('jp-OutputArea jp-Cell-outputArea')[0].innerHTML = '';\n",
" } else if(jupyter === 'notebook'){\n",
" allCells[i].getElementsByClassName('output')[0].innerHTML = '';\n",
" }\n",
" }, 20);\n",
"\n",
" break;\n",
" }\n",
" }\n",
" }\n",
" </script>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%insert_module ../src/hamilton_code/data_science.py"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Executing the previous cells should have registered the modules `data_processing` and `data_science`. Run the next cell to verify.\n",
"\n",
"Editing and re-executing the above files will update the module definitions"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<function companies at 0x7f8bbd6944c0>\n",
"<function split_data at 0x7f8c10087d00>\n"
]
}
],
"source": [
"print(data_processing.companies)\n",
"print(data_science.split_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dataflow execution\n",
"We can now build a Hamilton `Driver` to execute the dataflow defined by our modules `data_processing` and `data_science`."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Title: %3 Pages: 1 -->\n",
"<svg width=\"1345pt\" height=\"324pt\"\n",
" viewBox=\"0.00 0.00 1345.00 324.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 320)\">\n",
"<title>%3</title>\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-320 1341,-320 1341,4 -4,4\"/>\n",
"<g id=\"clust1\" class=\"cluster\">\n",
"<title>cluster__legend</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" points=\"8,-146 8,-278 104,-278 104,-146 8,-146\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-262.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">Legend</text>\n",
"</g>\n",
"<!-- companies -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>companies</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M238.5,-64C238.5,-64 155.5,-64 155.5,-64 149.5,-64 143.5,-58 143.5,-52 143.5,-52 143.5,-12 143.5,-12 143.5,-6 149.5,0 155.5,0 155.5,0 238.5,0 238.5,0 244.5,0 250.5,-6 250.5,-12 250.5,-12 250.5,-52 250.5,-52 250.5,-58 244.5,-64 238.5,-64\"/>\n",
"<text text-anchor=\"start\" x=\"154.5\" y=\"-42.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">companies</text>\n",
"<text text-anchor=\"start\" x=\"158.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- preprocess_companies -->\n",
"<g id=\"node9\" class=\"node\">\n",
"<title>preprocess_companies</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M470,-64C470,-64 294,-64 294,-64 288,-64 282,-58 282,-52 282,-52 282,-12 282,-12 282,-6 288,0 294,0 294,0 470,0 470,0 476,0 482,-6 482,-12 482,-12 482,-52 482,-52 482,-58 476,-64 470,-64\"/>\n",
"<text text-anchor=\"start\" x=\"293\" y=\"-42.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">preprocess_companies</text>\n",
"<text text-anchor=\"start\" x=\"343.5\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- companies&#45;&gt;preprocess_companies -->\n",
"<g id=\"edge13\" class=\"edge\">\n",
"<title>companies&#45;&gt;preprocess_companies</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M250.93,-32C257.53,-32 264.45,-32 271.52,-32\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"271.97,-35.5 281.97,-32 271.97,-28.5 271.97,-35.5\"/>\n",
"</g>\n",
"<!-- X_train -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>X_train</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M978,-316C978,-316 903,-316 903,-316 897,-316 891,-310 891,-304 891,-304 891,-264 891,-264 891,-258 897,-252 903,-252 903,-252 978,-252 978,-252 984,-252 990,-258 990,-264 990,-264 990,-304 990,-304 990,-310 984,-316 978,-316\"/>\n",
"<text text-anchor=\"start\" x=\"913\" y=\"-294.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">X_train</text>\n",
"<text text-anchor=\"start\" x=\"902\" y=\"-266.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- train_model -->\n",
"<g id=\"node8\" class=\"node\">\n",
"<title>train_model</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1150,-234C1150,-234 1031,-234 1031,-234 1025,-234 1019,-228 1019,-222 1019,-222 1019,-182 1019,-182 1019,-176 1025,-170 1031,-170 1031,-170 1150,-170 1150,-170 1156,-170 1162,-176 1162,-182 1162,-182 1162,-222 1162,-222 1162,-228 1156,-234 1150,-234\"/>\n",
"<text text-anchor=\"start\" x=\"1044\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">train_model</text>\n",
"<text text-anchor=\"start\" x=\"1030\" y=\"-184.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">LinearRegression</text>\n",
"</g>\n",
"<!-- X_train&#45;&gt;train_model -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>X_train&#45;&gt;train_model</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M990.37,-256.92C1000.7,-251.2 1011.77,-245.07 1022.63,-239.05\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1024.63,-241.94 1031.68,-234.03 1021.24,-235.82 1024.63,-241.94\"/>\n",
"</g>\n",
"<!-- X_test -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>X_test</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M978,-152C978,-152 903,-152 903,-152 897,-152 891,-146 891,-140 891,-140 891,-100 891,-100 891,-94 897,-88 903,-88 903,-88 978,-88 978,-88 984,-88 990,-94 990,-100 990,-100 990,-140 990,-140 990,-146 984,-152 978,-152\"/>\n",
"<text text-anchor=\"start\" x=\"916\" y=\"-130.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">X_test</text>\n",
"<text text-anchor=\"start\" x=\"902\" y=\"-102.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- evaluate_model -->\n",
"<g id=\"node13\" class=\"node\">\n",
"<title>evaluate_model</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M1325,-193C1325,-193 1203,-193 1203,-193 1197,-193 1191,-187 1191,-181 1191,-181 1191,-141 1191,-141 1191,-135 1197,-129 1203,-129 1203,-129 1325,-129 1325,-129 1331,-129 1337,-135 1337,-141 1337,-141 1337,-181 1337,-181 1337,-187 1331,-193 1325,-193\"/>\n",
"<text text-anchor=\"start\" x=\"1202\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">evaluate_model</text>\n",
"<text text-anchor=\"start\" x=\"1243.5\" y=\"-143.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Union</text>\n",
"</g>\n",
"<!-- X_test&#45;&gt;evaluate_model -->\n",
"<g id=\"edge18\" class=\"edge\">\n",
"<title>X_test&#45;&gt;evaluate_model</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M990.24,-114.01C1019.47,-111.88 1057.13,-111.75 1089.5,-120\"/>\n",
"</g>\n",
"<!-- create_model_input_table -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>create_model_input_table</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M722,-146C722,-146 523,-146 523,-146 517,-146 511,-140 511,-134 511,-134 511,-94 511,-94 511,-88 517,-82 523,-82 523,-82 722,-82 722,-82 728,-82 734,-88 734,-94 734,-94 734,-134 734,-134 734,-140 728,-146 722,-146\"/>\n",
"<text text-anchor=\"start\" x=\"522\" y=\"-124.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">create_model_input_table</text>\n",
"<text text-anchor=\"start\" x=\"584\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- split_data -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>split_data</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M850,-193C850,-193 775,-193 775,-193 769,-193 763,-187 763,-181 763,-181 763,-141 763,-141 763,-135 769,-129 775,-129 775,-129 850,-129 850,-129 856,-129 862,-135 862,-141 862,-141 862,-181 862,-181 862,-187 856,-193 850,-193\"/>\n",
"<text text-anchor=\"start\" x=\"774\" y=\"-171.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">split_data</text>\n",
"<text text-anchor=\"start\" x=\"799.5\" y=\"-143.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">dict</text>\n",
"</g>\n",
"<!-- create_model_input_table&#45;&gt;split_data -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>create_model_input_table&#45;&gt;split_data</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M734.22,-141.68C740.55,-143.26 746.78,-144.82 752.78,-146.32\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"752.1,-149.76 762.65,-148.79 753.8,-142.97 752.1,-149.76\"/>\n",
"</g>\n",
"<!-- y_train -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>y_train</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M966.5,-234C966.5,-234 914.5,-234 914.5,-234 908.5,-234 902.5,-228 902.5,-222 902.5,-222 902.5,-182 902.5,-182 902.5,-176 908.5,-170 914.5,-170 914.5,-170 966.5,-170 966.5,-170 972.5,-170 978.5,-176 978.5,-182 978.5,-182 978.5,-222 978.5,-222 978.5,-228 972.5,-234 966.5,-234\"/>\n",
"<text text-anchor=\"start\" x=\"913.5\" y=\"-212.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">y_train</text>\n",
"<text text-anchor=\"start\" x=\"919\" y=\"-184.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Series</text>\n",
"</g>\n",
"<!-- y_train&#45;&gt;train_model -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>y_train&#45;&gt;train_model</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M978.85,-202C988.06,-202 998.29,-202 1008.7,-202\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1008.71,-205.5 1018.71,-202 1008.71,-198.5 1008.71,-205.5\"/>\n",
"</g>\n",
"<!-- y_test -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>y_test</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M963.5,-70C963.5,-70 917.5,-70 917.5,-70 911.5,-70 905.5,-64 905.5,-58 905.5,-58 905.5,-18 905.5,-18 905.5,-12 911.5,-6 917.5,-6 917.5,-6 963.5,-6 963.5,-6 969.5,-6 975.5,-12 975.5,-18 975.5,-18 975.5,-58 975.5,-58 975.5,-64 969.5,-70 963.5,-70\"/>\n",
"<text text-anchor=\"start\" x=\"916.5\" y=\"-48.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">y_test</text>\n",
"<text text-anchor=\"start\" x=\"919\" y=\"-20.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">Series</text>\n",
"</g>\n",
"<!-- y_test&#45;&gt;evaluate_model -->\n",
"<g id=\"edge19\" class=\"edge\">\n",
"<title>y_test&#45;&gt;evaluate_model</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M975.51,-63.54C1004.2,-83.36 1047.23,-109.23 1089.5,-120\"/>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1091.5,-120C1120.56,-127.4 1152.49,-135.14 1180.84,-141.88\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1180.17,-145.32 1190.7,-144.22 1181.78,-138.5 1180.17,-145.32\"/>\n",
"</g>\n",
"<!-- split_data&#45;&gt;X_train -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>split_data&#45;&gt;X_train</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M842.51,-193.34C856.73,-208.77 874.35,-227.25 891,-243 891.68,-243.65 892.37,-244.3 893.07,-244.95\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"891.01,-247.8 900.77,-251.93 895.72,-242.62 891.01,-247.8\"/>\n",
"</g>\n",
"<!-- split_data&#45;&gt;X_test -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>split_data&#45;&gt;X_test</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M862.21,-145.15C868.4,-143.14 874.77,-141.06 881.08,-139.01\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"882.49,-142.23 890.91,-135.81 880.32,-135.58 882.49,-142.23\"/>\n",
"</g>\n",
"<!-- split_data&#45;&gt;y_train -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>split_data&#45;&gt;y_train</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M862.21,-176.85C872.19,-180.1 882.66,-183.51 892.57,-186.73\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"891.66,-190.11 902.25,-189.88 893.82,-183.46 891.66,-190.11\"/>\n",
"</g>\n",
"<!-- split_data&#45;&gt;y_test -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>split_data&#45;&gt;y_test</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M842.51,-128.66C856.73,-113.23 874.35,-94.75 891,-79 893.14,-76.98 895.36,-74.93 897.62,-72.88\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"900.25,-75.23 905.42,-65.98 895.61,-69.99 900.25,-75.23\"/>\n",
"</g>\n",
"<!-- train_model&#45;&gt;evaluate_model -->\n",
"<g id=\"edge17\" class=\"edge\">\n",
"<title>train_model&#45;&gt;evaluate_model</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1162.25,-185.09C1168.42,-183.61 1174.71,-182.11 1180.96,-180.61\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"1181.84,-184 1190.75,-178.27 1180.21,-177.19 1181.84,-184\"/>\n",
"</g>\n",
"<!-- preprocess_companies&#45;&gt;create_model_input_table -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>preprocess_companies&#45;&gt;create_model_input_table</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M476.24,-64.06C490.14,-68.84 504.54,-73.79 518.63,-78.63\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"517.74,-82.03 528.33,-81.97 520.01,-75.41 517.74,-82.03\"/>\n",
"</g>\n",
"<!-- shuttles -->\n",
"<g id=\"node10\" class=\"node\">\n",
"<title>shuttles</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M234.5,-146C234.5,-146 159.5,-146 159.5,-146 153.5,-146 147.5,-140 147.5,-134 147.5,-134 147.5,-94 147.5,-94 147.5,-88 153.5,-82 159.5,-82 159.5,-82 234.5,-82 234.5,-82 240.5,-82 246.5,-88 246.5,-94 246.5,-94 246.5,-134 246.5,-134 246.5,-140 240.5,-146 234.5,-146\"/>\n",
"<text text-anchor=\"start\" x=\"165\" y=\"-124.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">shuttles</text>\n",
"<text text-anchor=\"start\" x=\"158.5\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- preprocess_shuttles -->\n",
"<g id=\"node12\" class=\"node\">\n",
"<title>preprocess_shuttles</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M460,-146C460,-146 304,-146 304,-146 298,-146 292,-140 292,-134 292,-134 292,-94 292,-94 292,-88 298,-82 304,-82 304,-82 460,-82 460,-82 466,-82 472,-88 472,-94 472,-94 472,-134 472,-134 472,-140 466,-146 460,-146\"/>\n",
"<text text-anchor=\"start\" x=\"303\" y=\"-124.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">preprocess_shuttles</text>\n",
"<text text-anchor=\"start\" x=\"343.5\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- shuttles&#45;&gt;preprocess_shuttles -->\n",
"<g id=\"edge16\" class=\"edge\">\n",
"<title>shuttles&#45;&gt;preprocess_shuttles</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M246.56,-114C257.48,-114 269.45,-114 281.62,-114\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"281.86,-117.5 291.86,-114 281.86,-110.5 281.86,-117.5\"/>\n",
"</g>\n",
"<!-- reviews -->\n",
"<g id=\"node11\" class=\"node\">\n",
"<title>reviews</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M419.5,-228C419.5,-228 344.5,-228 344.5,-228 338.5,-228 332.5,-222 332.5,-216 332.5,-216 332.5,-176 332.5,-176 332.5,-170 338.5,-164 344.5,-164 344.5,-164 419.5,-164 419.5,-164 425.5,-164 431.5,-170 431.5,-176 431.5,-176 431.5,-216 431.5,-216 431.5,-222 425.5,-228 419.5,-228\"/>\n",
"<text text-anchor=\"start\" x=\"351.5\" y=\"-206.8\" font-family=\"Helvetica,sans-Serif\" font-weight=\"bold\" font-size=\"14.00\">reviews</text>\n",
"<text text-anchor=\"start\" x=\"343.5\" y=\"-178.8\" font-family=\"Helvetica,sans-Serif\" font-style=\"italic\" font-size=\"14.00\">DataFrame</text>\n",
"</g>\n",
"<!-- reviews&#45;&gt;create_model_input_table -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>reviews&#45;&gt;create_model_input_table</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M431.55,-179.31C456.62,-170.69 488.22,-159.82 518.41,-149.44\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"519.83,-152.66 528.15,-146.1 517.56,-146.04 519.83,-152.66\"/>\n",
"</g>\n",
"<!-- preprocess_shuttles&#45;&gt;create_model_input_table -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>preprocess_shuttles&#45;&gt;create_model_input_table</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M472.15,-114C481.48,-114 491.07,-114 500.67,-114\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"500.68,-117.5 510.68,-114 500.68,-110.5 500.68,-117.5\"/>\n",
"</g>\n",
"<!-- _companies_inputs -->\n",
"<g id=\"node14\" class=\"node\">\n",
"<title>_companies_inputs</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"112,-54.5 0,-54.5 0,-9.5 112,-9.5 112,-54.5\"/>\n",
"<text text-anchor=\"start\" x=\"15\" y=\"-27.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">data_dir</text>\n",
"<text text-anchor=\"start\" x=\"78\" y=\"-27.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
"</g>\n",
"<!-- _companies_inputs&#45;&gt;companies -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>_companies_inputs&#45;&gt;companies</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M112.34,-32C119.15,-32 126.16,-32 133.08,-32\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"133.12,-35.5 143.12,-32 133.12,-28.5 133.12,-35.5\"/>\n",
"</g>\n",
"<!-- _split_data_inputs -->\n",
"<g id=\"node15\" class=\"node\">\n",
"<title>_split_data_inputs</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"704,-251.5 541,-251.5 541,-164.5 704,-164.5 704,-251.5\"/>\n",
"<text text-anchor=\"start\" x=\"556.5\" y=\"-224.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">random_state</text>\n",
"<text text-anchor=\"start\" x=\"664.5\" y=\"-224.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">int</text>\n",
"<text text-anchor=\"start\" x=\"574\" y=\"-203.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">test_size</text>\n",
"<text text-anchor=\"start\" x=\"658.5\" y=\"-203.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">float</text>\n",
"<text text-anchor=\"start\" x=\"575.5\" y=\"-182.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">features</text>\n",
"<text text-anchor=\"start\" x=\"661.5\" y=\"-182.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">List</text>\n",
"</g>\n",
"<!-- _split_data_inputs&#45;&gt;split_data -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>_split_data_inputs&#45;&gt;split_data</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M704.05,-187.86C720.48,-183.76 737.47,-179.51 752.96,-175.64\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"754.05,-178.97 762.9,-173.15 752.35,-172.18 754.05,-178.97\"/>\n",
"</g>\n",
"<!-- _shuttles_inputs -->\n",
"<g id=\"node16\" class=\"node\">\n",
"<title>_shuttles_inputs</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"112,-136.5 0,-136.5 0,-91.5 112,-91.5 112,-136.5\"/>\n",
"<text text-anchor=\"start\" x=\"15\" y=\"-109.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">data_dir</text>\n",
"<text text-anchor=\"start\" x=\"78\" y=\"-109.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
"</g>\n",
"<!-- _shuttles_inputs&#45;&gt;shuttles -->\n",
"<g id=\"edge14\" class=\"edge\">\n",
"<title>_shuttles_inputs&#45;&gt;shuttles</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M112.34,-114C120.43,-114 128.79,-114 136.95,-114\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"137.15,-117.5 147.15,-114 137.15,-110.5 137.15,-117.5\"/>\n",
"</g>\n",
"<!-- _reviews_inputs -->\n",
"<g id=\"node17\" class=\"node\">\n",
"<title>_reviews_inputs</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"253,-218.5 141,-218.5 141,-173.5 253,-173.5 253,-218.5\"/>\n",
"<text text-anchor=\"start\" x=\"156\" y=\"-191.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">data_dir</text>\n",
"<text text-anchor=\"start\" x=\"219\" y=\"-191.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">str</text>\n",
"</g>\n",
"<!-- _reviews_inputs&#45;&gt;reviews -->\n",
"<g id=\"edge15\" class=\"edge\">\n",
"<title>_reviews_inputs&#45;&gt;reviews</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M253.4,-196C275.11,-196 300.04,-196 322.07,-196\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"322.3,-199.5 332.3,-196 322.3,-192.5 322.3,-199.5\"/>\n",
"</g>\n",
"<!-- input -->\n",
"<g id=\"node18\" class=\"node\">\n",
"<title>input</title>\n",
"<polygon fill=\"#ffffff\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"85.5,-246.5 26.5,-246.5 26.5,-209.5 85.5,-209.5 85.5,-246.5\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-224.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input</text>\n",
"</g>\n",
"<!-- function -->\n",
"<g id=\"node19\" class=\"node\">\n",
"<title>function</title>\n",
"<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M84,-191.5C84,-191.5 28,-191.5 28,-191.5 22,-191.5 16,-185.5 16,-179.5 16,-179.5 16,-166.5 16,-166.5 16,-160.5 22,-154.5 28,-154.5 28,-154.5 84,-154.5 84,-154.5 90,-154.5 96,-160.5 96,-166.5 96,-166.5 96,-179.5 96,-179.5 96,-185.5 90,-191.5 84,-191.5\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-169.3\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">function</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<hamilton.driver.Driver at 0x7f8bbd6a6560>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dr = driver.Builder().with_modules(data_processing, data_science).build()\n",
"dr"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'evaluate_model': 0.3869831978103261}\n"
]
}
],
"source": [
"inputs = dict(\n",
" data_dir=\"../data/\",\n",
" test_size=0.2,\n",
" random_state=3,\n",
" features=[\n",
" \"engines\",\n",
" \"passenger_capacity\",\n",
" \"crew\",\n",
" \"d_check_complete\",\n",
" \"moon_clearance_complete\",\n",
" \"iata_approved\",\n",
" \"company_rating\",\n",
" \"review_scores_rating\",\n",
" ],\n",
")\n",
"results = dr.execute([\"evaluate_model\"], inputs=inputs)\n",
"print(results)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"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.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}