From 561aa90f5fe704d7ddbbf78d3af008bb0d14cb7e Mon Sep 17 00:00:00 2001 From: jaimed411 <131529197+jaimed411@users.noreply.github.com> Date: Sat, 10 Jun 2023 18:23:34 +0000 Subject: [PATCH 1/2] mensaje --- notebook/problems.ipynb | 210 +++++++++++++++++++++++++++++++--------- 1 file changed, 165 insertions(+), 45 deletions(-) diff --git a/notebook/problems.ipynb b/notebook/problems.ipynb index 2889f183..837f9569 100644 --- a/notebook/problems.ipynb +++ b/notebook/problems.ipynb @@ -1,6 +1,7 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "id": "ac622319", "metadata": {}, @@ -9,6 +10,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "aa8993e4", "metadata": {}, @@ -17,6 +19,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "id": "5e0ab0d5", "metadata": {}, @@ -30,41 +33,80 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "34720ab6", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 1.76405235 0.40015721 0.97873798 2.2408932 1.86755799 -0.97727788\n", + " 0.95008842 -0.15135721 -0.10321885 0.4105985 0.14404357 1.45427351\n", + " 0.76103773 0.12167502 0.44386323 0.33367433 1.49407907 -0.20515826\n", + " 0.3130677 -0.85409574]\n" + ] + } + ], "source": [ "#import libraries\n", + "import numpy as np\n", "\n", "\n", "# Set seed in order to get similar results\n", + "np.random.seed(0)\n", "\n", "\n", "# create the data\n", + "data = np.random.normal(0, 1, 20)\n", "\n", "\n", - "#print results" + "#print results\n", + "print(data)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "49c55822", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.5693345929456347" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#Use numpy to get the mean of your data" + "#Use numpy to get the mean of your data\n", + "np.mean(data)" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "id": "03529459", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.7228107940950779" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#get the variance of your data" + "#get the variance of your data\n", + "data.var()" ] }, { @@ -72,48 +114,116 @@ "execution_count": 4, "id": "e53f30c5", "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0.8501828003994658" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Standard deviation\n" + "# Standard deviation\n", + "np.std(data)" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 33, "id": "9bce852f", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mode: ModeResult(mode=array([-1.7262826]), count=array([1]))\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/tmp/ipykernel_680/837115706.py:9: FutureWarning: Unlike other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode` typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of `keepdims` will become False, the `axis` over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set `keepdims` to True or False to avoid this warning.\n", + " mode_result = stats.mode(data)\n" + ] + } + ], "source": [ "#import libraries and print the mode\n", + "from scipy import stats\n", + "import numpy as np\n", + "\n", "\n", + "# Mode for continuous array\n", + "data = np.random.normal(0, 1, 20)\n", "\n", - "# Mode for continuous array\n" + "mode_result = stats.mode(data)\n", + "\n", + "\n", + "print(\"Mode:\", mode_result)" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 34, "id": "c682cb6e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mediana: -0.3806670488744016\n" + ] + } + ], "source": [ - "# Median\n" + "# Median\n", + "mediana = np.median(data)\n", + "\n", + "# Imprimir la mediana\n", + "print(\"Mediana:\", mediana)\n" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 35, "id": "39c3fabd", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Percentil de 25 (Q1): -0.827558998828811\n", + "Percentil de 50 (Median): -0.3806670488744016\n", + "Percentil de 75 (Q3): 0.14109371863149622\n", + "Rango intercuartil (IQR): 0.9686527174603072\n" + ] + } + ], "source": [ - "# Print the Quantiles\n", + "# Print the percentiles\n", + "percentil = np.percentile(data, [25, 50, 75])\n", + "\n", + "# Print the quantiles\n", + "print(\"Percentil de 25 (Q1):\", percentil[0])\n", + "print(\"Percentil de 50 (Median):\", percentil[1])\n", + "print(\"Percentil de 75 (Q3):\", percentil[2])\n", + "print(\"Rango intercuartil (IQR):\", percentil[2] - percentil[0])\n", "\n", "\n", - "# This match with np.median, why?\n" + "# This match with np.median, why?\n", + "#np.median y np.percentile son parecidos porque ambos separan el data set en dos mitades." ] }, { + "attachments": {}, "cell_type": "markdown", "id": "46c70c3d", "metadata": {}, @@ -128,58 +238,68 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 51, "id": "d590308e", "metadata": {}, "outputs": [ { - "ename": "IndentationError", - "evalue": "expected an indented block (4006267275.py, line 20)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Input \u001b[1;32mIn [8]\u001b[1;36m\u001b[0m\n\u001b[1;33m def avg_calc(ls):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m expected an indented block\n" + "name": "stdout", + "output_type": "stream", + "text": [ + "Datos: [4, 2, 5, 8, 6]\n", + "Desviación estándar: 2.0\n" ] } ], "source": [ - "import math\n", + "\n", + "\n", "import sys\n", + "import math\n", "\n", "# Define the standard deviation function\n", - "\n", "def sd_calc(data):\n", - " #code here\n", + " # Calcular la media utilizando la función np.mean()\n", + " mean = np.mean(data)\n", " \n", + " # Calcular la suma de los cuadrados de las diferencias con la media\n", + " sum_of_squares = sum((x - mean) ** 2 for x in data)\n", " \n", + " # Calcular la varianza dividiendo la suma de los cuadrados entre el número de elementos\n", + " variance = sum_of_squares / len(data)\n", " \n", - "\n", - " # calculate stan. dev.\n", + " # Calcular la desviación estándar tomando la raíz cuadrada de la varianza\n", + " std_deviation = math.sqrt(variance)\n", " \n", - "\n", - "\n", - "\n", + " return std_deviation\n", "\n", "# Define the average function\n", - "\n", "def avg_calc(ls):\n", - " #code here\n", + " # Calcular la suma de los elementos\n", + " total = sum(ls)\n", " \n", + " # Calcular la cantidad de elementos\n", + " count = len(ls)\n", " \n", + " # Calcular el promedio\n", + " average = total / count\n", " \n", - "\n", - " # calculate average\n", - " \n", + " return average\n", " \n", - " \n", - "\n", "data = [4, 2, 5, 8, 6]\n", "\n", - "#print the data\n", + "# Imprimir los datos\n", + "print(\"Datos:\", data)\n", + "\n", + "# Calcular la desviación estándar utilizando la función sd_calc()\n", + "std_deviation = sd_calc(data)\n", "\n", - "#print the standard deviation of the data" + "# Imprimir la desviación estándar\n", + "print(\"Desviación estándar:\", std_deviation)" ] }, { + "attachments": {}, "cell_type": "markdown", "id": "04b71791", "metadata": {}, @@ -209,7 +329,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.12" + "version": "3.11.3" } }, "nbformat": 4, From d755b42240e4460da4ad5a64f734d61e10484684 Mon Sep 17 00:00:00 2001 From: jaimed411 <131529197+jaimed411@users.noreply.github.com> Date: Mon, 12 Jun 2023 12:38:35 +0000 Subject: [PATCH 2/2] mensaje --- notebook/problems.ipynb | 118 ++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 53 deletions(-) diff --git a/notebook/problems.ipynb b/notebook/problems.ipynb index 837f9569..6a3202ea 100644 --- a/notebook/problems.ipynb +++ b/notebook/problems.ipynb @@ -33,7 +33,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 5, "id": "34720ab6", "metadata": {}, "outputs": [ @@ -44,7 +44,37 @@ "[ 1.76405235 0.40015721 0.97873798 2.2408932 1.86755799 -0.97727788\n", " 0.95008842 -0.15135721 -0.10321885 0.4105985 0.14404357 1.45427351\n", " 0.76103773 0.12167502 0.44386323 0.33367433 1.49407907 -0.20515826\n", - " 0.3130677 -0.85409574]\n" + " 0.3130677 -0.85409574 -2.55298982 0.6536186 0.8644362 -0.74216502\n", + " 2.26975462 -1.45436567 0.04575852 -0.18718385 1.53277921 1.46935877\n", + " 0.15494743 0.37816252 -0.88778575 -1.98079647 -0.34791215 0.15634897\n", + " 1.23029068 1.20237985 -0.38732682 -0.30230275 -1.04855297 -1.42001794\n", + " -1.70627019 1.9507754 -0.50965218 -0.4380743 -1.25279536 0.77749036\n", + " -1.61389785 -0.21274028 -0.89546656 0.3869025 -0.51080514 -1.18063218\n", + " -0.02818223 0.42833187 0.06651722 0.3024719 -0.63432209 -0.36274117\n", + " -0.67246045 -0.35955316 -0.81314628 -1.7262826 0.17742614 -0.40178094\n", + " -1.63019835 0.46278226 -0.90729836 0.0519454 0.72909056 0.12898291\n", + " 1.13940068 -1.23482582 0.40234164 -0.68481009 -0.87079715 -0.57884966\n", + " -0.31155253 0.05616534 -1.16514984 0.90082649 0.46566244 -1.53624369\n", + " 1.48825219 1.89588918 1.17877957 -0.17992484 -1.07075262 1.05445173\n", + " -0.40317695 1.22244507 0.20827498 0.97663904 0.3563664 0.70657317\n", + " 0.01050002 1.78587049 0.12691209 0.40198936 1.8831507 -1.34775906\n", + " -1.270485 0.96939671 -1.17312341 1.94362119 -0.41361898 -0.74745481\n", + " 1.92294203 1.48051479 1.86755896 0.90604466 -0.86122569 1.91006495\n", + " -0.26800337 0.8024564 0.94725197 -0.15501009 0.61407937 0.92220667\n", + " 0.37642553 -1.09940079 0.29823817 1.3263859 -0.69456786 -0.14963454\n", + " -0.43515355 1.84926373 0.67229476 0.40746184 -0.76991607 0.53924919\n", + " -0.67433266 0.03183056 -0.63584608 0.67643329 0.57659082 -0.20829876\n", + " 0.39600671 -1.09306151 -1.49125759 0.4393917 0.1666735 0.63503144\n", + " 2.38314477 0.94447949 -0.91282223 1.11701629 -1.31590741 -0.4615846\n", + " -0.06824161 1.71334272 -0.74475482 -0.82643854 -0.09845252 -0.66347829\n", + " 1.12663592 -1.07993151 -1.14746865 -0.43782004 -0.49803245 1.92953205\n", + " 0.94942081 0.08755124 -1.22543552 0.84436298 -1.00021535 -1.5447711\n", + " 1.18802979 0.31694261 0.92085882 0.31872765 0.85683061 -0.65102559\n", + " -1.03424284 0.68159452 -0.80340966 -0.68954978 -0.4555325 0.01747916\n", + " -0.35399391 -1.37495129 -0.6436184 -2.22340315 0.62523145 -1.60205766\n", + " -1.10438334 0.05216508 -0.739563 1.5430146 -1.29285691 0.26705087\n", + " -0.03928282 -1.1680935 0.52327666 -0.17154633 0.77179055 0.82350415\n", + " 2.16323595 1.33652795]\n" ] } ], @@ -67,17 +97,17 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 6, "id": "49c55822", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.5693345929456347" + "0.07091049314116117" ] }, - "execution_count": 2, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -89,17 +119,17 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "id": "03529459", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.7228107940950779" + "1.0433044724105929" ] }, - "execution_count": 3, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -111,17 +141,17 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "id": "e53f30c5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "0.8501828003994658" + "1.0214227686959954" ] }, - "execution_count": 4, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -133,7 +163,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 9, "id": "9bce852f", "metadata": {}, "outputs": [ @@ -141,14 +171,14 @@ "name": "stdout", "output_type": "stream", "text": [ - "Mode: ModeResult(mode=array([-1.7262826]), count=array([1]))\n" + "Mode: ModeResult(mode=array([-2.77259276]), count=array([1]))\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "/tmp/ipykernel_680/837115706.py:9: FutureWarning: Unlike other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode` typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of `keepdims` will become False, the `axis` over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set `keepdims` to True or False to avoid this warning.\n", + "/tmp/ipykernel_668/2492951849.py:9: FutureWarning: Unlike other reduction functions (e.g. `skew`, `kurtosis`), the default behavior of `mode` typically preserves the axis it acts along. In SciPy 1.11.0, this behavior will change: the default value of `keepdims` will become False, the `axis` over which the statistic is taken will be eliminated, and the value None will no longer be accepted. Set `keepdims` to True or False to avoid this warning.\n", " mode_result = stats.mode(data)\n" ] } @@ -160,7 +190,7 @@ "\n", "\n", "# Mode for continuous array\n", - "data = np.random.normal(0, 1, 20)\n", + "data = np.random.normal(0, 1, 200)\n", "\n", "mode_result = stats.mode(data)\n", "\n", @@ -170,7 +200,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 10, "id": "c682cb6e", "metadata": {}, "outputs": [ @@ -178,7 +208,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Mediana: -0.3806670488744016\n" + "Mediana: -0.14680835842106837\n" ] } ], @@ -192,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 11, "id": "39c3fabd", "metadata": {}, "outputs": [ @@ -200,10 +230,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "Percentil de 25 (Q1): -0.827558998828811\n", - "Percentil de 50 (Median): -0.3806670488744016\n", - "Percentil de 75 (Q3): 0.14109371863149622\n", - "Rango intercuartil (IQR): 0.9686527174603072\n" + "Percentil de 25 (Q1): -0.6900993503585511\n", + "Percentil de 50 (Median): -0.14680835842106837\n", + "Percentil de 75 (Q3): 0.5347408373388216\n", + "Rango intercuartil (IQR): 1.2248401876973727\n" ] } ], @@ -238,7 +268,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 14, "id": "d590308e", "metadata": {}, "outputs": [ @@ -247,55 +277,37 @@ "output_type": "stream", "text": [ "Datos: [4, 2, 5, 8, 6]\n", - "Desviación estándar: 2.0\n" + "Desviación Estándar: 2.0\n" ] } ], "source": [ - "\n", - "\n", - "import sys\n", "import math\n", + "import sys\n", + "import numpy as np\n", "\n", - "# Define the standard deviation function\n", - "def sd_calc(data):\n", + "# Función para calcular la desviación estándar\n", + "def desv_estandar(data):\n", " # Calcular la media utilizando la función np.mean()\n", - " mean = np.mean(data)\n", + " media = np.mean(data)\n", " \n", " # Calcular la suma de los cuadrados de las diferencias con la media\n", - " sum_of_squares = sum((x - mean) ** 2 for x in data)\n", + " suma_cuadrados = sum((x - media) ** 2 for x in data)\n", " \n", " # Calcular la varianza dividiendo la suma de los cuadrados entre el número de elementos\n", - " variance = sum_of_squares / len(data)\n", + " varianza = suma_cuadrados / len(data)\n", " \n", " # Calcular la desviación estándar tomando la raíz cuadrada de la varianza\n", - " std_deviation = math.sqrt(variance)\n", + " std_deviation = math.sqrt(varianza)\n", " \n", " return std_deviation\n", "\n", - "# Define the average function\n", - "def avg_calc(ls):\n", - " # Calcular la suma de los elementos\n", - " total = sum(ls)\n", - " \n", - " # Calcular la cantidad de elementos\n", - " count = len(ls)\n", - " \n", - " # Calcular el promedio\n", - " average = total / count\n", - " \n", - " return average\n", - " \n", + "# Datos\n", "data = [4, 2, 5, 8, 6]\n", "\n", - "# Imprimir los datos\n", + "# Imprimir los datos y la desviación estándar\n", "print(\"Datos:\", data)\n", - "\n", - "# Calcular la desviación estándar utilizando la función sd_calc()\n", - "std_deviation = sd_calc(data)\n", - "\n", - "# Imprimir la desviación estándar\n", - "print(\"Desviación estándar:\", std_deviation)" + "print(\"Desviación Estándar:\", desv_estandar(data))" ] }, {