{ "cells": [ { "cell_type": "markdown", "id": "723c394d-987d-4f2d-8bd6-378a23b1218e", "metadata": { "tags": [] }, "source": [ "# 4. Train ConvNN Model: Regression Method\n", "\n", "\n", "In the following steps, you will:\n", "\n", "- Load the brown dwarf dataset used to train the ML models.\n", "- Prepare the X and y variables to deploy the trained ML models.\n", "- Visualize them for a few cases.\n", "\n", "We will need the following modules from `TelescopeML`:\n", "\n", "- **DeepBuilder**: to prepare the synthetic brown dwarf dataset and load the trained machine learning (ML) models.\n", "- **Predictor**: to prepare the observational brown dwarf dataset and deploy the trained ML models.\n", "- **StatVisAnalyzer**: to provide statistical tests and plotting functions.\n", "- **IO_utils**: to provide functions to load the trained ML models.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "6a0e9b08-df67-4377-9ad7-61865ed8f859", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "No Bottleneck unit testing available.\n" ] }, { "data": { "text/html": [ "\n", "
" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "application/javascript": [ "\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", " var JS_MIME_TYPE = 'application/javascript';\n", " var HTML_MIME_TYPE = 'text/html';\n", " var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n", " var CLASS_NAME = 'output_bokeh rendered_html';\n", "\n", " /**\n", " * Render data to the DOM node\n", " */\n", " function render(props, node) {\n", " var script = document.createElement(\"script\");\n", " node.appendChild(script);\n", " }\n", "\n", " /**\n", " * Handle when an output is cleared or removed\n", " */\n", " function handleClearOutput(event, handle) {\n", " var cell = handle.cell;\n", "\n", " var id = cell.output_area._bokeh_element_id;\n", " var server_id = cell.output_area._bokeh_server_id;\n", " // Clean up Bokeh references\n", " if (id != null && id in Bokeh.index) {\n", " Bokeh.index[id].model.document.clear();\n", " delete Bokeh.index[id];\n", " }\n", "\n", " if (server_id !== undefined) {\n", " // Clean up Bokeh references\n", " var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n", " cell.notebook.kernel.execute(cmd, {\n", " iopub: {\n", " output: function(msg) {\n", " var id = msg.content.text.trim();\n", " if (id in Bokeh.index) {\n", " Bokeh.index[id].model.document.clear();\n", " delete Bokeh.index[id];\n", " }\n", " }\n", " }\n", " });\n", " // Destroy server and session\n", " var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n", " cell.notebook.kernel.execute(cmd);\n", " }\n", " }\n", "\n", " /**\n", " * Handle when a new output is added\n", " */\n", " function handleAddOutput(event, handle) {\n", " var output_area = handle.output_area;\n", " var output = handle.output;\n", "\n", " // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n", " if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n", " return\n", " }\n", "\n", " var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n", "\n", " if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n", " toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n", " // store reference to embed id on output_area\n", " output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n", " }\n", " if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n", " var bk_div = document.createElement(\"div\");\n", " bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n", " var script_attrs = bk_div.children[0].attributes;\n", " for (var i = 0; i < script_attrs.length; i++) {\n", " toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n", " toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n", " }\n", " // store reference to server id on output_area\n", " output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n", " }\n", " }\n", "\n", " function register_renderer(events, OutputArea) {\n", "\n", " function append_mime(data, metadata, element) {\n", " // create a DOM node to render to\n", " var toinsert = this.create_output_subarea(\n", " metadata,\n", " CLASS_NAME,\n", " EXEC_MIME_TYPE\n", " );\n", " this.keyboard_manager.register_events(toinsert);\n", " // Render to node\n", " var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n", " render(props, toinsert[toinsert.length - 1]);\n", " element.append(toinsert);\n", " return toinsert\n", " }\n", "\n", " /* Handle when an output is cleared or removed */\n", " events.on('clear_output.CodeCell', handleClearOutput);\n", " events.on('delete.Cell', handleClearOutput);\n", "\n", " /* Handle when a new output is added */\n", " events.on('output_added.OutputArea', handleAddOutput);\n", "\n", " /**\n", " * Register the mime type and append_mime function with output_area\n", " */\n", " OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n", " /* Is output safe? */\n", " safe: true,\n", " /* Index of renderer in `output_area.display_order` */\n", " index: 0\n", " });\n", " }\n", "\n", " // register the mime type if in Jupyter Notebook environment and previously unregistered\n", " if (root.Jupyter !== undefined) {\n", " var events = require('base/js/events');\n", " var OutputArea = require('notebook/js/outputarea').OutputArea;\n", "\n", " if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n", " register_renderer(events, OutputArea);\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", " \"\\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", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\\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 \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"\\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", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\\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 \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"\\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", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"
\\n\"+\n",
" \"\\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 \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"
\\n\"+\n \"\n", " | gravity | \n", "temperature | \n", "c_o_ratio | \n", "metallicity | \n", "2.512 | \n", "2.487 | \n", "2.462 | \n", "2.438 | \n", "2.413 | \n", "2.389 | \n", "... | \n", "0.981 | \n", "0.971 | \n", "0.962 | \n", "0.952 | \n", "0.943 | \n", "0.933 | \n", "0.924 | \n", "0.915 | \n", "0.906 | \n", "0.897 | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-1.0 | \n", "9.103045e-08 | \n", "1.181658e-07 | \n", "1.307868e-07 | \n", "1.269229e-07 | \n", "1.159179e-07 | \n", "8.925110e-08 | \n", "... | \n", "1.257751e-07 | \n", "9.640859e-08 | \n", "7.612550e-08 | \n", "6.901364e-08 | \n", "6.247359e-08 | \n", "4.112384e-08 | \n", "5.127995e-08 | \n", "4.897355e-08 | \n", "4.087795e-08 | \n", "2.791689e-08 | \n", "
1 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.7 | \n", "9.103045e-08 | \n", "1.181658e-07 | \n", "1.307868e-07 | \n", "1.269229e-07 | \n", "1.159179e-07 | \n", "8.925110e-08 | \n", "... | \n", "1.257751e-07 | \n", "9.640859e-08 | \n", "7.612550e-08 | \n", "6.901364e-08 | \n", "6.247359e-08 | \n", "4.112384e-08 | \n", "5.127995e-08 | \n", "4.897355e-08 | \n", "4.087795e-08 | \n", "2.791689e-08 | \n", "
2 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.5 | \n", "9.103045e-08 | \n", "1.181658e-07 | \n", "1.307868e-07 | \n", "1.269229e-07 | \n", "1.159179e-07 | \n", "8.925110e-08 | \n", "... | \n", "1.257751e-07 | \n", "9.640859e-08 | \n", "7.612550e-08 | \n", "6.901364e-08 | \n", "6.247359e-08 | \n", "4.112384e-08 | \n", "5.127995e-08 | \n", "4.897355e-08 | \n", "4.087795e-08 | \n", "2.791689e-08 | \n", "
3 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.3 | \n", "9.103045e-08 | \n", "1.181658e-07 | \n", "1.307868e-07 | \n", "1.269229e-07 | \n", "1.159179e-07 | \n", "8.925110e-08 | \n", "... | \n", "1.257751e-07 | \n", "9.640859e-08 | \n", "7.612550e-08 | \n", "6.901364e-08 | \n", "6.247359e-08 | \n", "4.112384e-08 | \n", "5.127995e-08 | \n", "4.897355e-08 | \n", "4.087795e-08 | \n", "2.791689e-08 | \n", "
4 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "0.0 | \n", "9.103045e-08 | \n", "1.181658e-07 | \n", "1.307868e-07 | \n", "1.269229e-07 | \n", "1.159179e-07 | \n", "8.925110e-08 | \n", "... | \n", "1.257751e-07 | \n", "9.640859e-08 | \n", "7.612550e-08 | \n", "6.901364e-08 | \n", "6.247359e-08 | \n", "4.112384e-08 | \n", "5.127995e-08 | \n", "4.897355e-08 | \n", "4.087795e-08 | \n", "2.791689e-08 | \n", "
5 rows × 108 columns
\n", "\n", " | gravity | \n", "temperature | \n", "c_o_ratio | \n", "metallicity | \n", "
---|---|---|---|---|
0 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-1.0 | \n", "
1 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.7 | \n", "
2 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.5 | \n", "
3 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "-0.3 | \n", "
4 | \n", "5.0 | \n", "1100 | \n", "0.25 | \n", "0.0 | \n", "
\n", " | wl | \n", "
---|---|
0 | \n", "2.511960 | \n", "
1 | \n", "2.486966 | \n", "
2 | \n", "2.462220 | \n", "
3 | \n", "2.437720 | \n", "
4 | \n", "2.413464 | \n", "
\n", " | gravity | \n", "c_o_ratio | \n", "metallicity | \n", "temperature | \n", "
---|---|---|---|---|
0 | \n", "5.0 | \n", "0.25 | \n", "-1.0 | \n", "3.041393 | \n", "
1 | \n", "5.0 | \n", "0.25 | \n", "-0.7 | \n", "3.041393 | \n", "
2 | \n", "5.0 | \n", "0.25 | \n", "-0.5 | \n", "3.041393 | \n", "
3 | \n", "5.0 | \n", "0.25 | \n", "-0.3 | \n", "3.041393 | \n", "
4 | \n", "5.0 | \n", "0.25 | \n", "0.0 | \n", "3.041393 | \n", "
\n", " | min | \n", "max | \n", "
---|---|---|
0 | \n", "8.265340e-12 | \n", "3.445259e-08 | \n", "
1 | \n", "8.080712e-22 | \n", "8.397132e-14 | \n", "
2 | \n", "2.734403e-07 | \n", "8.632182e-06 | \n", "
3 | \n", "4.414951e-16 | \n", "3.373262e-10 | \n", "
4 | \n", "3.722576e-07 | \n", "6.859888e-06 | \n", "