Skip to content

Commit e9f0e19

Browse files
committed
Ejemplo distribuciones
1 parent a3ad891 commit e9f0e19

17 files changed

+198
-1
lines changed

scripts/tema12/04-mtcars.Rmd

+92
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,95 @@ linewidth = 2.0, color = "red")
6262
plt.show()
6363
```
6464

65+
### Medidas de dispersión
66+
- Rango de `mpg`, five nums, cuartiles
67+
```{python}
68+
from ggplot import mtcars
69+
70+
rang = max(mtcars["mpg"]) - min(mtcars["mpg"])
71+
print(rang)
72+
73+
five_nums = [mtcars["mpg"].quantile(0),
74+
mtcars["mpg"].quantile(0.25),
75+
mtcars["mpg"].quantile(0.5),
76+
mtcars["mpg"].quantile(0.75),
77+
mtcars["mpg"].quantile(1.0)
78+
]
79+
print(five_nums)
80+
81+
print(mtcars["mpg"].describe())
82+
83+
print(mtcars["mpg"].quantile(0.75) - mtcars["mpg"].quantile(0.25))
84+
85+
import matplotlib.pyplot as plt
86+
plt.clf()
87+
mtcars.boxplot(column = "mpg", return_type = "axes", figsize = (10,10))
88+
89+
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.25), s = "1r cuartil")
90+
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.5), s = "Mediana")
91+
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.75), s = "3r cuartil")
92+
93+
plt.text(x=0.9, y = mtcars["mpg"].quantile(0), s = "Min")
94+
plt.text(x=0.9, y = mtcars["mpg"].quantile(1), s = "Max")
95+
96+
plt.text(x = 0.7, y = mtcars["mpg"].quantile(0.5), s = "RIC", rotation = 90, size = 25)
97+
plt.show()
98+
```
99+
100+
- Varianza y desviación típica
101+
102+
```{python}
103+
from ggplot import mtcars
104+
105+
print(mtcars["mpg"].var())
106+
print(mtcars["mpg"].std())
107+
108+
mad = abs(mtcars["mpg"]-mtcars["mpg"].median())
109+
k = 1.4826
110+
print(mad.median()*k)
111+
```
112+
113+
- El sesgo y la curtosis
114+
115+
```{python}
116+
from ggplot import mtcars
117+
118+
print(mtcars["mpg"].skew())
119+
print(mtcars["mpg"].kurt())
120+
```
121+
122+
123+
```{python}
124+
import numpy as np
125+
import pandas as pd
126+
import matplotlib.pyplot as plt
127+
128+
norm = np.random.normal(size=100000)
129+
skew = np.concatenate((np.random.normal(size=35000)+2,
130+
np.random.exponential(size=65000)),
131+
axis = 0)
132+
unif = np.random.uniform(-2,2,size = 100000)
133+
peak = np.concatenate((np.random.exponential(size=50000),
134+
np.random.exponential(size=50000)*(-1)),
135+
axis = 0)
136+
137+
138+
data = pd.DataFrame({
139+
"normal": norm,
140+
"skew": skew,
141+
"unif": unif,
142+
"peak": peak
143+
})
144+
145+
plt.clf()
146+
data.plot(kind="density", figsize = (10,10), xlim = (-5,5))
147+
plt.show()
148+
149+
print("Normal, Sesgo = %f, Curtosis = %f"%(data["normal"].skew(), data["normal"].kurt()))
150+
print("Normal+Exp, Sesgo = %f, Curtosis = %f"%(data["skew"].skew(), data["skew"].kurt()))
151+
print("Uniforme, Sesgo = %f, Curtosis = %f"%(data["unif"].skew(), data["unif"].kurt()))
152+
print("Suma de Exp, Sesgo = %f, Curtosis = %f"%(data["peak"].skew(), data["peak"].kurt()))
153+
```
154+
155+
156+

scripts/tema12/04-mtcars.html

+105
Large diffs are not rendered by default.

scripts/tema12/04-mtcars_cache/html/unnamed-chunk-4_34ba42fb2cdb68fa02545b5dde03b4b8.rdb

Whitespace-only changes.

scripts/tema12/04-mtcars_cache/html/unnamed-chunk-5_74e513266090c39ab5aa10a42d5a9a0f.rdb

Whitespace-only changes.

scripts/tema12/04-mtcars_cache/html/unnamed-chunk-6_be7fafc54cdbc7359fc7467b0ddfa775.rdb

Whitespace-only changes.

scripts/tema12/04-mtcars_cache/html/unnamed-chunk-7_4c23474492559bb63ab40d99729e3567.rdb

Whitespace-only changes.
Loading
Loading

teoria/Tema10.Rmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Tema 10 - Introducción a la regresión lineal"
2+
title: Tema 10 - Introducción a la regresión lineal
33
author: "Juan Gabriel Gomila & María Santos"
44
output:
55
ioslides_presentation:

0 commit comments

Comments
 (0)