Skip to content

Commit

Permalink
Ejemplo distribuciones
Browse files Browse the repository at this point in the history
  • Loading branch information
joanby committed Jan 19, 2019
1 parent a3ad891 commit e9f0e19
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 1 deletion.
92 changes: 92 additions & 0 deletions scripts/tema12/04-mtcars.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,95 @@ linewidth = 2.0, color = "red")
plt.show()
```

### Medidas de dispersión
- Rango de `mpg`, five nums, cuartiles
```{python}
from ggplot import mtcars
rang = max(mtcars["mpg"]) - min(mtcars["mpg"])
print(rang)
five_nums = [mtcars["mpg"].quantile(0),
mtcars["mpg"].quantile(0.25),
mtcars["mpg"].quantile(0.5),
mtcars["mpg"].quantile(0.75),
mtcars["mpg"].quantile(1.0)
]
print(five_nums)
print(mtcars["mpg"].describe())
print(mtcars["mpg"].quantile(0.75) - mtcars["mpg"].quantile(0.25))
import matplotlib.pyplot as plt
plt.clf()
mtcars.boxplot(column = "mpg", return_type = "axes", figsize = (10,10))
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.25), s = "1r cuartil")
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.5), s = "Mediana")
plt.text(x=0.8, y = mtcars["mpg"].quantile(0.75), s = "3r cuartil")
plt.text(x=0.9, y = mtcars["mpg"].quantile(0), s = "Min")
plt.text(x=0.9, y = mtcars["mpg"].quantile(1), s = "Max")
plt.text(x = 0.7, y = mtcars["mpg"].quantile(0.5), s = "RIC", rotation = 90, size = 25)
plt.show()
```

- Varianza y desviación típica

```{python}
from ggplot import mtcars
print(mtcars["mpg"].var())
print(mtcars["mpg"].std())
mad = abs(mtcars["mpg"]-mtcars["mpg"].median())
k = 1.4826
print(mad.median()*k)
```

- El sesgo y la curtosis

```{python}
from ggplot import mtcars
print(mtcars["mpg"].skew())
print(mtcars["mpg"].kurt())
```


```{python}
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
norm = np.random.normal(size=100000)
skew = np.concatenate((np.random.normal(size=35000)+2,
np.random.exponential(size=65000)),
axis = 0)
unif = np.random.uniform(-2,2,size = 100000)
peak = np.concatenate((np.random.exponential(size=50000),
np.random.exponential(size=50000)*(-1)),
axis = 0)
data = pd.DataFrame({
"normal": norm,
"skew": skew,
"unif": unif,
"peak": peak
})
plt.clf()
data.plot(kind="density", figsize = (10,10), xlim = (-5,5))
plt.show()
print("Normal, Sesgo = %f, Curtosis = %f"%(data["normal"].skew(), data["normal"].kurt()))
print("Normal+Exp, Sesgo = %f, Curtosis = %f"%(data["skew"].skew(), data["skew"].kurt()))
print("Uniforme, Sesgo = %f, Curtosis = %f"%(data["unif"].skew(), data["unif"].kurt()))
print("Suma de Exp, Sesgo = %f, Curtosis = %f"%(data["peak"].skew(), data["peak"].kurt()))
```



105 changes: 105 additions & 0 deletions scripts/tema12/04-mtcars.html

Large diffs are not rendered by default.

Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion teoria/Tema10.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Tema 10 - Introducción a la regresión lineal"
title: Tema 10 - Introducción a la regresión lineal
author: "Juan Gabriel Gomila & María Santos"
output:
ioslides_presentation:
Expand Down

0 comments on commit e9f0e19

Please sign in to comment.