PhilippeMoussalli commented on code in PR #22587:
URL: https://github.com/apache/beam/pull/22587#discussion_r964473694
##########
examples/notebooks/beam-ml/dataframe_api_preprocessing.ipynb:
##########
@@ -0,0 +1,1907 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Overview\n",
+ "\n",
+ "One of the most common tools used for data exploration and
pre-processing is [pandas
DataFrames](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html).
Pandas has become very popular for its ease of use. It has very intuitive
methods to perform common analytical tasks and data pre-processing. \n",
+ "\n",
+ "Pandas loads all of the data into memory on a single machine (one
node) for rapid execution. This works well when dealing with small-scale
datasets. However, many projects involve datasets that can grow too big to fit
in memory. These use cases generally require the usage of parallel data
processing frameworks such as Apache Beam.\n",
+ "\n",
+ "\n",
+ "## Beam DataFrames\n",
+ "\n",
+ "\n",
+ "Beam DataFrames provide a pandas-like DataFrame\n",
+ "API to declare and define Beam processing pipelines. It provides a
familiar interface for machine learning practioners to build complex
data-processing pipelines by only invoking standard pandas commands.\n",
+ "\n",
+ "> ℹ️ To learn more about Beam DataFrames, take a look at the\n",
+ "[Beam DataFrames
overview](https://beam.apache.org/documentation/dsls/dataframes/overview)
page.\n",
+ "\n",
+ "## Tutorial outline\n",
+ "\n",
+ "In this notebook, we walk through the use of the Beam DataFrames API
to perform common data exploration as well as pre-processing steps that are
necessary to prepare your dataset for machine learning model training and
inference, such as: \n",
+ "\n",
+ "* Removing unwanted columns.\n",
+ "* One-hot encoding categorical columns.\n",
+ "* Normalizing numerical columns.\n",
+ "\n",
+ "\n"
+ ],
+ "metadata": {
+ "id": "iFZC1inKuUCy"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Installation\n",
+ "\n",
+ "First, we need to install Apache Beam with the `interactive`
component to be able to use the Interactive runner. The latest implemented
DataFrames API methods invoked in this notebook are available in Beam
<b>2.41</b> or later.\n"
+ ],
+ "metadata": {
+ "id": "A0f2HJ22D4lt"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "pCjwrwNWnuqI"
+ },
+ "source": [
+ "**Option 1:** Install latest version with implemented df.mean()\n",
+ "\n",
+ "TODO: Remove this text later"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "-OJC0Xn5Um-C"
+ },
+ "outputs": [],
+ "source": [
+ "!git clone https://github.com/apache/beam.git\n",
+ "\n",
+ "!cd beam/sdks/python && pip3 install -r build-requirements.txt \n",
+ "\n",
+ "%pip install -e beam/sdks/python/.[interactive,gcp]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "xfXzNzA1n3ZP"
+ },
+ "source": [
+ "**Option 2:** Install latest release version \n",
+ "\n",
+ "**[12/07/2022]:** df.mean() is currently not supported for this
version (beam 2.40)\n",
+ "\n",
+ "TODO: Remove this text later"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "4xY7ECJZOuJj"
+ },
+ "outputs": [],
+ "source": [
+ "! pip install apache-beam[interactive,gcp]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# Part I : Local exploration with the Interactive Beam runner\n",
+ "We first use the [Interactive
Beam](https://beam.apache.org/releases/pydoc/2.20.0/apache_beam.runners.interactive.interactive_beam.html)
to explore and develop our pipeline.\n",
+ "This allows us to quickly test our pipeline locally before running it
on a distributed runner. \n",
+ "\n",
+ "\n",
+ "> ℹ️ In this section, we will only be working with a subset of the
original dataset since we're only using the the compute resources of the
notebook instance.\n"
+ ],
+ "metadata": {
+ "id": "3NO6RgB7GkkE"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "5I3G094hoB1P"
+ },
+ "source": [
+ "# Loading the data\n",
+ "\n",
+ "Pandas has the\n",
+
"[`pandas.read_csv`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html)\n",
+ "function to easily read CSV files into DataFrames.\n",
+ "We're using the beam\n",
+
"[`beam.dataframe.io.read_csv`](https://beam.apache.org/releases/pydoc/current/apache_beam.dataframe.io.html#apache_beam.dataframe.io.read_csv)\n",
+ "function that emulates `pandas.read_csv`. The main difference between
them is that the beam method returns a deferred Beam DataFrame while pandas
return a standard DataFrame.\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "id": "X3_OB9cAULav"
+ },
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "import numpy as np\n",
+ "import pandas as pd \n",
+ "import apache_beam as beam\n",
+ "import apache_beam.runners.interactive.interactive_beam as ib\n",
+ "from apache_beam.runners.interactive.interactive_runner import
InteractiveRunner\n",
+ "from apache_beam.runners.dataflow import DataflowRunner\n",
+ "\n",
+ "# Available options: [sample_1000, sample_10000, sample_100000,
sample] where\n",
+ "# sample contains all of the dataset (around 1000000 samples)\n",
+ "file_location =
'gs://apache-beam-samples/nasa_jpl_asteroid/sample_10000.csv'\n",
+ "\n",
+ "# Initialize pipline\n",
+ "p = beam.Pipeline(InteractiveRunner())\n",
+ "\n",
+ "# Create a deferred Beam DataFrame with the contents of our csv
file.\n",
+ "beam_df = p | beam.dataframe.io.read_csv(file_location,
splittable=True)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "paf7yf3YpCh8"
+ },
+ "source": [
+ "# Data pre-processing\n",
+ "\n",
+ "## Dataset description \n",
+ "\n",
+ "### [NASA - Nearest Earth Objects
dataset](https://cneos.jpl.nasa.gov/ca/)\n",
+ "There are an innumerable number of objects in the outer space. Some
of them are closer than we think. Even though we might think that a distance of
70,000 Km can not potentially harm us, but at an astronomical scale, this is a
very small distance and can disrupt many natural phenomena. \n",
+ "\n",
+ "These objects/asteroids can thus prove to be harmful. Hence, it is
wise to know what is surrounding us and what can harm us amongst those. Thus,
this dataset compiles the list of NASA certified asteroids that are classified
as the nearest earth object."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "\n",
+ "Let's first inspect the columns of our dataset and their types"
+ ],
+ "metadata": {
+ "id": "cvAu5T0ENjuQ"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "LwW77ixE-pjR",
+ "outputId": "c24ff83d-3a13-47a6-c9c2-3978729fde82"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "spk_id int64\n",
+ "full_name object\n",
+ "near_earth_object object\n",
+ "absolute_magnitude float64\n",
+ "diameter float64\n",
+ "albedo float64\n",
+ "diameter_sigma float64\n",
+ "eccentricity float64\n",
+ "inclination float64\n",
+ "moid_ld float64\n",
+ "object_class object\n",
+ "semi_major_axis_au_unit float64\n",
+ "hazardous_flag object\n",
+ "dtype: object"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 4
+ }
+ ],
+ "source": [
+ "beam_df.dtypes"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "When using Interactive Beam, we can use `ib.collect()` to bring a
Beam DataFrame into local memory as a Pandas DataFrame."
+ ],
+ "metadata": {
+ "id": "1Wa6fpbyQige"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 746
+ },
+ "id": "DPxkAmkpq4Xv",
+ "outputId": "14fa80de-2dee-4963-99d8-3e321f949ff8"
+ },
+ "outputs": [
+ {
+ "output_type": "display_data",
+ "data": {
+ "text/plain": [
+ "<IPython.core.display.HTML object>"
+ ],
+ "text/html": [
+ "\n",
+ " <link rel=\"stylesheet\"
href=\"https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css\"
integrity=\"sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh\"
crossorigin=\"anonymous\">\n",
+ " <div
id=\"progress_indicator_a986c6cc61ed5a5b622e163d92f73775\">\n",
+ " <div class=\"spinner-border text-info\"
role=\"status\"></div>\n",
+ " <span class=\"text-info\">Processing...
collect</span>\n",
+ " </div>\n",
+ " "
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "display_data",
+ "data": {
+ "application/javascript": [
+ "\n",
+ " if (typeof window.interactive_beam_jquery ==
'undefined') {\n",
+ " var jqueryScript =
document.createElement('script');\n",
+ " jqueryScript.src =
'https://code.jquery.com/jquery-3.4.1.slim.min.js';\n",
+ " jqueryScript.type = 'text/javascript';\n",
+ " jqueryScript.onload = function() {\n",
+ " var datatableScript =
document.createElement('script');\n",
+ " datatableScript.src =
'https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js';\n",
+ " datatableScript.type = 'text/javascript';\n",
+ " datatableScript.onload = function() {\n",
+ " window.interactive_beam_jquery =
jQuery.noConflict(true);\n",
+ "
window.interactive_beam_jquery(document).ready(function($){\n",
+ " \n",
+ "
$(\"#progress_indicator_a986c6cc61ed5a5b622e163d92f73775\").remove();\n",
+ " });\n",
+ " }\n",
+ " document.head.appendChild(datatableScript);\n",
+ " };\n",
+ " document.head.appendChild(jqueryScript);\n",
+ " } else {\n",
+ "
window.interactive_beam_jquery(document).ready(function($){\n",
+ " \n",
+ "
$(\"#progress_indicator_a986c6cc61ed5a5b622e163d92f73775\").remove();\n",
+ " });\n",
+ " }"
+ ]
+ },
+ "metadata": {}
+ },
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " spk_id full_name near_earth_object
\\\n",
+ "0 2000001 1 Ceres N
\n",
+ "1 2000002 2 Pallas N
\n",
+ "2 2000003 3 Juno N
\n",
+ "3 2000004 4 Vesta N
\n",
+ "4 2000005 5 Astraea N
\n",
+ "... ... ... ...
\n",
+ "9994 2009995 9995 Alouette (4805 P-L) N
\n",
+ "9995 2009996 9996 ANS (9070 P-L) N
\n",
+ "9996 2009997 9997 COBE (1217 T-1) N
\n",
+ "9997 2009998 9998 ISO (1293 T-1) N
\n",
+ "9998 2009999 9999 Wiles (4196 T-2) N
\n",
+ "\n",
+ " absolute_magnitude diameter albedo diameter_sigma
eccentricity \\\n",
+ "0 3.40 939.400 0.0900 0.200
0.076009 \n",
+ "1 4.20 545.000 0.1010 18.000
0.229972 \n",
+ "2 5.33 246.596 0.2140 10.594
0.256936 \n",
+ "3 3.00 525.400 0.4228 0.200
0.088721 \n",
+ "4 6.90 106.699 0.2740 3.140
0.190913 \n",
+ "... ... ... ... ...
... \n",
+ "9994 15.10 2.564 0.2450 0.550
0.160610 \n",
+ "9995 13.60 8.978 0.1130 0.376
0.235174 \n",
+ "9996 14.30 NaN NaN NaN
0.113059 \n",
+ "9997 15.10 2.235 0.3880 0.373
0.093852 \n",
+ "9998 13.00 7.148 0.2620 0.065
0.071351 \n",
+ "\n",
+ " inclination moid_ld object_class
semi_major_axis_au_unit \\\n",
+ "0 10.594067 620.640533 MBA
2.769165 \n",
+ "1 34.832932 480.348639 MBA
2.773841 \n",
+ "2 12.991043 402.514639 MBA
2.668285 \n",
+ "3 7.141771 443.451432 MBA
2.361418 \n",
+ "4 5.367427 426.433027 MBA
2.574037 \n",
+ "... ... ... ...
... \n",
+ "9994 2.311731 388.723233 MBA
2.390249 \n",
+ "9995 7.657713 444.194746 MBA
2.796605 \n",
+ "9996 2.459643 495.460110 MBA
2.545674 \n",
+ "9997 3.912263 373.848377 MBA
2.160961 \n",
+ "9998 3.198839 632.144398 MBA
2.839917 \n",
+ "\n",
+ " hazardous_flag \n",
+ "0 N \n",
+ "1 N \n",
+ "2 N \n",
+ "3 N \n",
+ "4 N \n",
+ "... ... \n",
+ "9994 N \n",
+ "9995 N \n",
+ "9996 N \n",
+ "9997 N \n",
+ "9998 N \n",
+ "\n",
+ "[9999 rows x 13 columns]"
+ ],
+ "text/html": [
+ "\n",
+ " <div id=\"df-0161aa69-d50f-4d6f-84c1-10dacb278880\">\n",
+ " <div class=\"colab-df-container\">\n",
+ " <div>\n",
+ "<style scoped>\n",
+ " .dataframe tbody tr th:only-of-type {\n",
+ " vertical-align: middle;\n",
+ " }\n",
+ "\n",
+ " .dataframe tbody tr th {\n",
+ " vertical-align: top;\n",
+ " }\n",
+ "\n",
+ " .dataframe thead th {\n",
+ " text-align: right;\n",
+ " }\n",
+ "</style>\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>spk_id</th>\n",
+ " <th>full_name</th>\n",
+ " <th>near_earth_object</th>\n",
+ " <th>absolute_magnitude</th>\n",
+ " <th>diameter</th>\n",
+ " <th>albedo</th>\n",
+ " <th>diameter_sigma</th>\n",
+ " <th>eccentricity</th>\n",
+ " <th>inclination</th>\n",
+ " <th>moid_ld</th>\n",
+ " <th>object_class</th>\n",
+ " <th>semi_major_axis_au_unit</th>\n",
+ " <th>hazardous_flag</th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>0</th>\n",
+ " <td>2000001</td>\n",
+ " <td>1 Ceres</td>\n",
+ " <td>N</td>\n",
+ " <td>3.40</td>\n",
+ " <td>939.400</td>\n",
+ " <td>0.0900</td>\n",
+ " <td>0.200</td>\n",
+ " <td>0.076009</td>\n",
+ " <td>10.594067</td>\n",
+ " <td>620.640533</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.769165</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>1</th>\n",
+ " <td>2000002</td>\n",
+ " <td>2 Pallas</td>\n",
+ " <td>N</td>\n",
+ " <td>4.20</td>\n",
+ " <td>545.000</td>\n",
+ " <td>0.1010</td>\n",
+ " <td>18.000</td>\n",
+ " <td>0.229972</td>\n",
+ " <td>34.832932</td>\n",
+ " <td>480.348639</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.773841</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>2</th>\n",
+ " <td>2000003</td>\n",
+ " <td>3 Juno</td>\n",
+ " <td>N</td>\n",
+ " <td>5.33</td>\n",
+ " <td>246.596</td>\n",
+ " <td>0.2140</td>\n",
+ " <td>10.594</td>\n",
+ " <td>0.256936</td>\n",
+ " <td>12.991043</td>\n",
+ " <td>402.514639</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.668285</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>3</th>\n",
+ " <td>2000004</td>\n",
+ " <td>4 Vesta</td>\n",
+ " <td>N</td>\n",
+ " <td>3.00</td>\n",
+ " <td>525.400</td>\n",
+ " <td>0.4228</td>\n",
+ " <td>0.200</td>\n",
+ " <td>0.088721</td>\n",
+ " <td>7.141771</td>\n",
+ " <td>443.451432</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.361418</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>4</th>\n",
+ " <td>2000005</td>\n",
+ " <td>5 Astraea</td>\n",
+ " <td>N</td>\n",
+ " <td>6.90</td>\n",
+ " <td>106.699</td>\n",
+ " <td>0.2740</td>\n",
+ " <td>3.140</td>\n",
+ " <td>0.190913</td>\n",
+ " <td>5.367427</td>\n",
+ " <td>426.433027</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.574037</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>...</th>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " <td>...</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>9994</th>\n",
+ " <td>2009995</td>\n",
+ " <td>9995 Alouette (4805 P-L)</td>\n",
+ " <td>N</td>\n",
+ " <td>15.10</td>\n",
+ " <td>2.564</td>\n",
+ " <td>0.2450</td>\n",
+ " <td>0.550</td>\n",
+ " <td>0.160610</td>\n",
+ " <td>2.311731</td>\n",
+ " <td>388.723233</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.390249</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>9995</th>\n",
+ " <td>2009996</td>\n",
+ " <td>9996 ANS (9070 P-L)</td>\n",
+ " <td>N</td>\n",
+ " <td>13.60</td>\n",
+ " <td>8.978</td>\n",
+ " <td>0.1130</td>\n",
+ " <td>0.376</td>\n",
+ " <td>0.235174</td>\n",
+ " <td>7.657713</td>\n",
+ " <td>444.194746</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.796605</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>9996</th>\n",
+ " <td>2009997</td>\n",
+ " <td>9997 COBE (1217 T-1)</td>\n",
+ " <td>N</td>\n",
+ " <td>14.30</td>\n",
+ " <td>NaN</td>\n",
+ " <td>NaN</td>\n",
+ " <td>NaN</td>\n",
+ " <td>0.113059</td>\n",
+ " <td>2.459643</td>\n",
+ " <td>495.460110</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.545674</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>9997</th>\n",
+ " <td>2009998</td>\n",
+ " <td>9998 ISO (1293 T-1)</td>\n",
+ " <td>N</td>\n",
+ " <td>15.10</td>\n",
+ " <td>2.235</td>\n",
+ " <td>0.3880</td>\n",
+ " <td>0.373</td>\n",
+ " <td>0.093852</td>\n",
+ " <td>3.912263</td>\n",
+ " <td>373.848377</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.160961</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>9998</th>\n",
+ " <td>2009999</td>\n",
+ " <td>9999 Wiles (4196 T-2)</td>\n",
+ " <td>N</td>\n",
+ " <td>13.00</td>\n",
+ " <td>7.148</td>\n",
+ " <td>0.2620</td>\n",
+ " <td>0.065</td>\n",
+ " <td>0.071351</td>\n",
+ " <td>3.198839</td>\n",
+ " <td>632.144398</td>\n",
+ " <td>MBA</td>\n",
+ " <td>2.839917</td>\n",
+ " <td>N</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "<p>9999 rows × 13 columns</p>\n",
+ "</div>\n",
+ " <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-0161aa69-d50f-4d6f-84c1-10dacb278880')\"\n",
+ " title=\"Convert this dataframe to an interactive
table.\"\n",
+ " style=\"display:none;\">\n",
+ " \n",
+ " <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\"viewBox=\"0 0 24 24\"\n",
+ " width=\"24px\">\n",
+ " <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n",
+ " <path d=\"M18.56 5.44l.94 2.06.94-2.06
2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06
2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06
2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41
7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72
7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2
1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72
1.47 1.35L5.41 20z\"/>\n",
+ " </svg>\n",
+ " </button>\n",
+ " \n",
+ " <style>\n",
+ " .colab-df-container {\n",
+ " display:flex;\n",
+ " flex-wrap:wrap;\n",
+ " gap: 12px;\n",
+ " }\n",
+ "\n",
+ " .colab-df-convert {\n",
+ " background-color: #E8F0FE;\n",
+ " border: none;\n",
+ " border-radius: 50%;\n",
+ " cursor: pointer;\n",
+ " display: none;\n",
+ " fill: #1967D2;\n",
+ " height: 32px;\n",
+ " padding: 0 0 0 0;\n",
+ " width: 32px;\n",
+ " }\n",
+ "\n",
+ " .colab-df-convert:hover {\n",
+ " background-color: #E2EBFA;\n",
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px
3px 1px rgba(60, 64, 67, 0.15);\n",
+ " fill: #174EA6;\n",
+ " }\n",
+ "\n",
+ " [theme=dark] .colab-df-convert {\n",
+ " background-color: #3B4455;\n",
+ " fill: #D2E3FC;\n",
+ " }\n",
+ "\n",
+ " [theme=dark] .colab-df-convert:hover {\n",
+ " background-color: #434B5C;\n",
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
+ " fill: #FFFFFF;\n",
+ " }\n",
+ " </style>\n",
+ "\n",
+ " <script>\n",
+ " const buttonEl =\n",
+ "
document.querySelector('#df-0161aa69-d50f-4d6f-84c1-10dacb278880
button.colab-df-convert');\n",
+ " buttonEl.style.display =\n",
+ " google.colab.kernel.accessAllowed ? 'block' :
'none';\n",
+ "\n",
+ " async function convertToInteractive(key) {\n",
+ " const element =
document.querySelector('#df-0161aa69-d50f-4d6f-84c1-10dacb278880');\n",
+ " const dataTable =\n",
+ " await
google.colab.kernel.invokeFunction('convertToInteractive',\n",
+ " [key],
{});\n",
+ " if (!dataTable) return;\n",
+ "\n",
+ " const docLinkHtml = 'Like what you see? Visit the '
+\n",
+ " '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n",
+ " + ' to learn more about interactive tables.';\n",
+ " element.innerHTML = '';\n",
+ " dataTable['output_type'] = 'display_data';\n",
+ " await google.colab.output.renderOutput(dataTable,
element);\n",
+ " const docLink = document.createElement('div');\n",
+ " docLink.innerHTML = docLinkHtml;\n",
+ " element.appendChild(docLink);\n",
+ " }\n",
+ " </script>\n",
+ " </div>\n",
+ " </div>\n",
+ " "
+ ]
+ },
+ "metadata": {},
+ "execution_count": 5
+ }
+ ],
+ "source": [
+ "ib.collect(beam_df)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "We can see that our datasets consists of both:\n",
+ "\n",
+ "* **Numerical columns:** These columns need to be transformed through
[normalization](https://en.wikipedia.org/wiki/Normalization_(statistics))
before they can be used for training a machine learning model.\n",
+ "\n",
+ "* **Categorical columns:** We need to transform those columns with
[one-hot
encoding](https://machinelearningmastery.com/why-one-hot-encode-data-in-machine-learning/)
to use them during training. \n"
+ ],
+ "metadata": {
+ "id": "8jV9odKhNyF2"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "D9uJtHLSSAMC"
+ },
+ "source": [
+ "Before executing any transformations, we need to check if all the
columns can be used for model training. Let's first have a look at the column
description as provided by the [JPL
website](https://ssd.jpl.nasa.gov/sbdb_query.cgi):\n",
Review Comment:
woops need to be used indeed :) nice catch!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]