Skip to content

pull request estadistica descriptiva #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 186 additions & 54 deletions notebook/problems.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"id": "ac622319",
"metadata": {},
Expand All @@ -9,6 +10,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "aa8993e4",
"metadata": {},
Expand All @@ -17,6 +19,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "5e0ab0d5",
"metadata": {},
Expand All @@ -30,90 +33,227 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"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 -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"
]
}
],
"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": 6,
"id": "49c55822",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"0.07091049314116117"
]
},
"execution_count": 6,
"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": 7,
"id": "03529459",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1.0433044724105929"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#get the variance of your data"
"#get the variance of your data\n",
"data.var()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"id": "e53f30c5",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"1.0214227686959954"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Standard deviation\n"
"# Standard deviation\n",
"np.std(data)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 9,
"id": "9bce852f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mode: ModeResult(mode=array([-2.77259276]), count=array([1]))\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/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"
]
}
],
"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, 200)\n",
"\n",
"mode_result = stats.mode(data)\n",
"\n",
"# Mode for continuous array\n"
"\n",
"print(\"Mode:\", mode_result)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 10,
"id": "c682cb6e",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mediana: -0.14680835842106837\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": 11,
"id": "39c3fabd",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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"
]
}
],
"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",
"# This match with np.median, why?\n"
"\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": {},
Expand All @@ -128,58 +268,50 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 14,
"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",
"import sys\n",
"import numpy as np\n",
"\n",
"# Define the standard deviation function\n",
"\n",
"def sd_calc(data):\n",
" #code here\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",
" media = np.mean(data)\n",
" \n",
" # Calcular la suma de los cuadrados de las diferencias con la media\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",
" varianza = suma_cuadrados / len(data)\n",
" \n",
"\n",
" # calculate stan. dev.\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"# Define the average function\n",
"\n",
"def avg_calc(ls):\n",
" #code here\n",
" \n",
" \n",
" \n",
"\n",
" # calculate average\n",
" \n",
" \n",
" # Calcular la desviación estándar tomando la raíz cuadrada de la varianza\n",
" std_deviation = math.sqrt(varianza)\n",
" \n",
" return std_deviation\n",
"\n",
"# Datos\n",
"data = [4, 2, 5, 8, 6]\n",
"\n",
"#print the data\n",
"\n",
"#print the standard deviation of the data"
"# Imprimir los datos y la desviación estándar\n",
"print(\"Datos:\", data)\n",
"print(\"Desviación Estándar:\", desv_estandar(data))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "04b71791",
"metadata": {},
Expand Down Expand Up @@ -209,7 +341,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
"version": "3.11.3"
}
},
"nbformat": 4,
Expand Down