"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "compound-criminal"
},
"source": [
"Se puede trabajar en Google Colab. Para ello es necesario contar con una cuenta de **google drive** y ejecutar un notebook almacenado en dicha cuenta. De lo contrario, no se conservarán los cambios realizados en la sesión. En caso de ya contar con una cuenta, se puede abrir el notebook y luego ir a `Archivo-->Guardar una copia en drive`. "
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "e_rith_Skga5"
},
"source": [
"La siguiente celda monta el disco personal del drive:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"executionInfo": {
"elapsed": 21875,
"status": "ok",
"timestamp": 1645451536176,
"user": {
"displayName": "Emiliano Acevedo",
"photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
"userId": "09255842080725499836"
},
"user_tz": 180
},
"id": "timely-power",
"outputId": "9b878f94-05b8-4598-baa4-08a3e132868d"
},
"outputs": [],
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "9WC47WBdkeqj"
},
"source": [
"A continuación, vaya a su cuenta de [Kaggle](https://www.kaggle.com/) (o cree una si aún no lo ha hecho), haga clic en el icono de perfil en la esquina superior derecha de la pantalla y seleccione \"Your Account\" en la lista desplegable. Luego, seleccione la viñeta \"Account\" y haga clic en \"Create new API token\". Entonces un archivo llamado kaggle.json se descargará automáticamente a su carpeta de descargas. Este archivo contiene sus credenciales de inicio de sesión para permitirle acceder a la API."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "changing-enhancement"
},
"source": [
"La siguiente celda realiza la configuración necesaria para obtener datos desde la plataforma Kaggle. Le solicitará que suba el archivo kaggle.json descargado anteriormente."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 90,
"resources": {
"http://localhost:8080/nbextensions/google.colab/files.js": {
"data": "Ly8gQ29weXJpZ2h0IDIwMTcgR29vZ2xlI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ICAgICAgfTsKICAgICAgcmVhZGVyLnJlYWRBc0FycmF5QnVmZmVyKGZpbGUpOwogICAgfSk7CiAgICAvLyBXYWl0IGZvciB0aGUgZGF0YSB0byBiZSByZWFkeS4KICAgIGxldCBmaWxlRGF0YSA9IHlpZWxkIHsKICAgICAgcHJvbWlzZTogZmlsZURhdGFQcm9taXNlLAogICAgICByZXNwb25zZTogewogICAgICAgIGFjdGlvbjogJ2NvbnRpbnVlJywKICAgICAgfQogICAgfTsKCiAgICAvLyBVc2UgYSBjaHVua2VkIHNlbmRpbmcgdG8gYXZvaWQgbWVzc2FnZSBzaXplIGxpbWl0cy4gU2VlIGIvNjIxMTU2NjAuCiAgICBsZXQgcG9zaXRpb24gPSAwOwogICAgZG8gewogICAgICBjb25zdCBsZW5ndGggPSBNYXRoLm1pbihmaWxlRGF0YS5ieXRlTGVuZ3RoIC0gcG9zaXRpb24sIE1BWF9QQVlMT0FEX1NJWkUpOwogICAgICBjb25zdCBjaHVuayA9IG5ldyBVaW50OEFycmF5KGZpbGVEYXRhLCBwb3NpdGlvbiwgbGVuZ3RoKTsKICAgICAgcG9zaXRpb24gKz0gbGVuZ3RoOwoKICAgICAgY29uc3QgYmFzZTY0ID0gYnRvYShTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIGNodW5rKSk7CiAgICAgIHlpZWxkIHsKICAgICAgICByZXNwb25zZTogewogICAgICAgICAgYWN0aW9uOiAnYXBwZW5kJywKICAgICAgICAgIGZpbGU6IGZpbGUubmFtZSwKICAgICAgICAgIGRhdGE6IGJhc2U2NCwKICAgICAgICB9LAogICAgICB9OwoKICAgICAgbGV0IHBlcmNlbnREb25lID0gZmlsZURhdGEuYnl0ZUxlbmd0aCA9PT0gMCA/CiAgICAgICAgICAxMDAgOgogICAgICAgICAgTWF0aC5yb3VuZCgocG9zaXRpb24gLyBmaWxlRGF0YS5ieXRlTGVuZ3RoKSAqIDEwMCk7CiAgICAgIHBlcmNlbnQudGV4dENvbnRlbnQgPSBgJHtwZXJjZW50RG9uZX0lIGRvbmVgOwoKICAgIH0gd2hpbGUgKHBvc2l0aW9uIDwgZmlsZURhdGEuYnl0ZUxlbmd0aCk7CiAgfQoKICAvLyBBbGwgZG9uZS4KICB5aWVsZCB7CiAgICByZXNwb25zZTogewogICAgICBhY3Rpb246ICdjb21wbGV0ZScsCiAgICB9CiAgfTsKfQoKc2NvcGUuZ29vZ2xlID0gc2NvcGUuZ29vZ2xlIHx8IHt9OwpzY29wZS5nb29nbGUuY29sYWIgPSBzY29wZS5nb29nbGUuY29sYWIgfHwge307CnNjb3BlLmdvb2dsZS5jb2xhYi5fZmlsZXMgPSB7CiAgX3VwbG9hZEZpbGVzLAogIF91cGxvYWRGaWxlc0NvbnRpbnVlLAp9Owp9KShzZWxmKTsK",
"headers": [
[
"content-type",
"application/javascript"
]
],
"ok": true,
"status": 200,
"status_text": ""
}
}
},
"executionInfo": {
"elapsed": 31400,
"status": "ok",
"timestamp": 1645451632279,
"user": {
"displayName": "Emiliano Acevedo",
"photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
"userId": "09255842080725499836"
},
"user_tz": 180
},
"id": "convinced-person",
"outputId": "59951021-dcb6-4622-e24e-062806a6ce7f"
},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')\n",
"from google.colab import files\n",
"\n",
"# El siguiente archivo solicitado es para habilitar la API de Kaggle en el entorno que está trabajando.\n",
"# Este archivo se descarga entrando a su perfíl de Kaggle, en la sección API, presionando donde dice: Create New API Token\n",
"\n",
"uploaded = files.upload()\n",
"\n",
"for fn in uploaded.keys():\n",
" print('User uploaded file \"{name}\" with length {length} bytes'.format(\n",
" name=fn, length=len(uploaded[fn])))\n",
"\n",
"#Then move kaggle.json into the folder where the API expects to find it.\n",
"!mkdir -p ~/.kaggle/ && mv kaggle.json ~/.kaggle/ && chmod 600 ~/.kaggle/kaggle.json"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "fossil-australian"
},
"source": [
"Una vez guardado el *token* se pueden descargar los datos, en este caso se bajarán los datos del dataset de Demanda de Bicicletas:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2022-04-06T08:18:39.849067Z",
"start_time": "2022-04-06T08:18:38.482792Z"
},
"colab": {
"base_uri": "https://localhost:8080/"
},
"executionInfo": {
"elapsed": 2104,
"status": "ok",
"timestamp": 1645451663400,
"user": {
"displayName": "Emiliano Acevedo",
"photoUrl": "https://lh3.googleusercontent.com/a/default-user=s64",
"userId": "09255842080725499836"
},
"user_tz": 180
},
"id": "independent-eagle",
"outputId": "bfe00bd3-81a5-487f-e60f-8b6e2ce1a189"
},
"outputs": [],
"source": [
"!kaggle competitions download -c bike-sharing-demand"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2022-04-06T08:19:07.842906Z",
"start_time": "2022-04-06T08:18:41.405686Z"
}
},
"outputs": [],
"source": [
"!unzip bike-sharing-demand.zip"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Paquetes a utilizar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"En esta actividad se utilizarán algunas bibliotecas auxiliares que deberán ser instaladas. Ejecutar la siguiente celda hasta que se ejecute sin errores. En caso de error, se puede instalar el paquete faltante desde el notebook con el comando:\n",
"\n",
"`!pip install paquete_faltante`"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2022-04-06T08:45:12.980879Z",
"start_time": "2022-04-06T08:45:10.992955Z"
}
},
"outputs": [],
"source": [
"#import comet_ml in the top of your file\n",
"from comet_ml import Experiment\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"#import seaborn as sns\n",
"#sns.set_theme(style=\"whitegrid\")\n",
"\n",
"df_train = pd.read_csv('train.csv')\n",
"df_test = pd.read_csv('test.csv')\n",
"df_submission = pd.read_csv('sampleSubmission.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "HQi0j-avej0Q"
},
"source": [
"## Parte 1 - Procesamiento de los datos\n",
"\n",
"Dado que ya se ha familiarizado con los datos, se implementa el mismo preprocesamiento que utilizó en el Taller 3."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2022-04-06T08:45:17.367597Z",
"start_time": "2022-04-06T08:45:17.333795Z"
},
"id": "WAJk7qqqphJa"
},
"outputs": [],
"source": [
"df_train['datetime'] = pd.to_datetime(df_train['datetime'])\n",
"\n",
"df_train['hour'] = df_train['datetime'].dt.hour\n",
"df_train['weekday'] = df_train['datetime'].dt.weekday\n",
"df_train['month'] = df_train['datetime'].dt.month \n",
"df_train['year'] = df_train['datetime'].dt.year\n",
"\n",
"y_train_full = df_train['count']\n",
"df_train = df_train.drop(['datetime', 'casual', 'registered', 'count'], axis=1) # hay que eliminarlas ya que tiene relación directa con la columna objetivo y no aparecen en el conjunto de *test*."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"- Dado que se trabajará con redes neuronales, ¿Cree conveniente realizar alguna modificación en el preprocesamiento?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2022-04-06T08:45:19.115054Z",
"start_time": "2022-04-06T08:45:19.108573Z"
},
"id": "3RotPZI9O67F"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "nyhdy7JagA0k"
},
"source": [
"## Parte 2 - Multilayer Perceptron (MLP)\n",
"\n",
"Siguiendo el ejemplo de la sección *Building a Regression MLP Using the Sequential API*:\n",
"\n",
"\n",
"* Implementar un estimador manteniendo los hiperparámetros del ejemplo.\n",
"* ¿Cuál es la cantidad total de parámetros entrenables de la red?\n",
"* Seleccionar aleatoriamente un *10%* de los datos para validación, y graficar la función de *loss* (*Mean Squared Logarithmic Error*) de entrenamiento y validación.\n",
"\n",
"***Nota:** Observe que en el ejemplo se agrega una capa de normalización*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "jzchTK1jrIxA"
},
"source": [
"## Parte 3 - Ajuste fino\n",
"\n",
"Siguiendo el ejemplo de la sección *Fine-Tuning Neural Network Hyperparameters*:\n",
"\n",
"\n",
"* Utilizar la herramienta *RandomSearch* de *KerasTuner* para la busqueda de hiperparámetros del modelo implementado en *keras*. \n",
"* Probar el *tip* que se sugiere en la sección *Number of Neurons per Hidden Layer* y comentar los resultados."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "HmUt2QrywG60"
},
"source": [
"## Parte 4 - Ajuste fino (Optuna)\n",
"\n",
"* Utilizar *Optuna* para la busqueda de hiperparámetros del modelo en *Keras*. Se le sugiere seguir uno de los siguientes ejemplos: [*keras_simple*](https://github.com/optuna/optuna-examples/blob/main/keras/keras_simple.py), [OptunaSearchCV](https://github.com/optuna/optuna-examples/blob/main/sklearn/sklearn_optuna_search_cv_simple.py).\n",
"\n",
"***Nota:** Optuna puede utilizarse para optimizar otras técnicas por fuera de las redes neuronales.*\n",
"\n",
"***Nota2:** Keras Tuner permite realizar Optimización bayesiana.*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "0DM4D3m-1X64",
"outputId": "b2ed6754-9b75-4a83-8e61-c3e8394b613a"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"id": "cQoU9uS1lkM0"
},
"source": [
"## Parte 5 - Pipeline\n",
"\n",
"\n",
"\n",
"* Incorporar el estimador con mejor desempeño a un *pipeline* similar al implementado en el taller 3. Puede ser útil la librería [scikeras](https://adriangb.com/scikeras/stable/migration.html).\n",
"* Subir los resultados de los datos *test* a la página de la competencia.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "hXPwnG-rhKN2",
"outputId": "1f40a4c8-e48a-4cdb-bf22-03e86d33ae5e"
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parte 6 - Shapley Values\n",
"\n",
"- Siguiendo el [ejemplo](https://shap.readthedocs.io/en/latest/example_notebooks/overviews/An%20introduction%20to%20explainable%20AI%20with%20Shapley%20values.html) presentado en la sección *Explaining a non-additive boosted tree model* de la librería *shap*. Encuentre los shapley values para el mejor modelo que haya encontrado.\n",
"- Elija una muestra y mediante la función *shap.plots.waterfall* observe la explicación de la predicción del modelo.\n",
"\n",
"Más explicación de los Shapley Values y su uso en la interpretabilidad de modelos de aprendizaje automático se puede encontrar [aquí](https://christophm.github.io/interpretable-ml-book/shapley.html)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "Taller5_demanda_de_bicicletas_con_NNs_solucion.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "cf9ed6eb9f80a715f753bb5491e7f879990bf814a1e5372a2cadce9b619c9f4f"
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}