{ "cells": [ { "cell_type": "markdown", "id": "9c0b037c-8235-4578-acdd-5dc5418fb36c", "metadata": {}, "source": [ "# Clustering **k-Means**\n", "## por módulos (no por tiempo)\n", "\n", "Técnica descriptiva que genera *k* clusters (agrupaciones) de los datos numéricos (porque calcula distancias), tal que los datos dentro de un cluster sean lo más parecidos entre ellos, pero que cad cluster sea lo más diferente a los demás\n", "\n", "El resultado de esta técnica es un modelo en forma de centroides, uno por cada cluster que caracteriza o describe al cluster al que pertenece." ] }, { "cell_type": "code", "execution_count": 15, "id": "8fef52ea-af00-49dc-812c-f6eced9c6330", "metadata": {}, "outputs": [], "source": [ "# Bibliotecas\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "\n", "## Clustering\n", "from sklearn.cluster import KMeans " ] }, { "cell_type": "markdown", "id": "e50e7a2b-e1a5-4031-8157-f25089969c44", "metadata": {}, "source": [ "## Carga de datos" ] }, { "cell_type": "code", "execution_count": 16, "id": "fa3ff14d-339b-4390-8e64-3875e2ac450b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Etiquetas de filaassignsubmission_commentsassignsubmission_fileassignsubmission_onlinetextblock_commentsbooktool_printcoregradereport_usermod_activequizmod_assign...mod_quizmod_resourcemod_scormmod_surveymod_taskchainmod_urlmod_wikimod_workshoptool_usertoursUnnamed: 40
0130.02.06.00.00.00.01.04.00.04.0...2.03.00.00.00.00.00.00.00.0NaN
1162.00.00.00.00.00.01.00.00.00.0...0.00.00.00.00.00.00.00.00.0NaN
2176.00.00.00.00.00.01.00.00.00.0...0.00.00.00.00.00.00.00.00.0NaN
3187.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.0NaN
4188.00.00.00.00.00.01.00.00.00.0...0.00.00.00.00.00.00.00.00.0NaN
..................................................................
38997957.00.00.00.00.00.01.02.04.00.0...0.04.00.00.00.04.00.00.00.0NaN
39007958.05.022.00.00.00.00.08.00.08.0...19.010.00.00.00.010.00.00.00.0NaN
39017967.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.0NaN
39027969.00.00.00.00.00.00.02.00.00.0...9.04.00.00.00.00.00.00.00.0NaN
3903NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "

3904 rows × 41 columns

\n", "
" ], "text/plain": [ " Etiquetas de fila assignsubmission_comments assignsubmission_file \\\n", "0 130.0 2.0 6.0 \n", "1 162.0 0.0 0.0 \n", "2 176.0 0.0 0.0 \n", "3 187.0 0.0 0.0 \n", "4 188.0 0.0 0.0 \n", "... ... ... ... \n", "3899 7957.0 0.0 0.0 \n", "3900 7958.0 5.0 22.0 \n", "3901 7967.0 0.0 0.0 \n", "3902 7969.0 0.0 0.0 \n", "3903 NaN NaN NaN \n", "\n", " assignsubmission_onlinetext block_comments booktool_print core \\\n", "0 0.0 0.0 0.0 1.0 \n", "1 0.0 0.0 0.0 1.0 \n", "2 0.0 0.0 0.0 1.0 \n", "3 0.0 0.0 0.0 0.0 \n", "4 0.0 0.0 0.0 1.0 \n", "... ... ... ... ... \n", "3899 0.0 0.0 0.0 1.0 \n", "3900 0.0 0.0 0.0 0.0 \n", "3901 0.0 0.0 0.0 0.0 \n", "3902 0.0 0.0 0.0 0.0 \n", "3903 NaN NaN NaN NaN \n", "\n", " gradereport_user mod_activequiz mod_assign ... mod_quiz \\\n", "0 4.0 0.0 4.0 ... 2.0 \n", "1 0.0 0.0 0.0 ... 0.0 \n", "2 0.0 0.0 0.0 ... 0.0 \n", "3 0.0 0.0 0.0 ... 0.0 \n", "4 0.0 0.0 0.0 ... 0.0 \n", "... ... ... ... ... ... \n", "3899 2.0 4.0 0.0 ... 0.0 \n", "3900 8.0 0.0 8.0 ... 19.0 \n", "3901 0.0 0.0 0.0 ... 0.0 \n", "3902 2.0 0.0 0.0 ... 9.0 \n", "3903 NaN NaN NaN ... NaN \n", "\n", " mod_resource mod_scorm mod_survey mod_taskchain mod_url mod_wiki \\\n", "0 3.0 0.0 0.0 0.0 0.0 0.0 \n", "1 0.0 0.0 0.0 0.0 0.0 0.0 \n", "2 0.0 0.0 0.0 0.0 0.0 0.0 \n", "3 0.0 0.0 0.0 0.0 0.0 0.0 \n", "4 0.0 0.0 0.0 0.0 0.0 0.0 \n", "... ... ... ... ... ... ... \n", "3899 4.0 0.0 0.0 0.0 4.0 0.0 \n", "3900 10.0 0.0 0.0 0.0 10.0 0.0 \n", "3901 0.0 0.0 0.0 0.0 0.0 0.0 \n", "3902 4.0 0.0 0.0 0.0 0.0 0.0 \n", "3903 NaN NaN NaN NaN NaN NaN \n", "\n", " mod_workshop tool_usertours Unnamed: 40 \n", "0 0.0 0.0 NaN \n", "1 0.0 0.0 NaN \n", "2 0.0 0.0 NaN \n", "3 0.0 0.0 NaN \n", "4 0.0 0.0 NaN \n", "... ... ... ... \n", "3899 0.0 0.0 NaN \n", "3900 0.0 0.0 NaN \n", "3901 0.0 0.0 NaN \n", "3902 0.0 0.0 NaN \n", "3903 NaN NaN NaN \n", "\n", "[3904 rows x 41 columns]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv ('/Users/josel/datosAulas/aulas_con_modulo.csv');\n", "df" ] }, { "cell_type": "markdown", "id": "352a01a7-dbec-4958-803b-1a47ac7cbc9a", "metadata": {}, "source": [ "## Tipos de datos" ] }, { "cell_type": "code", "execution_count": 17, "id": "93d5c16f-f240-4f74-9076-27d45172705b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Etiquetas de fila float64\n", "assignsubmission_comments float64\n", "assignsubmission_file float64\n", "assignsubmission_onlinetext float64\n", "block_comments float64\n", "booktool_print float64\n", "core float64\n", "gradereport_user float64\n", "mod_activequiz float64\n", "mod_assign float64\n", "mod_attendance float64\n", "mod_book float64\n", "mod_chat float64\n", "mod_checklist float64\n", "mod_choice float64\n", "mod_data float64\n", "mod_feedback float64\n", "mod_folder float64\n", "mod_forum float64\n", "mod_geogebra float64\n", "mod_glossary float64\n", "mod_groupselect float64\n", "mod_hotpot float64\n", "mod_hvp float64\n", "mod_jclic float64\n", "mod_journal float64\n", "mod_lesson float64\n", "mod_lightboxgallery float64\n", "mod_page float64\n", "mod_publication float64\n", "mod_questionnaire float64\n", "mod_quiz float64\n", "mod_resource float64\n", "mod_scorm float64\n", "mod_survey float64\n", "mod_taskchain float64\n", "mod_url float64\n", "mod_wiki float64\n", "mod_workshop float64\n", "tool_usertours float64\n", "Unnamed: 40 float64\n", "dtype: object" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.dtypes" ] }, { "cell_type": "code", "execution_count": 40, "id": "2d3da752-43c0-46cb-a0cf-048e1a75d75d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
assignsubmission_commentsassignsubmission_fileassignsubmission_onlinetextblock_commentsbooktool_printcoregradereport_usermod_activequizmod_assignmod_attendance...mod_questionnairemod_quizmod_resourcemod_scormmod_surveymod_taskchainmod_urlmod_wikimod_workshoptool_usertours
02.06.00.00.00.01.04.00.04.01.0...0.02.03.00.00.00.00.00.00.00.0
10.00.00.00.00.01.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
20.00.00.00.00.01.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
30.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
40.00.00.00.00.01.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
..................................................................
38980.00.00.00.00.00.03.00.00.00.0...0.00.03.00.00.00.00.00.00.00.0
38990.00.00.00.00.01.02.04.00.00.0...0.00.04.00.00.00.04.00.00.00.0
39005.022.00.00.00.00.08.00.08.00.0...0.019.010.00.00.00.010.00.00.00.0
39010.00.00.00.00.00.00.00.00.00.0...0.00.00.00.00.00.00.00.00.00.0
39020.00.00.00.00.00.02.00.00.00.0...0.09.04.00.00.00.00.00.00.00.0
\n", "

3903 rows × 39 columns

\n", "
" ], "text/plain": [ " assignsubmission_comments assignsubmission_file \\\n", "0 2.0 6.0 \n", "1 0.0 0.0 \n", "2 0.0 0.0 \n", "3 0.0 0.0 \n", "4 0.0 0.0 \n", "... ... ... \n", "3898 0.0 0.0 \n", "3899 0.0 0.0 \n", "3900 5.0 22.0 \n", "3901 0.0 0.0 \n", "3902 0.0 0.0 \n", "\n", " assignsubmission_onlinetext block_comments booktool_print core \\\n", "0 0.0 0.0 0.0 1.0 \n", "1 0.0 0.0 0.0 1.0 \n", "2 0.0 0.0 0.0 1.0 \n", "3 0.0 0.0 0.0 0.0 \n", "4 0.0 0.0 0.0 1.0 \n", "... ... ... ... ... \n", "3898 0.0 0.0 0.0 0.0 \n", "3899 0.0 0.0 0.0 1.0 \n", "3900 0.0 0.0 0.0 0.0 \n", "3901 0.0 0.0 0.0 0.0 \n", "3902 0.0 0.0 0.0 0.0 \n", "\n", " gradereport_user mod_activequiz mod_assign mod_attendance ... \\\n", "0 4.0 0.0 4.0 1.0 ... \n", "1 0.0 0.0 0.0 0.0 ... \n", "2 0.0 0.0 0.0 0.0 ... \n", "3 0.0 0.0 0.0 0.0 ... \n", "4 0.0 0.0 0.0 0.0 ... \n", "... ... ... ... ... ... \n", "3898 3.0 0.0 0.0 0.0 ... \n", "3899 2.0 4.0 0.0 0.0 ... \n", "3900 8.0 0.0 8.0 0.0 ... \n", "3901 0.0 0.0 0.0 0.0 ... \n", "3902 2.0 0.0 0.0 0.0 ... \n", "\n", " mod_questionnaire mod_quiz mod_resource mod_scorm mod_survey \\\n", "0 0.0 2.0 3.0 0.0 0.0 \n", "1 0.0 0.0 0.0 0.0 0.0 \n", "2 0.0 0.0 0.0 0.0 0.0 \n", "3 0.0 0.0 0.0 0.0 0.0 \n", "4 0.0 0.0 0.0 0.0 0.0 \n", "... ... ... ... ... ... \n", "3898 0.0 0.0 3.0 0.0 0.0 \n", "3899 0.0 0.0 4.0 0.0 0.0 \n", "3900 0.0 19.0 10.0 0.0 0.0 \n", "3901 0.0 0.0 0.0 0.0 0.0 \n", "3902 0.0 9.0 4.0 0.0 0.0 \n", "\n", " mod_taskchain mod_url mod_wiki mod_workshop tool_usertours \n", "0 0.0 0.0 0.0 0.0 0.0 \n", "1 0.0 0.0 0.0 0.0 0.0 \n", "2 0.0 0.0 0.0 0.0 0.0 \n", "3 0.0 0.0 0.0 0.0 0.0 \n", "4 0.0 0.0 0.0 0.0 0.0 \n", "... ... ... ... ... ... \n", "3898 0.0 0.0 0.0 0.0 0.0 \n", "3899 0.0 4.0 0.0 0.0 0.0 \n", "3900 0.0 10.0 0.0 0.0 0.0 \n", "3901 0.0 0.0 0.0 0.0 0.0 \n", "3902 0.0 0.0 0.0 0.0 0.0 \n", "\n", "[3903 rows x 39 columns]" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#df=df.drop(3903)\n", "df" ] }, { "cell_type": "markdown", "id": "5fca3caf-a1d7-4408-913c-64f39394838a", "metadata": {}, "source": [ "## Correlaciones" ] }, { "cell_type": "code", "execution_count": 5, "id": "1836d532-0583-4e7f-83fc-be5fbb201f05", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Etiquetas de filaassignsubmission_commentsassignsubmission_fileassignsubmission_onlinetextblock_commentsbooktool_printcoregradereport_usermod_activequizmod_assign...mod_quizmod_resourcemod_scormmod_surveymod_taskchainmod_urlmod_wikimod_workshoptool_usertoursUnnamed: 40
Etiquetas de fila1.0000000.1767540.1843630.0961110.0109370.047675-0.1487650.2594130.0123910.198368...0.1459970.2102220.0189630.0136920.0197190.155911-0.0037460.0182890.037782NaN
assignsubmission_comments0.1767541.0000000.9347970.4930970.0954650.1895070.2216260.7534330.0728730.924896...0.5279710.6582170.0986130.0631410.0287020.6032090.1307920.1276610.054523NaN
assignsubmission_file0.1843630.9347971.0000000.4709800.1093360.2018930.2145610.7955800.0817000.952034...0.5699630.7146610.1333800.0704780.0212960.6446200.1384920.1372510.050285NaN
assignsubmission_onlinetext0.0961110.4930970.4709801.0000000.0447100.1410570.2213500.4064710.0394630.514710...0.2753720.3364610.1596410.0138180.0404500.3870200.0699420.1043250.000908NaN
block_comments0.0109370.0954650.1093360.0447101.0000000.0121070.0864620.0790940.0269670.102808...0.0939020.0840650.0062250.055597-0.0012950.0952600.008548-0.0038490.070047NaN
booktool_print0.0476750.1895070.2018930.1410570.0121071.0000000.0750960.2032810.0779020.201229...0.2499520.1606780.1912390.000033-0.0038610.1285320.0233260.1446440.005141NaN
core-0.1487650.2216260.2145610.2213500.0864620.0750961.0000000.1595620.0959930.230445...0.1945190.1693880.097120-0.012443-0.0093470.2236950.0494040.1439560.053809NaN
gradereport_user0.2594130.7534330.7955800.4064710.0790940.2032810.1595621.0000000.0813830.801752...0.7013420.7626210.0904110.0765190.0160820.6728180.1257030.1488210.069442NaN
mod_activequiz0.0123910.0728730.0817000.0394630.0269670.0779020.0959930.0813831.0000000.074123...0.0806100.0405730.097648-0.003043-0.0016280.0571040.0096870.0752830.038808NaN
mod_assign0.1983680.9248960.9520340.5147100.1028080.2012290.2304450.8017520.0741231.000000...0.5594850.7075490.1264050.0499670.0274290.6512890.1367640.1453880.041429NaN
mod_attendance0.0473400.1121280.1706760.111297-0.0053210.0667100.0791820.1576880.0406020.167318...0.0943170.1581010.0887210.008484-0.0031610.1402340.0553740.137911-0.008991NaN
mod_book0.1018340.3479950.3725600.3000520.0090540.5474620.1023160.3775910.0475020.387625...0.3441510.3042110.1474960.009700-0.0089980.2593700.0715020.1856550.026645NaN
mod_chat0.0296770.2345590.2356820.1370100.0410240.0232850.0910000.2089740.0653090.236664...0.1598150.196099-0.0037770.0071510.0226060.2285400.0975490.287649-0.002209NaN
mod_checklist0.0374520.1490060.1350020.2550070.0387760.0574500.0609650.1177250.0863680.143333...0.0950410.0815940.041865-0.003200-0.0017120.079987-0.0064760.000587-0.004869NaN
mod_choice0.0241670.0993130.1514150.250549-0.0039250.2160010.1222570.1170700.0424420.134040...0.1389310.1070190.3580230.0009290.0215510.1346020.0726690.0178250.001207NaN
mod_data0.0071510.1072550.1324420.164760-0.0045940.0439990.1334930.1227690.0534440.121242...0.1273510.0872620.1183940.035810-0.0027290.1395920.0417560.1516880.006235NaN
mod_feedback-0.0238270.0620450.0615790.084594-0.002737-0.0081590.0149730.086300-0.0034400.076330...0.0809590.083243-0.004420-0.003039-0.0016260.0592250.0131420.0413590.028432NaN
mod_folder0.0825730.4040440.4496120.2544460.0597620.0975400.1128830.4559070.0093350.457499...0.3438140.4583550.0575350.0679260.0293580.4678730.1293810.1087030.018161NaN
mod_forum0.1529280.6109440.6177290.4947120.0575820.2421970.1832120.6072810.0704150.625155...0.4852840.5136360.1263160.0849090.0237070.5197610.1812860.2028210.053786NaN
mod_geogebra0.0223160.0908810.0811400.0394560.0435830.1693840.0044610.078386-0.0038770.090347...0.0757680.0665890.1609810.062033-0.0018320.076032-0.006933-0.005446-0.005212NaN
mod_glossary0.0962300.2655850.2738530.2557150.0059370.1083650.1231530.3034150.0356960.289306...0.2927570.2602240.0811670.0087120.0040160.2879970.1570720.3521350.009281NaN
mod_groupselect0.0059940.0523580.0394950.052524-0.0014130.1405030.0162970.055362-0.0017760.045276...0.0178670.029532-0.002282-0.0015690.2175620.0312170.0072840.181808-0.002388NaN
mod_hotpot0.0137620.1394750.1445340.1881340.0112630.174308-0.0053910.1165500.0452610.147093...0.1212000.1162830.252379-0.003865-0.0020680.0694740.028127-0.006145-0.005881NaN
mod_hvp0.1057060.2743730.2558980.2769840.0049200.0934360.1015460.2460900.0660900.281794...0.2161530.2089680.0443220.0408570.0162460.1981120.0018700.027653-0.002181NaN
mod_jclic0.0309680.1122330.0966520.1541220.0245670.0317270.0145070.0770630.0078820.102916...0.0770090.0643570.027558-0.002271-0.0012150.0391270.0010810.089913-0.003456NaN
mod_journal0.0469840.1278380.1315900.1147340.0012600.0387820.0029350.1260240.0713830.130355...0.0793150.1106390.0008070.0002050.0128820.0754870.1729390.168499-0.006500NaN
mod_lesson0.0387010.1899230.2214990.2744010.0071060.1806870.1830600.2136050.0434840.217176...0.2854660.1824080.318980-0.007441-0.0010510.2064380.1469560.248299-0.005555NaN
mod_lightboxgallery0.0463600.1389900.1542910.116454-0.0045780.0995150.0573200.1353530.0351550.136626...0.0356340.1314880.019447-0.005084-0.0027200.1132840.0836890.000785-0.007736NaN
mod_page0.1230470.4454430.4511600.433011-0.0049540.2317210.2225610.4470350.0515120.479471...0.3689800.4100010.1387510.018282-0.0060360.3895270.0667880.1889460.021025NaN
mod_publication0.0570830.0880570.1103900.0200830.024425-0.0130640.0188060.1598440.0521900.104196...0.0993690.144060-0.0074110.0066900.0093490.1556660.0606950.0500260.023771NaN
mod_questionnaire0.0375110.2444420.2892590.2023070.0145050.0818380.1343920.2582150.0640590.270605...0.2371160.2288460.107461-0.0068430.0219440.2375630.1037660.1666890.004093NaN
mod_quiz0.1459970.5279710.5699630.2753720.0939020.2499520.1945190.7013420.0806100.559485...1.0000000.5604620.1530140.0916360.0122920.5182360.0882680.1328360.083057NaN
mod_resource0.2102220.6582170.7146610.3364610.0840650.1606780.1693880.7626210.0405730.707549...0.5604621.0000000.1071210.0593090.0166420.7141450.1443420.1182340.059692NaN
mod_scorm0.0189630.0986130.1333800.1596410.0062250.1912390.0971200.0904110.0976480.126405...0.1530140.1071211.0000000.035960-0.0020910.1160240.0064110.001573-0.005949NaN
mod_survey0.0136920.0631410.0704780.0138180.0555970.000033-0.0124430.076519-0.0030430.049967...0.0916360.0593090.0359601.000000-0.0014380.060731-0.005440-0.004274-0.004090NaN
mod_taskchain0.0197190.0287020.0212960.040450-0.001295-0.003861-0.0093470.016082-0.0016280.027429...0.0122920.016642-0.002091-0.0014381.0000000.0265620.005077-0.002286-0.002188NaN
mod_url0.1559110.6032090.6446200.3870200.0952600.1285320.2236950.6728180.0571040.651289...0.5182360.7141450.1160240.0607310.0265621.0000000.1380670.1256280.060999NaN
mod_wiki-0.0037460.1307920.1384920.0699420.0085480.0233260.0494040.1257030.0096870.136764...0.0882680.1443420.006411-0.0054400.0050770.1380671.0000000.133049-0.008278NaN
mod_workshop0.0182890.1276610.1372510.104325-0.0038490.1446440.1439560.1488210.0752830.145388...0.1328360.1182340.001573-0.004274-0.0022860.1256280.1330491.0000000.037686NaN
tool_usertours0.0377820.0545230.0502850.0009080.0700470.0051410.0538090.0694420.0388080.041429...0.0830570.059692-0.005949-0.004090-0.0021880.060999-0.0082780.0376861.000000NaN
Unnamed: 40NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN...NaNNaNNaNNaNNaNNaNNaNNaNNaNNaN
\n", "

41 rows × 41 columns

\n", "
" ], "text/plain": [ " Etiquetas de fila assignsubmission_comments \\\n", "Etiquetas de fila 1.000000 0.176754 \n", "assignsubmission_comments 0.176754 1.000000 \n", "assignsubmission_file 0.184363 0.934797 \n", "assignsubmission_onlinetext 0.096111 0.493097 \n", "block_comments 0.010937 0.095465 \n", "booktool_print 0.047675 0.189507 \n", "core -0.148765 0.221626 \n", "gradereport_user 0.259413 0.753433 \n", "mod_activequiz 0.012391 0.072873 \n", "mod_assign 0.198368 0.924896 \n", "mod_attendance 0.047340 0.112128 \n", "mod_book 0.101834 0.347995 \n", "mod_chat 0.029677 0.234559 \n", "mod_checklist 0.037452 0.149006 \n", "mod_choice 0.024167 0.099313 \n", "mod_data 0.007151 0.107255 \n", "mod_feedback -0.023827 0.062045 \n", "mod_folder 0.082573 0.404044 \n", "mod_forum 0.152928 0.610944 \n", "mod_geogebra 0.022316 0.090881 \n", "mod_glossary 0.096230 0.265585 \n", "mod_groupselect 0.005994 0.052358 \n", "mod_hotpot 0.013762 0.139475 \n", "mod_hvp 0.105706 0.274373 \n", "mod_jclic 0.030968 0.112233 \n", "mod_journal 0.046984 0.127838 \n", "mod_lesson 0.038701 0.189923 \n", "mod_lightboxgallery 0.046360 0.138990 \n", "mod_page 0.123047 0.445443 \n", "mod_publication 0.057083 0.088057 \n", "mod_questionnaire 0.037511 0.244442 \n", "mod_quiz 0.145997 0.527971 \n", "mod_resource 0.210222 0.658217 \n", "mod_scorm 0.018963 0.098613 \n", "mod_survey 0.013692 0.063141 \n", "mod_taskchain 0.019719 0.028702 \n", "mod_url 0.155911 0.603209 \n", "mod_wiki -0.003746 0.130792 \n", "mod_workshop 0.018289 0.127661 \n", "tool_usertours 0.037782 0.054523 \n", "Unnamed: 40 NaN NaN \n", "\n", " assignsubmission_file \\\n", "Etiquetas de fila 0.184363 \n", "assignsubmission_comments 0.934797 \n", "assignsubmission_file 1.000000 \n", "assignsubmission_onlinetext 0.470980 \n", "block_comments 0.109336 \n", "booktool_print 0.201893 \n", "core 0.214561 \n", "gradereport_user 0.795580 \n", "mod_activequiz 0.081700 \n", "mod_assign 0.952034 \n", "mod_attendance 0.170676 \n", "mod_book 0.372560 \n", "mod_chat 0.235682 \n", "mod_checklist 0.135002 \n", "mod_choice 0.151415 \n", "mod_data 0.132442 \n", "mod_feedback 0.061579 \n", "mod_folder 0.449612 \n", "mod_forum 0.617729 \n", "mod_geogebra 0.081140 \n", "mod_glossary 0.273853 \n", "mod_groupselect 0.039495 \n", "mod_hotpot 0.144534 \n", "mod_hvp 0.255898 \n", "mod_jclic 0.096652 \n", "mod_journal 0.131590 \n", "mod_lesson 0.221499 \n", "mod_lightboxgallery 0.154291 \n", "mod_page 0.451160 \n", "mod_publication 0.110390 \n", "mod_questionnaire 0.289259 \n", "mod_quiz 0.569963 \n", "mod_resource 0.714661 \n", "mod_scorm 0.133380 \n", "mod_survey 0.070478 \n", "mod_taskchain 0.021296 \n", "mod_url 0.644620 \n", "mod_wiki 0.138492 \n", "mod_workshop 0.137251 \n", "tool_usertours 0.050285 \n", "Unnamed: 40 NaN \n", "\n", " assignsubmission_onlinetext block_comments \\\n", "Etiquetas de fila 0.096111 0.010937 \n", "assignsubmission_comments 0.493097 0.095465 \n", "assignsubmission_file 0.470980 0.109336 \n", "assignsubmission_onlinetext 1.000000 0.044710 \n", "block_comments 0.044710 1.000000 \n", "booktool_print 0.141057 0.012107 \n", "core 0.221350 0.086462 \n", "gradereport_user 0.406471 0.079094 \n", "mod_activequiz 0.039463 0.026967 \n", "mod_assign 0.514710 0.102808 \n", "mod_attendance 0.111297 -0.005321 \n", "mod_book 0.300052 0.009054 \n", "mod_chat 0.137010 0.041024 \n", "mod_checklist 0.255007 0.038776 \n", "mod_choice 0.250549 -0.003925 \n", "mod_data 0.164760 -0.004594 \n", "mod_feedback 0.084594 -0.002737 \n", "mod_folder 0.254446 0.059762 \n", "mod_forum 0.494712 0.057582 \n", "mod_geogebra 0.039456 0.043583 \n", "mod_glossary 0.255715 0.005937 \n", "mod_groupselect 0.052524 -0.001413 \n", "mod_hotpot 0.188134 0.011263 \n", "mod_hvp 0.276984 0.004920 \n", "mod_jclic 0.154122 0.024567 \n", "mod_journal 0.114734 0.001260 \n", "mod_lesson 0.274401 0.007106 \n", "mod_lightboxgallery 0.116454 -0.004578 \n", "mod_page 0.433011 -0.004954 \n", "mod_publication 0.020083 0.024425 \n", "mod_questionnaire 0.202307 0.014505 \n", "mod_quiz 0.275372 0.093902 \n", "mod_resource 0.336461 0.084065 \n", "mod_scorm 0.159641 0.006225 \n", "mod_survey 0.013818 0.055597 \n", "mod_taskchain 0.040450 -0.001295 \n", "mod_url 0.387020 0.095260 \n", "mod_wiki 0.069942 0.008548 \n", "mod_workshop 0.104325 -0.003849 \n", "tool_usertours 0.000908 0.070047 \n", "Unnamed: 40 NaN NaN \n", "\n", " booktool_print core gradereport_user \\\n", "Etiquetas de fila 0.047675 -0.148765 0.259413 \n", "assignsubmission_comments 0.189507 0.221626 0.753433 \n", "assignsubmission_file 0.201893 0.214561 0.795580 \n", "assignsubmission_onlinetext 0.141057 0.221350 0.406471 \n", "block_comments 0.012107 0.086462 0.079094 \n", "booktool_print 1.000000 0.075096 0.203281 \n", "core 0.075096 1.000000 0.159562 \n", "gradereport_user 0.203281 0.159562 1.000000 \n", "mod_activequiz 0.077902 0.095993 0.081383 \n", "mod_assign 0.201229 0.230445 0.801752 \n", "mod_attendance 0.066710 0.079182 0.157688 \n", "mod_book 0.547462 0.102316 0.377591 \n", "mod_chat 0.023285 0.091000 0.208974 \n", "mod_checklist 0.057450 0.060965 0.117725 \n", "mod_choice 0.216001 0.122257 0.117070 \n", "mod_data 0.043999 0.133493 0.122769 \n", "mod_feedback -0.008159 0.014973 0.086300 \n", "mod_folder 0.097540 0.112883 0.455907 \n", "mod_forum 0.242197 0.183212 0.607281 \n", "mod_geogebra 0.169384 0.004461 0.078386 \n", "mod_glossary 0.108365 0.123153 0.303415 \n", "mod_groupselect 0.140503 0.016297 0.055362 \n", "mod_hotpot 0.174308 -0.005391 0.116550 \n", "mod_hvp 0.093436 0.101546 0.246090 \n", "mod_jclic 0.031727 0.014507 0.077063 \n", "mod_journal 0.038782 0.002935 0.126024 \n", "mod_lesson 0.180687 0.183060 0.213605 \n", "mod_lightboxgallery 0.099515 0.057320 0.135353 \n", "mod_page 0.231721 0.222561 0.447035 \n", "mod_publication -0.013064 0.018806 0.159844 \n", "mod_questionnaire 0.081838 0.134392 0.258215 \n", "mod_quiz 0.249952 0.194519 0.701342 \n", "mod_resource 0.160678 0.169388 0.762621 \n", "mod_scorm 0.191239 0.097120 0.090411 \n", "mod_survey 0.000033 -0.012443 0.076519 \n", "mod_taskchain -0.003861 -0.009347 0.016082 \n", "mod_url 0.128532 0.223695 0.672818 \n", "mod_wiki 0.023326 0.049404 0.125703 \n", "mod_workshop 0.144644 0.143956 0.148821 \n", "tool_usertours 0.005141 0.053809 0.069442 \n", "Unnamed: 40 NaN NaN NaN \n", "\n", " mod_activequiz mod_assign ... mod_quiz \\\n", "Etiquetas de fila 0.012391 0.198368 ... 0.145997 \n", "assignsubmission_comments 0.072873 0.924896 ... 0.527971 \n", "assignsubmission_file 0.081700 0.952034 ... 0.569963 \n", "assignsubmission_onlinetext 0.039463 0.514710 ... 0.275372 \n", "block_comments 0.026967 0.102808 ... 0.093902 \n", "booktool_print 0.077902 0.201229 ... 0.249952 \n", "core 0.095993 0.230445 ... 0.194519 \n", "gradereport_user 0.081383 0.801752 ... 0.701342 \n", "mod_activequiz 1.000000 0.074123 ... 0.080610 \n", "mod_assign 0.074123 1.000000 ... 0.559485 \n", "mod_attendance 0.040602 0.167318 ... 0.094317 \n", "mod_book 0.047502 0.387625 ... 0.344151 \n", "mod_chat 0.065309 0.236664 ... 0.159815 \n", "mod_checklist 0.086368 0.143333 ... 0.095041 \n", "mod_choice 0.042442 0.134040 ... 0.138931 \n", "mod_data 0.053444 0.121242 ... 0.127351 \n", "mod_feedback -0.003440 0.076330 ... 0.080959 \n", "mod_folder 0.009335 0.457499 ... 0.343814 \n", "mod_forum 0.070415 0.625155 ... 0.485284 \n", "mod_geogebra -0.003877 0.090347 ... 0.075768 \n", "mod_glossary 0.035696 0.289306 ... 0.292757 \n", "mod_groupselect -0.001776 0.045276 ... 0.017867 \n", "mod_hotpot 0.045261 0.147093 ... 0.121200 \n", "mod_hvp 0.066090 0.281794 ... 0.216153 \n", "mod_jclic 0.007882 0.102916 ... 0.077009 \n", "mod_journal 0.071383 0.130355 ... 0.079315 \n", "mod_lesson 0.043484 0.217176 ... 0.285466 \n", "mod_lightboxgallery 0.035155 0.136626 ... 0.035634 \n", "mod_page 0.051512 0.479471 ... 0.368980 \n", "mod_publication 0.052190 0.104196 ... 0.099369 \n", "mod_questionnaire 0.064059 0.270605 ... 0.237116 \n", "mod_quiz 0.080610 0.559485 ... 1.000000 \n", "mod_resource 0.040573 0.707549 ... 0.560462 \n", "mod_scorm 0.097648 0.126405 ... 0.153014 \n", "mod_survey -0.003043 0.049967 ... 0.091636 \n", "mod_taskchain -0.001628 0.027429 ... 0.012292 \n", "mod_url 0.057104 0.651289 ... 0.518236 \n", "mod_wiki 0.009687 0.136764 ... 0.088268 \n", "mod_workshop 0.075283 0.145388 ... 0.132836 \n", "tool_usertours 0.038808 0.041429 ... 0.083057 \n", "Unnamed: 40 NaN NaN ... NaN \n", "\n", " mod_resource mod_scorm mod_survey \\\n", "Etiquetas de fila 0.210222 0.018963 0.013692 \n", "assignsubmission_comments 0.658217 0.098613 0.063141 \n", "assignsubmission_file 0.714661 0.133380 0.070478 \n", "assignsubmission_onlinetext 0.336461 0.159641 0.013818 \n", "block_comments 0.084065 0.006225 0.055597 \n", "booktool_print 0.160678 0.191239 0.000033 \n", "core 0.169388 0.097120 -0.012443 \n", "gradereport_user 0.762621 0.090411 0.076519 \n", "mod_activequiz 0.040573 0.097648 -0.003043 \n", "mod_assign 0.707549 0.126405 0.049967 \n", "mod_attendance 0.158101 0.088721 0.008484 \n", "mod_book 0.304211 0.147496 0.009700 \n", "mod_chat 0.196099 -0.003777 0.007151 \n", "mod_checklist 0.081594 0.041865 -0.003200 \n", "mod_choice 0.107019 0.358023 0.000929 \n", "mod_data 0.087262 0.118394 0.035810 \n", "mod_feedback 0.083243 -0.004420 -0.003039 \n", "mod_folder 0.458355 0.057535 0.067926 \n", "mod_forum 0.513636 0.126316 0.084909 \n", "mod_geogebra 0.066589 0.160981 0.062033 \n", "mod_glossary 0.260224 0.081167 0.008712 \n", "mod_groupselect 0.029532 -0.002282 -0.001569 \n", "mod_hotpot 0.116283 0.252379 -0.003865 \n", "mod_hvp 0.208968 0.044322 0.040857 \n", "mod_jclic 0.064357 0.027558 -0.002271 \n", "mod_journal 0.110639 0.000807 0.000205 \n", "mod_lesson 0.182408 0.318980 -0.007441 \n", "mod_lightboxgallery 0.131488 0.019447 -0.005084 \n", "mod_page 0.410001 0.138751 0.018282 \n", "mod_publication 0.144060 -0.007411 0.006690 \n", "mod_questionnaire 0.228846 0.107461 -0.006843 \n", "mod_quiz 0.560462 0.153014 0.091636 \n", "mod_resource 1.000000 0.107121 0.059309 \n", "mod_scorm 0.107121 1.000000 0.035960 \n", "mod_survey 0.059309 0.035960 1.000000 \n", "mod_taskchain 0.016642 -0.002091 -0.001438 \n", "mod_url 0.714145 0.116024 0.060731 \n", "mod_wiki 0.144342 0.006411 -0.005440 \n", "mod_workshop 0.118234 0.001573 -0.004274 \n", "tool_usertours 0.059692 -0.005949 -0.004090 \n", "Unnamed: 40 NaN NaN NaN \n", "\n", " mod_taskchain mod_url mod_wiki mod_workshop \\\n", "Etiquetas de fila 0.019719 0.155911 -0.003746 0.018289 \n", "assignsubmission_comments 0.028702 0.603209 0.130792 0.127661 \n", "assignsubmission_file 0.021296 0.644620 0.138492 0.137251 \n", "assignsubmission_onlinetext 0.040450 0.387020 0.069942 0.104325 \n", "block_comments -0.001295 0.095260 0.008548 -0.003849 \n", "booktool_print -0.003861 0.128532 0.023326 0.144644 \n", "core -0.009347 0.223695 0.049404 0.143956 \n", "gradereport_user 0.016082 0.672818 0.125703 0.148821 \n", "mod_activequiz -0.001628 0.057104 0.009687 0.075283 \n", "mod_assign 0.027429 0.651289 0.136764 0.145388 \n", "mod_attendance -0.003161 0.140234 0.055374 0.137911 \n", "mod_book -0.008998 0.259370 0.071502 0.185655 \n", "mod_chat 0.022606 0.228540 0.097549 0.287649 \n", "mod_checklist -0.001712 0.079987 -0.006476 0.000587 \n", "mod_choice 0.021551 0.134602 0.072669 0.017825 \n", "mod_data -0.002729 0.139592 0.041756 0.151688 \n", "mod_feedback -0.001626 0.059225 0.013142 0.041359 \n", "mod_folder 0.029358 0.467873 0.129381 0.108703 \n", "mod_forum 0.023707 0.519761 0.181286 0.202821 \n", "mod_geogebra -0.001832 0.076032 -0.006933 -0.005446 \n", "mod_glossary 0.004016 0.287997 0.157072 0.352135 \n", "mod_groupselect 0.217562 0.031217 0.007284 0.181808 \n", "mod_hotpot -0.002068 0.069474 0.028127 -0.006145 \n", "mod_hvp 0.016246 0.198112 0.001870 0.027653 \n", "mod_jclic -0.001215 0.039127 0.001081 0.089913 \n", "mod_journal 0.012882 0.075487 0.172939 0.168499 \n", "mod_lesson -0.001051 0.206438 0.146956 0.248299 \n", "mod_lightboxgallery -0.002720 0.113284 0.083689 0.000785 \n", "mod_page -0.006036 0.389527 0.066788 0.188946 \n", "mod_publication 0.009349 0.155666 0.060695 0.050026 \n", "mod_questionnaire 0.021944 0.237563 0.103766 0.166689 \n", "mod_quiz 0.012292 0.518236 0.088268 0.132836 \n", "mod_resource 0.016642 0.714145 0.144342 0.118234 \n", "mod_scorm -0.002091 0.116024 0.006411 0.001573 \n", "mod_survey -0.001438 0.060731 -0.005440 -0.004274 \n", "mod_taskchain 1.000000 0.026562 0.005077 -0.002286 \n", "mod_url 0.026562 1.000000 0.138067 0.125628 \n", "mod_wiki 0.005077 0.138067 1.000000 0.133049 \n", "mod_workshop -0.002286 0.125628 0.133049 1.000000 \n", "tool_usertours -0.002188 0.060999 -0.008278 0.037686 \n", "Unnamed: 40 NaN NaN NaN NaN \n", "\n", " tool_usertours Unnamed: 40 \n", "Etiquetas de fila 0.037782 NaN \n", "assignsubmission_comments 0.054523 NaN \n", "assignsubmission_file 0.050285 NaN \n", "assignsubmission_onlinetext 0.000908 NaN \n", "block_comments 0.070047 NaN \n", "booktool_print 0.005141 NaN \n", "core 0.053809 NaN \n", "gradereport_user 0.069442 NaN \n", "mod_activequiz 0.038808 NaN \n", "mod_assign 0.041429 NaN \n", "mod_attendance -0.008991 NaN \n", "mod_book 0.026645 NaN \n", "mod_chat -0.002209 NaN \n", "mod_checklist -0.004869 NaN \n", "mod_choice 0.001207 NaN \n", "mod_data 0.006235 NaN \n", "mod_feedback 0.028432 NaN \n", "mod_folder 0.018161 NaN \n", "mod_forum 0.053786 NaN \n", "mod_geogebra -0.005212 NaN \n", "mod_glossary 0.009281 NaN \n", "mod_groupselect -0.002388 NaN \n", "mod_hotpot -0.005881 NaN \n", "mod_hvp -0.002181 NaN \n", "mod_jclic -0.003456 NaN \n", "mod_journal -0.006500 NaN \n", "mod_lesson -0.005555 NaN \n", "mod_lightboxgallery -0.007736 NaN \n", "mod_page 0.021025 NaN \n", "mod_publication 0.023771 NaN \n", "mod_questionnaire 0.004093 NaN \n", "mod_quiz 0.083057 NaN \n", "mod_resource 0.059692 NaN \n", "mod_scorm -0.005949 NaN \n", "mod_survey -0.004090 NaN \n", "mod_taskchain -0.002188 NaN \n", "mod_url 0.060999 NaN \n", "mod_wiki -0.008278 NaN \n", "mod_workshop 0.037686 NaN \n", "tool_usertours 1.000000 NaN \n", "Unnamed: 40 NaN NaN \n", "\n", "[41 rows x 41 columns]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.corr()" ] }, { "cell_type": "markdown", "id": "14ac5cd6-94e5-4b70-a0e2-fc0e75b9f0b5", "metadata": {}, "source": [ "## Diagramas de dispersión" ] }, { "cell_type": "code", "execution_count": 24, "id": "6a96fe32-da9c-4664-8e39-fc5570f8f2cc", "metadata": {}, "outputs": [], "source": [ "#pd.plotting.scatter_matrix(df)" ] }, { "cell_type": "markdown", "id": "d3e3d30b-b8f2-4df4-812b-cdd4203e67f1", "metadata": {}, "source": [ "## Eliminación de columnas que **no** son numéricas" ] }, { "cell_type": "code", "execution_count": 41, "id": "09bc867f-a15b-40f4-b37d-158b2b1220f1", "metadata": {}, "outputs": [], "source": [ "#df=df.drop(columns=['Etiquetas de fila', 'Unnamed: 40'])\n", "df;" ] }, { "cell_type": "code", "execution_count": 27, "id": "11a148a6-0c69-45b5-be9f-d8bf5bafcac6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "assignsubmission_comments float64\n", "assignsubmission_file float64\n", "assignsubmission_onlinetext float64\n", "block_comments float64\n", "booktool_print float64\n", "core float64\n", "gradereport_user float64\n", "mod_activequiz float64\n", "mod_assign float64\n", "mod_attendance float64\n", "mod_book float64\n", "mod_chat float64\n", "mod_checklist float64\n", "mod_choice float64\n", "mod_data float64\n", "mod_feedback float64\n", "mod_folder float64\n", "mod_forum float64\n", "mod_geogebra float64\n", "mod_glossary float64\n", "mod_groupselect float64\n", "mod_hotpot float64\n", "mod_hvp float64\n", "mod_jclic float64\n", "mod_journal float64\n", "mod_lesson float64\n", "mod_lightboxgallery float64\n", "mod_page float64\n", "mod_publication float64\n", "mod_questionnaire float64\n", "mod_quiz float64\n", "mod_resource float64\n", "mod_scorm float64\n", "mod_survey float64\n", "mod_taskchain float64\n", "mod_url float64\n", "mod_wiki float64\n", "mod_workshop float64\n", "tool_usertours float64\n", "dtype: object" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.dtypes" ] }, { "cell_type": "markdown", "id": "fea1e2ea-2116-4a2b-9cfd-282587dc7d9c", "metadata": {}, "source": [ "# Generación de clusters" ] }, { "cell_type": "markdown", "id": "dbc5bb5c-7fdd-4b17-991c-ade61b62edeb", "metadata": {}, "source": [ "## Asignación de número de clusters ($k$)" ] }, { "cell_type": "code", "execution_count": 42, "id": "d4892cbf-6d89-4da7-9966-24409e188f35", "metadata": {}, "outputs": [], "source": [ "k=3 #Número de clusters a generar (default de 10)" ] }, { "cell_type": "markdown", "id": "d473086f-2993-477f-91f3-07baf292e01b", "metadata": {}, "source": [ "## Creación del modelo" ] }, { "cell_type": "code", "execution_count": 43, "id": "6c21d970-377b-4a08-945b-2c05be93dc4b", "metadata": { "tags": [] }, "outputs": [], "source": [ "modelo = KMeans (n_clusters=k)\n", "# maximo de iteraciones, valores iniciales, algoritmos" ] }, { "cell_type": "markdown", "id": "54d7e112-fd79-4f06-8e39-056e8094b526", "metadata": {}, "source": [ "## Entrenamiento con los datos de entrada" ] }, { "cell_type": "code", "execution_count": 44, "id": "ea8bd6c8-ecd6-4795-aab7-416ca6b34626", "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "KMeans(n_clusters=3)" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "modelo.fit(df)" ] }, { "cell_type": "markdown", "id": "c8b11fe7-1e31-42d6-89ab-2f317a6efb7a", "metadata": {}, "source": [ "## ¿Dónde quedaron los centroides? (*.cluster_centers*)\n", "Cada centroide tiene un valor para cada atributos" ] }, { "cell_type": "code", "execution_count": 45, "id": "0e750268-28cd-4af7-b9ec-2e44696dab50", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Index(['assignsubmission_comments', 'assignsubmission_file',\n", " 'assignsubmission_onlinetext', 'block_comments', 'booktool_print',\n", " 'core', 'gradereport_user', 'mod_activequiz', 'mod_assign',\n", " 'mod_attendance', 'mod_book', 'mod_chat', 'mod_checklist', 'mod_choice',\n", " 'mod_data', 'mod_feedback', 'mod_folder', 'mod_forum', 'mod_geogebra',\n", " 'mod_glossary', 'mod_groupselect', 'mod_hotpot', 'mod_hvp', 'mod_jclic',\n", " 'mod_journal', 'mod_lesson', 'mod_lightboxgallery', 'mod_page',\n", " 'mod_publication', 'mod_questionnaire', 'mod_quiz', 'mod_resource',\n", " 'mod_scorm', 'mod_survey', 'mod_taskchain', 'mod_url', 'mod_wiki',\n", " 'mod_workshop', 'tool_usertours'],\n", " dtype='object')\n" ] } ], "source": [ "print(df.columns)\n", "centroides=modelo.cluster_centers_" ] }, { "cell_type": "code", "execution_count": 46, "id": "d62007c3-0928-48c4-983d-3204b085b8b7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[ 6.33734157e-02, 3.57491063e-01, 6.10984725e-02,\n", " -2.60208521e-17, 1.85245369e-02, 6.59083523e-01,\n", " 7.77055574e-01, 3.57491063e-03, 3.34741631e-01,\n", " 1.81995450e-02, 4.27039324e-01, 3.24991875e-02,\n", " 6.49983750e-04, 2.11244719e-02, 2.66493338e-02,\n", " 6.49983750e-04, 3.51641209e-01, 9.26551836e-01,\n", " 8.44978876e-03, 1.14072148e-01, 3.24991875e-04,\n", " 9.42476438e-03, 8.77478063e-02, 6.49983750e-04,\n", " 8.12479688e-03, 6.88982775e-02, 1.33246669e-02,\n", " 2.97692558e-01, 4.32239194e-02, 2.20994475e-02,\n", " 8.11179721e-01, 8.78453039e-01, 1.68995775e-02,\n", " 6.49983750e-04, 6.49983750e-04, 4.57588560e-01,\n", " 1.98245044e-02, 5.84985375e-03, 4.54988625e-03],\n", " [ 4.77474403e+00, 1.69078498e+01, 5.79180887e+00,\n", " 4.09556314e-02, 7.23549488e-01, 1.80204778e+00,\n", " 7.93856655e+00, 6.82593857e-02, 1.18259386e+01,\n", " 2.83276451e-01, 5.94197952e+00, 9.86348123e-01,\n", " 1.60409556e-01, 4.70989761e-01, 7.06484642e-01,\n", " 4.43686007e-02, 5.13993174e+00, 3.73993174e+01,\n", " 8.53242321e-02, 2.52218430e+00, 6.82593857e-03,\n", " 4.67576792e-01, 2.01023891e+00, 1.09215017e-01,\n", " 3.24232082e-01, 3.94197952e+00, 2.08191126e-01,\n", " 4.09897611e+00, 2.01365188e-01, 7.57679181e-01,\n", " 1.20341297e+01, 6.83959044e+00, 4.19795222e-01,\n", " 6.14334471e-02, 3.41296928e-03, 5.78498294e+00,\n", " 7.50853242e-01, 1.23890785e+00, 2.04778157e-02],\n", " [ 3.71669794e+00, 1.47692308e+01, 2.11444653e+00,\n", " 3.37711069e-02, 2.62664165e-01, 1.21575985e+00,\n", " 6.84803002e+00, 3.18949343e-02, 1.00375235e+01,\n", " 2.13883677e-01, 2.82363977e+00, 3.30206379e-01,\n", " 4.31519700e-02, 9.56848030e-02, 8.25515947e-02,\n", " 1.12570356e-02, 3.64352720e+00, 6.91557223e+00,\n", " 6.56660413e-02, 8.34896811e-01, 3.75234522e-03,\n", " 9.19324578e-02, 7.11069418e-01, 1.12570356e-02,\n", " 1.42589118e-01, 7.52345216e-01, 1.51969981e-01,\n", " 1.80300188e+00, 3.11444653e-01, 3.18949343e-01,\n", " 8.64352720e+00, 6.42776735e+00, 2.00750469e-01,\n", " 3.37711069e-02, 3.25260652e-19, 4.46529081e+00,\n", " 3.62101313e-01, 1.96998124e-01, 1.12570356e-02]])" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "centroides" ] }, { "cell_type": "code", "execution_count": 47, "id": "939200cd-6217-46ba-836d-a07c93b30971", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Inertia 508440.9646498222\n" ] } ], "source": [ "print(\"Inertia\",modelo.inertia_) # Suma de cuadrados de las diferencias" ] }, { "cell_type": "markdown", "id": "5a68d6bf-3d52-4f72-a3ca-c8deda3414e7", "metadata": {}, "source": [ "## Cluster asignados (*.labels_*)" ] }, { "cell_type": "code", "execution_count": 48, "id": "da2716e2-3940-490d-aa89-3380e60ac6a7", "metadata": {}, "outputs": [], "source": [ "clusterAsignado=modelo.labels_" ] }, { "cell_type": "markdown", "id": "92819944-8f42-4876-b74a-1a616f69fa4f", "metadata": { "tags": [] }, "source": [ "## Nuevo CSV con columna de cluster asignado" ] }, { "cell_type": "code", "execution_count": null, "id": "87e89122-b52e-4f11-aafb-c43e002773ec", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "c999690e-a82c-4f41-9ce3-d31a92ccf9bc", "metadata": {}, "source": [ "## Graficación\n", "En el caso de una gráfica de 2D se puede hacer con scatter y adicionar los centroides\n" ] }, { "cell_type": "code", "execution_count": 49, "id": "3583b094-e0e6-4af6-9dfc-c6faf18b4039", "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'DataFrame' object has no attribute 'x'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[0mcolorC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcolorCentroides\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcluster\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 16\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorP\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\".\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Puntos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 17\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 18\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'D'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorC\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0medgecolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Black\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#Centroide\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5463\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5464\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5465\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5466\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5467\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'x'" ] }, { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Tablas de colores\n", "colorPuntos = ['#ffcdd2', '#a5d6a7', '#bbdefb',\"#fff176\",\"#ffab91\",\"#a7ffeb\",\"#d1c4e9\",\"#eeff41\",\"#90a4ae\",\"#f8bbd0\",\"#9ccc65\",\"#81d4fa\",\"#e1bee7\",\"#e6ee9c\",\"#84ffff\"]\n", "colorCentroides = [\"#d32f2f\", \"#388e3c\", \"#1e88e5\",\"#f57f17\",\"#ff5722\",\"#1de9b6\",\"#5e35b1\",\"#aeea00\",\"#455a64\",\"#c2185b\",\"#33691e\",\"#0288d1\",\"#7b1fa2\",\"#9e9d24\",\"#00e5ff\"]\n", "\n", "#Graficación\n", "plt.figure (num=1, figsize=(7,7))\n", "#zip \"empareja\" un elemento de una lista con un elemento de otra\n", "for cluster in range(k): # Una iteración por cada cluster\n", " #Puntos que pertenecen al cluster\n", " cualesSI = (clusterAsignado == cluster)\n", " centroide = centroides[cluster]\n", " \n", " colorP = colorPuntos [cluster]\n", " colorC = colorCentroides[cluster]\n", "\n", " plt.scatter(df[cualesSI].x, df[cualesSI].y,color=colorP, marker=\".\") # Puntos\n", " \n", " plt.scatter (centroide[0], centroide[1], marker='D', color=colorC, edgecolors=\"Black\") #Centroide" ] }, { "cell_type": "markdown", "id": "bee22f1f-bd47-4c95-990e-e6ae3d0be5e5", "metadata": { "tags": [] }, "source": [ "https://matplotlib.org/stable/api/markers_api.html" ] }, { "cell_type": "markdown", "id": "b00dd6d5-f66f-4a28-adc5-8bb49a8d160f", "metadata": {}, "source": [ "## Método *del codo* para aproximar el mejor número de *clusters*\n", "Donde se vea el _quiebre_ más pronunciado se determina el valor de $k$" ] }, { "cell_type": "code", "execution_count": 50, "id": "6423e905-f251-4b24-86a7-b4e618f1fc48", "metadata": { "tags": [] }, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfoAAADgCAYAAADrL6QAAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAuaUlEQVR4nO3dd3gd1Z3/8fdHzbItF9zAcsXGmG4CpgVCnNBCCSSEEhJS2bBJWBJCJyFLwiYsKaT8NtULISQxZE3vvYcEAwZcMKbjjgvGFUuypO/vjxnZspDkC9LVSFef1/Pc596ZOXfOVwOPv/ecOXOOIgIzMzMrTEVZB2BmZmb540RvZmZWwJzozczMCpgTvZmZWQFzojczMytgTvRmZmYFzInerAuT9DtJP2rnc4akHdrhPJMkLcyx7A8k/a2tdbZXPGaFxInerJOQ9KakGkmDmux/Pk2+o5vsPx2ojoiLG+1zMjOzLZRkHYCZbeEN4BTgfwAk7Q70bK5gREzuwLjMrItyi96sc/kr8MVG218C/tK4gKQekn4uab6kpZL+IKmnpN7A3UClpHXpqzIt/ytJi9PXryT1aHS+8yQtSY99tUld/ST9RdJySfMkXSyp2X830hj+LOkdSXOAfZocr5R0Y3quNyR9K9eLIum4tGdjjaTXJH2i0Tlvk7RS0quSvvY+4tlZ0iOSVkl6QdKxucZj1pU40Zt1Lk8CfdMkVAycDDS9d/0TYEdgT2AHYBjwnxGxHjgSWBwRFelrMfA9YP+0/ARgX+BigDRhngscBowDDm1S1/8A/YAxwEdJfoR8pYXYLwHGpq8jSH6kkNZTBNwOzEjjPQQ4S9IRW7sgkvYl+bFzHtAfOBh4Mz18HbAQqAROAC6TdEgO8ZSm8dwHDAHOBKZIGr+1eMy6moJN9JL+JGmZpNk5lj9J0pz0l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ain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "maximoClusters=8\n", "ks = range(1, maximoClusters) #rango del 1 al máximo\n", "\n", "kmeans = [KMeans(n_clusters=i, max_iter=500) for i in ks] #Genera una lista con varios modelos\n", "score = [kmeans[i].fit(df).score(df) for i in range(len(kmeans))] #Calcula el score para cada modelo\n", "plt.figure (num=1, figsize=(8,3))\n", "plt.plot(ks,score) #Imprime k,score para cada uno de los modelos generados\n", "\n", "plt.xlabel('k (valores menores son mejor)')\n", "plt.ylabel('Score (cercano a 0 es mejor)')\n", "plt.title('Método del codo')\n", "plt.show()" ] }, { "cell_type": "markdown", "id": "c31b8f28-dff1-432f-847b-940b5811b28e", "metadata": {}, "source": [ "# _Predicción_ con data frame diferente\n", "Se carga un conjunto de datos y se utiliza el modelo para crear los clusters" ] }, { "cell_type": "code", "execution_count": 51, "id": "44ed1104-bdb0-40b3-af48-141ce49fc3ba", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
xyz
0243.472712233.161719a
1180.100413229.863836a
2135.924379207.173889a
3191.515041211.023219a
4178.990861183.943386a
\n", "
" ], "text/plain": [ " x y z\n", "0 243.472712 233.161719 a\n", "1 180.100413 229.863836 a\n", "2 135.924379 207.173889 a\n", "3 191.515041 211.023219 a\n", "4 178.990861 183.943386 a" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "otroDF = pd.read_csv (\"./datosEntrada/clustering01.csv\");\n", "otroDF.head()" ] }, { "cell_type": "code", "execution_count": 52, "id": "2e9322b9-663e-419f-8474-88b9e7549b73", "metadata": {}, "outputs": [], "source": [ "otroDF = otroDF.drop(columns=[\"z\"])" ] }, { "cell_type": "code", "execution_count": 53, "id": "6d1c8007-458f-4b43-8983-d3711b646a26", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "X has 2 features, but KMeans is expecting 39 features as input.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mclusterNuevo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodelo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0motroDF\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mclusterNuevo\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mmodelo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlabels_\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"cluster\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclusterNuevo\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/cluster/_kmeans.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, X, sample_weight)\u001b[0m\n\u001b[1;32m 1154\u001b[0m \u001b[0mcheck_is_fitted\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1155\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1156\u001b[0;31m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_test_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1157\u001b[0m \u001b[0mx_squared_norms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrow_norms\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msquared\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1158\u001b[0m \u001b[0msample_weight\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_check_sample_weight\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/cluster/_kmeans.py\u001b[0m in \u001b[0;36m_check_test_data\u001b[0;34m(self, X)\u001b[0m\n\u001b[1;32m 856\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 857\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_check_test_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 858\u001b[0;31m X = self._validate_data(X, accept_sparse='csr', reset=False,\n\u001b[0m\u001b[1;32m 859\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 860\u001b[0m order='C', accept_large_sparse=False)\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36m_validate_data\u001b[0;34m(self, X, y, reset, validate_separately, **check_params)\u001b[0m\n\u001b[1;32m 435\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcheck_params\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ensure_2d'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 437\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_n_features\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreset\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreset\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 438\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 439\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36m_check_n_features\u001b[0;34m(self, X, reset)\u001b[0m\n\u001b[1;32m 363\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 364\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn_features\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_features_in_\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 365\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 366\u001b[0m \u001b[0;34mf\"X has {n_features} features, but {self.__class__.__name__} \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 367\u001b[0m f\"is expecting {self.n_features_in_} features as input.\")\n", "\u001b[0;31mValueError\u001b[0m: X has 2 features, but KMeans is expecting 39 features as input." ] } ], "source": [ "clusterNuevo = modelo.predict(otroDF)\n", "clusterNuevo\n", "modelo.labels_\n", "otroDF[\"cluster\"] = clusterNuevo\n", "otroDF" ] }, { "cell_type": "code", "execution_count": 54, "id": "4db8b3ef-2981-4fb3-bedb-3943ff462c17", "metadata": {}, "outputs": [ { "ename": "KeyError", "evalue": "\"['cluster'] not found in axis\"", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0motroDF\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"cluster\"\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36mdrop\u001b[0;34m(self, labels, axis, index, columns, level, inplace, errors)\u001b[0m\n\u001b[1;32m 4306\u001b[0m \u001b[0mweight\u001b[0m \u001b[0;36m1.0\u001b[0m \u001b[0;36m0.8\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4307\u001b[0m \"\"\"\n\u001b[0;32m-> 4308\u001b[0;31m return super().drop(\n\u001b[0m\u001b[1;32m 4309\u001b[0m \u001b[0mlabels\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4310\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36mdrop\u001b[0;34m(self, labels, axis, index, columns, level, inplace, errors)\u001b[0m\n\u001b[1;32m 4151\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlabels\u001b[0m \u001b[0;32min\u001b[0m \u001b[0maxes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4152\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mlabels\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4153\u001b[0;31m \u001b[0mobj\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_drop_axis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4154\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4155\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0minplace\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m_drop_axis\u001b[0;34m(self, labels, axis, level, errors)\u001b[0m\n\u001b[1;32m 4186\u001b[0m \u001b[0mnew_axis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4187\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4188\u001b[0;31m \u001b[0mnew_axis\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4189\u001b[0m \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m**\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0maxis_name\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mnew_axis\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4190\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/indexes/base.py\u001b[0m in \u001b[0;36mdrop\u001b[0;34m(self, labels, errors)\u001b[0m\n\u001b[1;32m 5589\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mmask\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0many\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5590\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0;34m\"ignore\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5591\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34mf\"{labels[mask]} not found in axis\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5592\u001b[0m \u001b[0mindexer\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mindexer\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m~\u001b[0m\u001b[0mmask\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5593\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdelete\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mKeyError\u001b[0m: \"['cluster'] not found in axis\"" ] } ], "source": [ "otroDF = otroDF.drop(columns=[\"cluster\"])" ] }, { "cell_type": "code", "execution_count": 55, "id": "da5a037e-2371-4e15-b8aa-2eb39e0e7c8f", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "X has 2 features, but KMeans is expecting 39 features as input.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mclusterAsignado\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodelo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpredict\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0motroDF\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mclusterAsignado\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mmodelo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlabels_\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m\"cluster\"\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mclusterAsignado\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/cluster/_kmeans.py\u001b[0m in \u001b[0;36mpredict\u001b[0;34m(self, X, sample_weight)\u001b[0m\n\u001b[1;32m 1154\u001b[0m \u001b[0mcheck_is_fitted\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1155\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1156\u001b[0;31m \u001b[0mX\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_test_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1157\u001b[0m \u001b[0mx_squared_norms\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrow_norms\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msquared\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1158\u001b[0m \u001b[0msample_weight\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_check_sample_weight\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msample_weight\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdtype\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/cluster/_kmeans.py\u001b[0m in \u001b[0;36m_check_test_data\u001b[0;34m(self, X)\u001b[0m\n\u001b[1;32m 856\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 857\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_check_test_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mX\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 858\u001b[0;31m X = self._validate_data(X, accept_sparse='csr', reset=False,\n\u001b[0m\u001b[1;32m 859\u001b[0m \u001b[0mdtype\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat64\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat32\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 860\u001b[0m order='C', accept_large_sparse=False)\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36m_validate_data\u001b[0;34m(self, X, y, reset, validate_separately, **check_params)\u001b[0m\n\u001b[1;32m 435\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 436\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcheck_params\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'ensure_2d'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 437\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_check_n_features\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreset\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreset\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 438\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 439\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mout\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/sklearn/base.py\u001b[0m in \u001b[0;36m_check_n_features\u001b[0;34m(self, X, reset)\u001b[0m\n\u001b[1;32m 363\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 364\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mn_features\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mn_features_in_\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 365\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 366\u001b[0m \u001b[0;34mf\"X has {n_features} features, but {self.__class__.__name__} \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 367\u001b[0m f\"is expecting {self.n_features_in_} features as input.\")\n", "\u001b[0;31mValueError\u001b[0m: X has 2 features, but KMeans is expecting 39 features as input." ] } ], "source": [ "clusterAsignado = modelo.predict(otroDF)\n", "clusterAsignado\n", "modelo.labels_\n", "otroDF[\"cluster\"] = clusterAsignado\n", "otroDF" ] }, { "cell_type": "markdown", "id": "e3e179a4-e056-4d32-87a1-bdca1f6dd946", "metadata": {}, "source": [ "## Graficación del nuevo conjunto de datos" ] }, { "cell_type": "code", "execution_count": 56, "id": "d3a55226-28fc-4a5f-86b2-d1567018fbd1", "metadata": {}, "outputs": [ { "ename": "AttributeError", "evalue": "'DataFrame' object has no attribute 'x'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[0mcolorC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcolorCentroides\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcluster\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 11\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdf\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorP\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\".\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Puntos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 12\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'D'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorC\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0medgecolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Black\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#Centroide\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5463\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_info_axis\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_can_hold_identifiers_and_holds_name\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5464\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5465\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5466\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5467\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'x'" ] }, { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.figure (num=1, figsize=(7,7))\n", "#zip \"empareja\" un elemento de una lista con un elemento de otra\n", "for cluster in range(k): # Una iteración por cada cluster\n", " #Puntos que pertenecen al cluster\n", " cualesSI = (clusterAsignado == cluster)\n", " centroide = centroides[cluster]\n", " \n", " colorP = colorPuntos [cluster]\n", " colorC = colorCentroides[cluster]\n", "\n", " plt.scatter(df[cualesSI].x, df[cualesSI].y,color=colorP, marker=\".\") # Puntos\n", " \n", " plt.scatter (centroide[0], centroide[1], marker='D', color=colorC, edgecolors=\"Black\") #Centroide" ] }, { "cell_type": "code", "execution_count": 57, "id": "0a2cbbe9-97db-4451-a431-ec236b91b063", "metadata": {}, "outputs": [ { "ename": "ValueError", "evalue": "Item wrong length 3903 instead of 910.", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mcolorC\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcolorCentroides\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcluster\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0motroDF\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0motroDF\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcualesSI\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorP\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\".\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m# Puntos\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0mplt\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mscatter\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcentroide\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmarker\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'D'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolor\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcolorC\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0medgecolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Black\"\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;31m#Centroide\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3013\u001b[0m \u001b[0;31m# Do we have a (boolean) 1d indexer?\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3014\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcom\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mis_bool_indexer\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3015\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_getitem_bool_array\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3016\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3017\u001b[0m \u001b[0;31m# We are left with two options: a single key, and a collection of keys,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/frame.py\u001b[0m in \u001b[0;36m_getitem_bool_array\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 3060\u001b[0m )\n\u001b[1;32m 3061\u001b[0m \u001b[0;32melif\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 3062\u001b[0;31m raise ValueError(\n\u001b[0m\u001b[1;32m 3063\u001b[0m \u001b[0;34mf\"Item wrong length {len(key)} instead of {len(self.index)}.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3064\u001b[0m )\n", "\u001b[0;31mValueError\u001b[0m: Item wrong length 3903 instead of 910." ] }, { "data": { "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.figure (num=1, figsize=(8,8))\n", "for cluster in range(k): #zip \"empareja\" un elemento de una lista con un elemento de otra\n", " #Puntos que pertenecen al cluster\n", " cualesSI = clusterAsignado == cluster\n", " centroide = centroides[cluster]\n", " colorP= colorPuntos[cluster]\n", " colorC = colorCentroides[cluster]\n", "\n", " plt.scatter(otroDF[cualesSI].x, otroDF[cualesSI].y,color=colorP, marker=\".\") # Puntos\n", " \n", " plt.scatter (centroide[0], centroide[1], marker='D', color=colorC, edgecolors=\"Black\") #Centroide" ] }, { "cell_type": "code", "execution_count": 58, "id": "1baacc11-a0c8-4453-ad6a-40888d1bc9d2", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Fin del notebook 2022-09-21 23:25:41.365852\n" ] } ], "source": [ "import datetime as dt\n", "print (\"Fin del notebook\", dt.datetime.today())" ] }, { "cell_type": "code", "execution_count": null, "id": "fba68e34-dec9-4227-9c7b-a0dec192696f", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }