# Descriptive Statistics.

Working with dataset: 
- https://archive.ics.uci.edu/ml/datasets/Vertebral+Column


```python
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
```

Vamos a ver aquí algunas medidas iniciales para el análisis de datos. El análisis inicial de los datos es muy importante para hacer estimaciones y sacar conclusiones.


```python
names=["pelvic_incidence","pelvic_tilt","lumbar_lordosis_angle","sacral_slope","pelvic_radius","degree_spondylolisthesis","class"]
data=pd.read_csv("../Datas/VertebralColumn/column_2C.dat",delimiter="\s+",names=names)
```


```python
data
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>pelvic_incidence</th>
      <th>pelvic_tilt</th>
      <th>lumbar_lordosis_angle</th>
      <th>sacral_slope</th>
      <th>pelvic_radius</th>
      <th>degree_spondylolisthesis</th>
      <th>class</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>63.03</td>
      <td>22.55</td>
      <td>39.61</td>
      <td>40.48</td>
      <td>98.67</td>
      <td>-0.25</td>
      <td>AB</td>
    </tr>
    <tr>
      <th>1</th>
      <td>39.06</td>
      <td>10.06</td>
      <td>25.02</td>
      <td>29.00</td>
      <td>114.41</td>
      <td>4.56</td>
      <td>AB</td>
    </tr>
    <tr>
      <th>2</th>
      <td>68.83</td>
      <td>22.22</td>
      <td>50.09</td>
      <td>46.61</td>
      <td>105.99</td>
      <td>-3.53</td>
      <td>AB</td>
    </tr>
    <tr>
      <th>3</th>
      <td>69.30</td>
      <td>24.65</td>
      <td>44.31</td>
      <td>44.64</td>
      <td>101.87</td>
      <td>11.21</td>
      <td>AB</td>
    </tr>
    <tr>
      <th>4</th>
      <td>49.71</td>
      <td>9.65</td>
      <td>28.32</td>
      <td>40.06</td>
      <td>108.17</td>
      <td>7.92</td>
      <td>AB</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>305</th>
      <td>47.90</td>
      <td>13.62</td>
      <td>36.00</td>
      <td>34.29</td>
      <td>117.45</td>
      <td>-4.25</td>
      <td>NO</td>
    </tr>
    <tr>
      <th>306</th>
      <td>53.94</td>
      <td>20.72</td>
      <td>29.22</td>
      <td>33.22</td>
      <td>114.37</td>
      <td>-0.42</td>
      <td>NO</td>
    </tr>
    <tr>
      <th>307</th>
      <td>61.45</td>
      <td>22.69</td>
      <td>46.17</td>
      <td>38.75</td>
      <td>125.67</td>
      <td>-2.71</td>
      <td>NO</td>
    </tr>
    <tr>
      <th>308</th>
      <td>45.25</td>
      <td>8.69</td>
      <td>41.58</td>
      <td>36.56</td>
      <td>118.55</td>
      <td>0.21</td>
      <td>NO</td>
    </tr>
    <tr>
      <th>309</th>
      <td>33.84</td>
      <td>5.07</td>
      <td>36.64</td>
      <td>28.77</td>
      <td>123.95</td>
      <td>-0.20</td>
      <td>NO</td>
    </tr>
  </tbody>
</table>
<p>310 rows × 7 columns</p>
</div>



Podemos hacer primero una visión general de nuestros datos para entender cual es el compotamiento de las variables que tenemos en el estudio. Esto podemos hacerlo muy fácilmente con Python usando una librería de pandas y usando algunos de los algoritmos y funciones predefinidas.


```python
print("El número de variables es N_var =",len(data.columns))
print("El número de casos o instancias (o individuos estudiados) es N =",len(data))
```

    El número de variables es N_var = 7
    El número de casos o instancias (o individuos estudiados) es N = 310


Algunos estdísticos comunes y usuales. Por ejemplo podemos calcular la media, mediana y moda, así como también las desviaciones estándar y varianzas para cada una de las 7 variables.

- Media (Promedio): 
\begin{equation}
\bar x=\frac{1}{N}\sum_{i=0}^{N-1}x_i
\end{equation}
- Mediana (Cuartil 50): Con datos ordenados en orden ascendente:
\begin{equation}
median=\left\{\begin{matrix}
x\left[\frac{N}{2}\right] &  \mbox{si $N$ es par}\\
\frac{1}{2}\left(x\left[\frac{N-1}{2}\right]+x\left[\frac{N+1}{2}\right]\right) &  \mbox{si $N$ es impar}\\
\end{matrix}\right.
\end{equation}
- Moda (dato con mayor frecuencia)
- varianza:
\begin{equation}
s^2(x)=\mbox{Var}(x)=\frac{1}{N}\sum_{i=0}^{N-1}(x_i-\bar x)^2
\end{equation}
- Desviación estándar:
\begin{equation}
\sigma_x=s(x)=\sqrt{\mbox{Var}(x)}=\sqrt{\frac{1}{N}\sum_{i=0}^{N-1}(x_i-\bar x)^2}
\end{equation}



```python
def average(var):
    return np.sum(var)/len(var)
def median(var):
    var_ord=np.sort(var)
    N=len(var_ord)
    if N%2==0:
        median=var_ord[N//2]
    if N%2!=0:
        median=(var_ord[(N-1)//2]+var_ord[(N+1)//2])/2
    return median
def mode(var):
    dat,frec=np.unique(var,return_counts=True)
    if len(dat[frec==frec.max()])>1:
        print("Existen varias modas (la variable es multimodal)")
    if len(dat[frec==frec.max()])==1:
        print("Existe una moda (la variable es unimodal)")
    return dat[frec==frec.max()]
```


```python
def variance(var):
    return np.sum((var-average(var))**2)/len(var)
def std(var):
    return np.sqrt(variance(var))
```


```python
for i in data.columns[:-1]:
    print("Para la variable "+str(i),"el promedio (la media) es <{}> =".format(str(i)),average(data[i]))
```

    Para la variable pelvic_incidence el promedio (la media) es <pelvic_incidence> = 60.49648387096773
    Para la variable pelvic_tilt el promedio (la media) es <pelvic_tilt> = 17.542903225806448
    Para la variable lumbar_lordosis_angle el promedio (la media) es <lumbar_lordosis_angle> = 51.93070967741936
    Para la variable sacral_slope el promedio (la media) es <sacral_slope> = 42.953870967741935
    Para la variable pelvic_radius el promedio (la media) es <pelvic_radius> = 117.92054838709676
    Para la variable degree_spondylolisthesis el promedio (la media) es <degree_spondylolisthesis> = 26.296741935483873



```python
for i in data.columns[:-1]:
    print("Para la variable "+str(i),"la mediana es med({}) =".format(str(i)),median(data[i]))
```

    Para la variable pelvic_incidence la mediana es med(pelvic_incidence) = 58.78
    Para la variable pelvic_tilt la mediana es med(pelvic_tilt) = 16.42
    Para la variable lumbar_lordosis_angle la mediana es med(lumbar_lordosis_angle) = 49.78
    Para la variable sacral_slope la mediana es med(sacral_slope) = 42.44
    Para la variable pelvic_radius la mediana es med(pelvic_radius) = 118.34
    Para la variable degree_spondylolisthesis la mediana es med(degree_spondylolisthesis) = 12.07



```python
for i in data.columns[:-1]:
    print("Para la variable "+str(i),"la moda es moda({}) =".format(str(i)),mode(data[i]))
```

    Existen varias modas (la variable es multimodal)
    Para la variable pelvic_incidence la moda es moda(pelvic_incidence) = [42.52 49.71 50.91 53.94 54.92 63.03 65.01 65.76 74.72]
    Existen varias modas (la variable es multimodal)
    Para la variable pelvic_tilt la moda es moda(pelvic_tilt) = [ 5.27  8.4  10.06 10.22 10.76 13.11 13.28 13.92 14.38 15.4  16.42 16.74
     17.44 19.44 21.12 23.08 26.33 33.28 37.52]
    Existen varias modas (la variable es multimodal)
    Para la variable lumbar_lordosis_angle la moda es moda(lumbar_lordosis_angle) = [35. 42. 47. 52. 58.]
    Existe una moda (la variable es unimodal)
    Para la variable sacral_slope la moda es moda(sacral_slope) = [56.31]
    Existen varias modas (la variable es multimodal)
    Para la variable pelvic_radius la moda es moda(pelvic_radius) = [110.71 116.56 116.59 116.8  117.98 119.32 129.39]
    Existen varias modas (la variable es multimodal)
    Para la variable degree_spondylolisthesis la moda es moda(degree_spondylolisthesis) = [-4.08 -2.01  1.01  3.09  4.96]



```python
for i in data.columns[:-1]:
    print("Para la variable "+str(i),"la varianza es Var({}) =".format(str(i)),variance(data[i]))
```

    Para la variable pelvic_incidence la varianza es Var(pelvic_incidence) = 296.12512021748176
    Para la variable pelvic_tilt la varianza es Var(pelvic_tilt) = 99.83976124869929
    Para la variable lumbar_lordosis_angle la varianza es Var(lumbar_lordosis_angle) = 343.13176723829343
    Para la variable sacral_slope la varianza es Var(sacral_slope) = 179.5889740478668
    Para la variable pelvic_radius la varianza es Var(pelvic_radius) = 176.7871277637877
    Para la variable degree_spondylolisthesis la varianza es Var(degree_spondylolisthesis) = 1406.119148417274



```python
for i in data.columns[:-1]:
    print("Para la variable "+str(i),"la desviación estándar es STD({}) =".format(str(i)),std(data[i]))
```

    Para la variable pelvic_incidence la desviación estándar es STD(pelvic_incidence) = 17.208286382364797
    Para la variable pelvic_tilt la desviación estándar es STD(pelvic_tilt) = 9.991984850303732
    Para la variable lumbar_lordosis_angle la desviación estándar es STD(lumbar_lordosis_angle) = 18.523816216921755
    Para la variable sacral_slope la desviación estándar es STD(sacral_slope) = 13.401081077579779
    Para la variable pelvic_radius la desviación estándar es STD(pelvic_radius) = 13.296132060256761
    Para la variable degree_spondylolisthesis la desviación estándar es STD(degree_spondylolisthesis) = 37.49825527164263


También podemos usar una función de Pandas que reune algunos estadísticos básicos:


```python
vertebral_stats=data.describe().T
```


```python
vertebral_stats
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>count</th>
      <th>mean</th>
      <th>std</th>
      <th>min</th>
      <th>25%</th>
      <th>50%</th>
      <th>75%</th>
      <th>max</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>pelvic_incidence</th>
      <td>310.0</td>
      <td>60.496484</td>
      <td>17.236109</td>
      <td>26.15</td>
      <td>46.4325</td>
      <td>58.690</td>
      <td>72.8800</td>
      <td>129.83</td>
    </tr>
    <tr>
      <th>pelvic_tilt</th>
      <td>310.0</td>
      <td>17.542903</td>
      <td>10.008140</td>
      <td>-6.55</td>
      <td>10.6675</td>
      <td>16.360</td>
      <td>22.1200</td>
      <td>49.43</td>
    </tr>
    <tr>
      <th>lumbar_lordosis_angle</th>
      <td>310.0</td>
      <td>51.930710</td>
      <td>18.553766</td>
      <td>14.00</td>
      <td>37.0000</td>
      <td>49.565</td>
      <td>63.0000</td>
      <td>125.74</td>
    </tr>
    <tr>
      <th>sacral_slope</th>
      <td>310.0</td>
      <td>42.953871</td>
      <td>13.422748</td>
      <td>13.37</td>
      <td>33.3475</td>
      <td>42.405</td>
      <td>52.6925</td>
      <td>121.43</td>
    </tr>
    <tr>
      <th>pelvic_radius</th>
      <td>310.0</td>
      <td>117.920548</td>
      <td>13.317629</td>
      <td>70.08</td>
      <td>110.7100</td>
      <td>118.265</td>
      <td>125.4675</td>
      <td>163.07</td>
    </tr>
    <tr>
      <th>degree_spondylolisthesis</th>
      <td>310.0</td>
      <td>26.296742</td>
      <td>37.558883</td>
      <td>-11.06</td>
      <td>1.6000</td>
      <td>11.765</td>
      <td>41.2850</td>
      <td>418.54</td>
    </tr>
  </tbody>
</table>
</div>



también podemos usar las funciones que están predefinidas en Python para estas tareas:


```python
import scipy.stats as st
# La mediana puede ser también calculada, así como el coeficiente de asimetría y curtosis respectivamente
print(data.columns)
print("media =",np.mean(data.loc[:, data.columns != 'class'],axis=0))
print("median =",np.median(data.loc[:, data.columns != 'class'],axis=0))
print("varianza =",np.var(data.loc[:, data.columns != 'class'],axis=0))
print("desviación estándar =",np.std(data.loc[:, data.columns != 'class'],axis=0))
print("skewness =",st.skew(data.loc[:, data.columns != 'class'],axis=0))
print("kurtosis =",st.kurtosis(data.loc[:, data.columns != 'class'],axis=0))
```

    Index(['pelvic_incidence', 'pelvic_tilt', 'lumbar_lordosis_angle',
           'sacral_slope', 'pelvic_radius', 'degree_spondylolisthesis', 'class'],
          dtype='object')
    media = pelvic_incidence             60.496484
    pelvic_tilt                  17.542903
    lumbar_lordosis_angle        51.930710
    sacral_slope                 42.953871
    pelvic_radius               117.920548
    degree_spondylolisthesis     26.296742
    dtype: float64
    median = [ 58.69   16.36   49.565  42.405 118.265  11.765]
    varianza = pelvic_incidence             296.125120
    pelvic_tilt                   99.839761
    lumbar_lordosis_angle        343.131767
    sacral_slope                 179.588974
    pelvic_radius                176.787128
    degree_spondylolisthesis    1406.119148
    dtype: float64
    desviación estándar = pelvic_incidence            17.208286
    pelvic_tilt                  9.991985
    lumbar_lordosis_angle       18.523816
    sacral_slope                13.401081
    pelvic_radius               13.296132
    degree_spondylolisthesis    37.498255
    dtype: float64
    skewness = [ 0.51786409  0.67329913  0.5964695   0.78883655 -0.17607403  4.29696644]
    kurtosis = [ 0.2006561   0.64597047  0.13977901  2.94050906  0.90035703 37.4374569 ]



```python
vertebral_stats["median"]=np.median(data.loc[:, data.columns != 'class'],axis=0)
vertebral_stats["skewness"]=st.skew(data.loc[:, data.columns != 'class'],axis=0)
vertebral_stats["kurtosis"]=st.kurtosis(data.loc[:, data.columns != 'class'],axis=0)
```


```python
vertebral_stats
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>count</th>
      <th>mean</th>
      <th>std</th>
      <th>min</th>
      <th>25%</th>
      <th>50%</th>
      <th>75%</th>
      <th>max</th>
      <th>median</th>
      <th>skewness</th>
      <th>kurtosis</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>pelvic_incidence</th>
      <td>310.0</td>
      <td>60.496484</td>
      <td>17.236109</td>
      <td>26.15</td>
      <td>46.4325</td>
      <td>58.690</td>
      <td>72.8800</td>
      <td>129.83</td>
      <td>58.690</td>
      <td>0.517864</td>
      <td>0.200656</td>
    </tr>
    <tr>
      <th>pelvic_tilt</th>
      <td>310.0</td>
      <td>17.542903</td>
      <td>10.008140</td>
      <td>-6.55</td>
      <td>10.6675</td>
      <td>16.360</td>
      <td>22.1200</td>
      <td>49.43</td>
      <td>16.360</td>
      <td>0.673299</td>
      <td>0.645970</td>
    </tr>
    <tr>
      <th>lumbar_lordosis_angle</th>
      <td>310.0</td>
      <td>51.930710</td>
      <td>18.553766</td>
      <td>14.00</td>
      <td>37.0000</td>
      <td>49.565</td>
      <td>63.0000</td>
      <td>125.74</td>
      <td>49.565</td>
      <td>0.596469</td>
      <td>0.139779</td>
    </tr>
    <tr>
      <th>sacral_slope</th>
      <td>310.0</td>
      <td>42.953871</td>
      <td>13.422748</td>
      <td>13.37</td>
      <td>33.3475</td>
      <td>42.405</td>
      <td>52.6925</td>
      <td>121.43</td>
      <td>42.405</td>
      <td>0.788837</td>
      <td>2.940509</td>
    </tr>
    <tr>
      <th>pelvic_radius</th>
      <td>310.0</td>
      <td>117.920548</td>
      <td>13.317629</td>
      <td>70.08</td>
      <td>110.7100</td>
      <td>118.265</td>
      <td>125.4675</td>
      <td>163.07</td>
      <td>118.265</td>
      <td>-0.176074</td>
      <td>0.900357</td>
    </tr>
    <tr>
      <th>degree_spondylolisthesis</th>
      <td>310.0</td>
      <td>26.296742</td>
      <td>37.558883</td>
      <td>-11.06</td>
      <td>1.6000</td>
      <td>11.765</td>
      <td>41.2850</td>
      <td>418.54</td>
      <td>11.765</td>
      <td>4.296966</td>
      <td>37.437457</td>
    </tr>
  </tbody>
</table>
</div>




```python

```


```python

```

Ahora entendamos el problema en el que nos embarcamos. Resulta que los datos pueden contener outliers, o en otras palabras, hay datos que parecen estar fuera del rango de valores del conjunto total. Veamos esto con otro conjunto de datos: https://archive.ics.uci.edu/ml/datasets/ionosphere


```python
#names=["pelvic_incidence","pelvic_tilt","lumbar_lordosis_angle","sacral_slope","pelvic_radius","degree_spondylolisthesis","class"]
data=pd.read_csv("../Datas/Ionosphere/ionosphere.data",delimiter=",",names=["Atr"+str(i) for i in range(35)])
```


```python
data
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Atr0</th>
      <th>Atr1</th>
      <th>Atr2</th>
      <th>Atr3</th>
      <th>Atr4</th>
      <th>Atr5</th>
      <th>Atr6</th>
      <th>Atr7</th>
      <th>Atr8</th>
      <th>Atr9</th>
      <th>...</th>
      <th>Atr25</th>
      <th>Atr26</th>
      <th>Atr27</th>
      <th>Atr28</th>
      <th>Atr29</th>
      <th>Atr30</th>
      <th>Atr31</th>
      <th>Atr32</th>
      <th>Atr33</th>
      <th>Atr34</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>0</td>
      <td>0.99539</td>
      <td>-0.05889</td>
      <td>0.85243</td>
      <td>0.02306</td>
      <td>0.83398</td>
      <td>-0.37708</td>
      <td>1.00000</td>
      <td>0.03760</td>
      <td>...</td>
      <td>-0.51171</td>
      <td>0.41078</td>
      <td>-0.46168</td>
      <td>0.21266</td>
      <td>-0.34090</td>
      <td>0.42267</td>
      <td>-0.54487</td>
      <td>0.18641</td>
      <td>-0.45300</td>
      <td>g</td>
    </tr>
    <tr>
      <th>1</th>
      <td>1</td>
      <td>0</td>
      <td>1.00000</td>
      <td>-0.18829</td>
      <td>0.93035</td>
      <td>-0.36156</td>
      <td>-0.10868</td>
      <td>-0.93597</td>
      <td>1.00000</td>
      <td>-0.04549</td>
      <td>...</td>
      <td>-0.26569</td>
      <td>-0.20468</td>
      <td>-0.18401</td>
      <td>-0.19040</td>
      <td>-0.11593</td>
      <td>-0.16626</td>
      <td>-0.06288</td>
      <td>-0.13738</td>
      <td>-0.02447</td>
      <td>b</td>
    </tr>
    <tr>
      <th>2</th>
      <td>1</td>
      <td>0</td>
      <td>1.00000</td>
      <td>-0.03365</td>
      <td>1.00000</td>
      <td>0.00485</td>
      <td>1.00000</td>
      <td>-0.12062</td>
      <td>0.88965</td>
      <td>0.01198</td>
      <td>...</td>
      <td>-0.40220</td>
      <td>0.58984</td>
      <td>-0.22145</td>
      <td>0.43100</td>
      <td>-0.17365</td>
      <td>0.60436</td>
      <td>-0.24180</td>
      <td>0.56045</td>
      <td>-0.38238</td>
      <td>g</td>
    </tr>
    <tr>
      <th>3</th>
      <td>1</td>
      <td>0</td>
      <td>1.00000</td>
      <td>-0.45161</td>
      <td>1.00000</td>
      <td>1.00000</td>
      <td>0.71216</td>
      <td>-1.00000</td>
      <td>0.00000</td>
      <td>0.00000</td>
      <td>...</td>
      <td>0.90695</td>
      <td>0.51613</td>
      <td>1.00000</td>
      <td>1.00000</td>
      <td>-0.20099</td>
      <td>0.25682</td>
      <td>1.00000</td>
      <td>-0.32382</td>
      <td>1.00000</td>
      <td>b</td>
    </tr>
    <tr>
      <th>4</th>
      <td>1</td>
      <td>0</td>
      <td>1.00000</td>
      <td>-0.02401</td>
      <td>0.94140</td>
      <td>0.06531</td>
      <td>0.92106</td>
      <td>-0.23255</td>
      <td>0.77152</td>
      <td>-0.16399</td>
      <td>...</td>
      <td>-0.65158</td>
      <td>0.13290</td>
      <td>-0.53206</td>
      <td>0.02431</td>
      <td>-0.62197</td>
      <td>-0.05707</td>
      <td>-0.59573</td>
      <td>-0.04608</td>
      <td>-0.65697</td>
      <td>g</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>346</th>
      <td>1</td>
      <td>0</td>
      <td>0.83508</td>
      <td>0.08298</td>
      <td>0.73739</td>
      <td>-0.14706</td>
      <td>0.84349</td>
      <td>-0.05567</td>
      <td>0.90441</td>
      <td>-0.04622</td>
      <td>...</td>
      <td>-0.04202</td>
      <td>0.83479</td>
      <td>0.00123</td>
      <td>1.00000</td>
      <td>0.12815</td>
      <td>0.86660</td>
      <td>-0.10714</td>
      <td>0.90546</td>
      <td>-0.04307</td>
      <td>g</td>
    </tr>
    <tr>
      <th>347</th>
      <td>1</td>
      <td>0</td>
      <td>0.95113</td>
      <td>0.00419</td>
      <td>0.95183</td>
      <td>-0.02723</td>
      <td>0.93438</td>
      <td>-0.01920</td>
      <td>0.94590</td>
      <td>0.01606</td>
      <td>...</td>
      <td>0.01361</td>
      <td>0.93522</td>
      <td>0.04925</td>
      <td>0.93159</td>
      <td>0.08168</td>
      <td>0.94066</td>
      <td>-0.00035</td>
      <td>0.91483</td>
      <td>0.04712</td>
      <td>g</td>
    </tr>
    <tr>
      <th>348</th>
      <td>1</td>
      <td>0</td>
      <td>0.94701</td>
      <td>-0.00034</td>
      <td>0.93207</td>
      <td>-0.03227</td>
      <td>0.95177</td>
      <td>-0.03431</td>
      <td>0.95584</td>
      <td>0.02446</td>
      <td>...</td>
      <td>0.03193</td>
      <td>0.92489</td>
      <td>0.02542</td>
      <td>0.92120</td>
      <td>0.02242</td>
      <td>0.92459</td>
      <td>0.00442</td>
      <td>0.92697</td>
      <td>-0.00577</td>
      <td>g</td>
    </tr>
    <tr>
      <th>349</th>
      <td>1</td>
      <td>0</td>
      <td>0.90608</td>
      <td>-0.01657</td>
      <td>0.98122</td>
      <td>-0.01989</td>
      <td>0.95691</td>
      <td>-0.03646</td>
      <td>0.85746</td>
      <td>0.00110</td>
      <td>...</td>
      <td>-0.02099</td>
      <td>0.89147</td>
      <td>-0.07760</td>
      <td>0.82983</td>
      <td>-0.17238</td>
      <td>0.96022</td>
      <td>-0.03757</td>
      <td>0.87403</td>
      <td>-0.16243</td>
      <td>g</td>
    </tr>
    <tr>
      <th>350</th>
      <td>1</td>
      <td>0</td>
      <td>0.84710</td>
      <td>0.13533</td>
      <td>0.73638</td>
      <td>-0.06151</td>
      <td>0.87873</td>
      <td>0.08260</td>
      <td>0.88928</td>
      <td>-0.09139</td>
      <td>...</td>
      <td>-0.15114</td>
      <td>0.81147</td>
      <td>-0.04822</td>
      <td>0.78207</td>
      <td>-0.00703</td>
      <td>0.75747</td>
      <td>-0.06678</td>
      <td>0.85764</td>
      <td>-0.06151</td>
      <td>g</td>
    </tr>
  </tbody>
</table>
<p>351 rows × 35 columns</p>
</div>




```python
len(data.columns)
```




    35




```python
plt.figure(figsize=(30,6))
data.iloc[:,2:].boxplot(grid=True,fontsize=15)
plt.legend(fontsize=16)
#plt.xticks(range(1,7),np.array(["pelvic \n incidence","pelvic \n tilt","lumbar \n lordosis \n angle","sacral \n slope","pelvic \n radius","degree \n spondylolisthesis"]),fontsize=16)
plt.yticks(fontsize=16)
plt.savefig("../../figures/ionosphere_boxplot1.png",bbox_inches ="tight")
plt.show()
```


```python
ionosphere_stats=data.describe().T
```


```python
ionosphere_stats["LII"]=ionosphere_stats["25%"]-((ionosphere_stats["75%"]-ionosphere_stats["25%"])*1.5)
ionosphere_stats["LIS"]=ionosphere_stats["75%"]+((ionosphere_stats["75%"]-ionosphere_stats["25%"])*1.5)
ionosphere_stats["LEI"]=ionosphere_stats["25%"]-((ionosphere_stats["75%"]-ionosphere_stats["25%"])*3.0)
ionosphere_stats["LES"]=ionosphere_stats["75%"]+((ionosphere_stats["75%"]-ionosphere_stats["25%"])*3.0)
```


```python
ionosphere_stats
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>count</th>
      <th>mean</th>
      <th>std</th>
      <th>min</th>
      <th>25%</th>
      <th>50%</th>
      <th>75%</th>
      <th>max</th>
      <th>LII</th>
      <th>LIS</th>
      <th>LEI</th>
      <th>LES</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>Atr0</th>
      <td>351.0</td>
      <td>0.891738</td>
      <td>0.311155</td>
      <td>0.0</td>
      <td>1.000000</td>
      <td>1.00000</td>
      <td>1.000000</td>
      <td>1.0</td>
      <td>1.000000</td>
      <td>1.000000</td>
      <td>1.000000</td>
      <td>1.000000</td>
    </tr>
    <tr>
      <th>Atr1</th>
      <td>351.0</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.0</td>
      <td>0.000000</td>
      <td>0.00000</td>
      <td>0.000000</td>
      <td>0.0</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.000000</td>
      <td>0.000000</td>
    </tr>
    <tr>
      <th>Atr2</th>
      <td>351.0</td>
      <td>0.641342</td>
      <td>0.497708</td>
      <td>-1.0</td>
      <td>0.472135</td>
      <td>0.87111</td>
      <td>1.000000</td>
      <td>1.0</td>
      <td>-0.319663</td>
      <td>1.791797</td>
      <td>-1.111460</td>
      <td>2.583595</td>
    </tr>
    <tr>
      <th>Atr3</th>
      <td>351.0</td>
      <td>0.044372</td>
      <td>0.441435</td>
      <td>-1.0</td>
      <td>-0.064735</td>
      <td>0.01631</td>
      <td>0.194185</td>
      <td>1.0</td>
      <td>-0.453115</td>
      <td>0.582565</td>
      <td>-0.841495</td>
      <td>0.970945</td>
    </tr>
    <tr>
      <th>Atr4</th>
      <td>351.0</td>
      <td>0.601068</td>
      <td>0.519862</td>
      <td>-1.0</td>
      <td>0.412660</td>
      <td>0.80920</td>
      <td>1.000000</td>
      <td>1.0</td>
      <td>-0.468350</td>
      <td>1.881010</td>
      <td>-1.349360</td>
      <td>2.762020</td>
    </tr>
    <tr>
      <th>Atr5</th>
      <td>351.0</td>
      <td>0.115889</td>
      <td>0.460810</td>
      <td>-1.0</td>
      <td>-0.024795</td>
      <td>0.02280</td>
      <td>0.334655</td>
      <td>1.0</td>
      <td>-0.563970</td>
      <td>0.873830</td>
      <td>-1.103145</td>
      <td>1.413005</td>
    </tr>
    <tr>
      <th>Atr6</th>
      <td>351.0</td>
      <td>0.550095</td>
      <td>0.492654</td>
      <td>-1.0</td>
      <td>0.211310</td>
      <td>0.72873</td>
      <td>0.969240</td>
      <td>1.0</td>
      <td>-0.925585</td>
      <td>2.106135</td>
      <td>-2.062480</td>
      <td>3.243030</td>
    </tr>
    <tr>
      <th>Atr7</th>
      <td>351.0</td>
      <td>0.119360</td>
      <td>0.520750</td>
      <td>-1.0</td>
      <td>-0.054840</td>
      <td>0.01471</td>
      <td>0.445675</td>
      <td>1.0</td>
      <td>-0.805613</td>
      <td>1.196448</td>
      <td>-1.556385</td>
      <td>1.947220</td>
    </tr>
    <tr>
      <th>Atr8</th>
      <td>351.0</td>
      <td>0.511848</td>
      <td>0.507066</td>
      <td>-1.0</td>
      <td>0.087110</td>
      <td>0.68421</td>
      <td>0.953240</td>
      <td>1.0</td>
      <td>-1.212085</td>
      <td>2.252435</td>
      <td>-2.511280</td>
      <td>3.551630</td>
    </tr>
    <tr>
      <th>Atr9</th>
      <td>351.0</td>
      <td>0.181345</td>
      <td>0.483851</td>
      <td>-1.0</td>
      <td>-0.048075</td>
      <td>0.01829</td>
      <td>0.534195</td>
      <td>1.0</td>
      <td>-0.921480</td>
      <td>1.407600</td>
      <td>-1.794885</td>
      <td>2.281005</td>
    </tr>
    <tr>
      <th>Atr10</th>
      <td>351.0</td>
      <td>0.476183</td>
      <td>0.563496</td>
      <td>-1.0</td>
      <td>0.021120</td>
      <td>0.66798</td>
      <td>0.957895</td>
      <td>1.0</td>
      <td>-1.384043</td>
      <td>2.363058</td>
      <td>-2.789205</td>
      <td>3.768220</td>
    </tr>
    <tr>
      <th>Atr11</th>
      <td>351.0</td>
      <td>0.155040</td>
      <td>0.494817</td>
      <td>-1.0</td>
      <td>-0.065265</td>
      <td>0.02825</td>
      <td>0.482375</td>
      <td>1.0</td>
      <td>-0.886725</td>
      <td>1.303835</td>
      <td>-1.708185</td>
      <td>2.125295</td>
    </tr>
    <tr>
      <th>Atr12</th>
      <td>351.0</td>
      <td>0.400801</td>
      <td>0.622186</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.64407</td>
      <td>0.955505</td>
      <td>1.0</td>
      <td>-1.433258</td>
      <td>2.388763</td>
      <td>-2.866515</td>
      <td>3.822020</td>
    </tr>
    <tr>
      <th>Atr13</th>
      <td>351.0</td>
      <td>0.093414</td>
      <td>0.494873</td>
      <td>-1.0</td>
      <td>-0.073725</td>
      <td>0.03027</td>
      <td>0.374860</td>
      <td>1.0</td>
      <td>-0.746602</td>
      <td>1.047737</td>
      <td>-1.419480</td>
      <td>1.720615</td>
    </tr>
    <tr>
      <th>Atr14</th>
      <td>351.0</td>
      <td>0.344159</td>
      <td>0.652828</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.60194</td>
      <td>0.919330</td>
      <td>1.0</td>
      <td>-1.378995</td>
      <td>2.298325</td>
      <td>-2.757990</td>
      <td>3.677320</td>
    </tr>
    <tr>
      <th>Atr15</th>
      <td>351.0</td>
      <td>0.071132</td>
      <td>0.458371</td>
      <td>-1.0</td>
      <td>-0.081705</td>
      <td>0.00000</td>
      <td>0.308975</td>
      <td>1.0</td>
      <td>-0.667725</td>
      <td>0.894995</td>
      <td>-1.253745</td>
      <td>1.481015</td>
    </tr>
    <tr>
      <th>Atr16</th>
      <td>351.0</td>
      <td>0.381949</td>
      <td>0.618020</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.59091</td>
      <td>0.935705</td>
      <td>1.0</td>
      <td>-1.403558</td>
      <td>2.339263</td>
      <td>-2.807115</td>
      <td>3.742820</td>
    </tr>
    <tr>
      <th>Atr17</th>
      <td>351.0</td>
      <td>-0.003617</td>
      <td>0.496762</td>
      <td>-1.0</td>
      <td>-0.225690</td>
      <td>0.00000</td>
      <td>0.195285</td>
      <td>1.0</td>
      <td>-0.857152</td>
      <td>0.826747</td>
      <td>-1.488615</td>
      <td>1.458210</td>
    </tr>
    <tr>
      <th>Atr18</th>
      <td>351.0</td>
      <td>0.359390</td>
      <td>0.626267</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.57619</td>
      <td>0.899265</td>
      <td>1.0</td>
      <td>-1.348898</td>
      <td>2.248163</td>
      <td>-2.697795</td>
      <td>3.597060</td>
    </tr>
    <tr>
      <th>Atr19</th>
      <td>351.0</td>
      <td>-0.024025</td>
      <td>0.519076</td>
      <td>-1.0</td>
      <td>-0.234670</td>
      <td>0.00000</td>
      <td>0.134370</td>
      <td>1.0</td>
      <td>-0.788230</td>
      <td>0.687930</td>
      <td>-1.341790</td>
      <td>1.241490</td>
    </tr>
    <tr>
      <th>Atr20</th>
      <td>351.0</td>
      <td>0.336695</td>
      <td>0.609828</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.49909</td>
      <td>0.894865</td>
      <td>1.0</td>
      <td>-1.342297</td>
      <td>2.237163</td>
      <td>-2.684595</td>
      <td>3.579460</td>
    </tr>
    <tr>
      <th>Atr21</th>
      <td>351.0</td>
      <td>0.008296</td>
      <td>0.518166</td>
      <td>-1.0</td>
      <td>-0.243870</td>
      <td>0.00000</td>
      <td>0.188760</td>
      <td>1.0</td>
      <td>-0.892815</td>
      <td>0.837705</td>
      <td>-1.541760</td>
      <td>1.486650</td>
    </tr>
    <tr>
      <th>Atr22</th>
      <td>351.0</td>
      <td>0.362475</td>
      <td>0.603767</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.53176</td>
      <td>0.911235</td>
      <td>1.0</td>
      <td>-1.366853</td>
      <td>2.278087</td>
      <td>-2.733705</td>
      <td>3.644940</td>
    </tr>
    <tr>
      <th>Atr23</th>
      <td>351.0</td>
      <td>-0.057406</td>
      <td>0.527456</td>
      <td>-1.0</td>
      <td>-0.366885</td>
      <td>0.00000</td>
      <td>0.164630</td>
      <td>1.0</td>
      <td>-1.164157</td>
      <td>0.961902</td>
      <td>-1.961430</td>
      <td>1.759175</td>
    </tr>
    <tr>
      <th>Atr24</th>
      <td>351.0</td>
      <td>0.396135</td>
      <td>0.578451</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.55389</td>
      <td>0.905240</td>
      <td>1.0</td>
      <td>-1.357860</td>
      <td>2.263100</td>
      <td>-2.715720</td>
      <td>3.620960</td>
    </tr>
    <tr>
      <th>Atr25</th>
      <td>351.0</td>
      <td>-0.071187</td>
      <td>0.508495</td>
      <td>-1.0</td>
      <td>-0.332390</td>
      <td>-0.01505</td>
      <td>0.156765</td>
      <td>1.0</td>
      <td>-1.066123</td>
      <td>0.890497</td>
      <td>-1.799855</td>
      <td>1.624230</td>
    </tr>
    <tr>
      <th>Atr26</th>
      <td>351.0</td>
      <td>0.541641</td>
      <td>0.516205</td>
      <td>-1.0</td>
      <td>0.286435</td>
      <td>0.70824</td>
      <td>0.999945</td>
      <td>1.0</td>
      <td>-0.783830</td>
      <td>2.070210</td>
      <td>-1.854095</td>
      <td>3.140475</td>
    </tr>
    <tr>
      <th>Atr27</th>
      <td>351.0</td>
      <td>-0.069538</td>
      <td>0.550025</td>
      <td>-1.0</td>
      <td>-0.443165</td>
      <td>-0.01769</td>
      <td>0.153535</td>
      <td>1.0</td>
      <td>-1.338215</td>
      <td>1.048585</td>
      <td>-2.233265</td>
      <td>1.943635</td>
    </tr>
    <tr>
      <th>Atr28</th>
      <td>351.0</td>
      <td>0.378445</td>
      <td>0.575886</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.49664</td>
      <td>0.883465</td>
      <td>1.0</td>
      <td>-1.325197</td>
      <td>2.208662</td>
      <td>-2.650395</td>
      <td>3.533860</td>
    </tr>
    <tr>
      <th>Atr29</th>
      <td>351.0</td>
      <td>-0.027907</td>
      <td>0.507974</td>
      <td>-1.0</td>
      <td>-0.236885</td>
      <td>0.00000</td>
      <td>0.154075</td>
      <td>1.0</td>
      <td>-0.823325</td>
      <td>0.740515</td>
      <td>-1.409765</td>
      <td>1.326955</td>
    </tr>
    <tr>
      <th>Atr30</th>
      <td>351.0</td>
      <td>0.352514</td>
      <td>0.571483</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.44277</td>
      <td>0.857620</td>
      <td>1.0</td>
      <td>-1.286430</td>
      <td>2.144050</td>
      <td>-2.572860</td>
      <td>3.430480</td>
    </tr>
    <tr>
      <th>Atr31</th>
      <td>351.0</td>
      <td>-0.003794</td>
      <td>0.513574</td>
      <td>-1.0</td>
      <td>-0.242595</td>
      <td>0.00000</td>
      <td>0.200120</td>
      <td>1.0</td>
      <td>-0.906668</td>
      <td>0.864193</td>
      <td>-1.570740</td>
      <td>1.528265</td>
    </tr>
    <tr>
      <th>Atr32</th>
      <td>351.0</td>
      <td>0.349364</td>
      <td>0.522663</td>
      <td>-1.0</td>
      <td>0.000000</td>
      <td>0.40956</td>
      <td>0.813765</td>
      <td>1.0</td>
      <td>-1.220648</td>
      <td>2.034413</td>
      <td>-2.441295</td>
      <td>3.255060</td>
    </tr>
    <tr>
      <th>Atr33</th>
      <td>351.0</td>
      <td>0.014480</td>
      <td>0.468337</td>
      <td>-1.0</td>
      <td>-0.165350</td>
      <td>0.00000</td>
      <td>0.171660</td>
      <td>1.0</td>
      <td>-0.670865</td>
      <td>0.677175</td>
      <td>-1.176380</td>
      <td>1.182690</td>
    </tr>
  </tbody>
</table>
</div>




```python
ionosphere_stats2=pd.DataFrame()
ionosphere_stats2.index=ionosphere_stats.index
atipicos,extremos=[],[]
for i in ionosphere_stats2.index:
    LII=ionosphere_stats[ionosphere_stats.index==i]["LII"][0]
    LIS=ionosphere_stats[ionosphere_stats.index==i]["LIS"][0]
    LEI=ionosphere_stats[ionosphere_stats.index==i]["LEI"][0]
    LES=ionosphere_stats[ionosphere_stats.index==i]["LES"][0]
    atipicos.append(len(data[((data[i]<=LII)&(data[i]>=LIS))|((data[i]>=LIS)&(data[i]<=LES))]))
    extremos.append(len(data[((data[i]<=LEI)|(data[i]>=LES))]))
ionosphere_stats2["Valores atipicos"]=atipicos
ionosphere_stats2["Valores extremos"]=extremos
ionosphere_stats2["Valores atipicos (%)"]=np.round(ionosphere_stats2["Valores atipicos"]/len(data)*100,2)
ionosphere_stats2["Valores extremos (%)"]=np.round(ionosphere_stats2["Valores extremos"]/len(data)*100,2)
ionosphere_stats2.loc['Total'] = ionosphere_stats2.sum(axis=0)
```


```python
ionosphere_stats2[24:]
```




<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Valores atipicos</th>
      <th>Valores extremos</th>
      <th>Valores atipicos (%)</th>
      <th>Valores extremos (%)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>Atr24</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr25</th>
      <td>20.0</td>
      <td>0.0</td>
      <td>5.70</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr26</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr27</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr28</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr29</th>
      <td>31.0</td>
      <td>0.0</td>
      <td>8.83</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr30</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr31</th>
      <td>33.0</td>
      <td>0.0</td>
      <td>9.40</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr32</th>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.00</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Atr33</th>
      <td>40.0</td>
      <td>0.0</td>
      <td>11.40</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>Total</th>
      <td>971.0</td>
      <td>755.0</td>
      <td>276.64</td>
      <td>215.1</td>
    </tr>
  </tbody>
</table>
</div>



Tomemos por ejemplo los datos que tienen valores atípicos en mayor cantidad, por ejemplo, los datos con  `Atr33`, y veamos como cambia la distribución cual eliminamos los valores atípicos.


```python
def filter_outlier(col):
    LII=ionosphere_stats[ionosphere_stats.index==col]["LII"][0]
    LIS=ionosphere_stats[ionosphere_stats.index==col]["LIS"][0]
    LEI=ionosphere_stats[ionosphere_stats.index==col]["LEI"][0]
    LES=ionosphere_stats[ionosphere_stats.index==col]["LES"][0]
    return data[~(((data[col]<=LII)&(data[col]>=LIS))|((data[col]>=LIS)&(data[col]<=LES)))][col]
```


```python
plt.figure(figsize=(16,6))
plt.subplot(121)
plt.hist(filter_outlier("Atr33"),label="Atr33 (Outliers removed) ({} rows)".format(len(filter_outlier("Atr33"))),alpha=0.4,color='b')
plt.hist(data["Atr33"],label="Atr33 (All data) ({} rows)".format(len(data)),alpha=0.4,color='r')
plt.vlines(np.mean(filter_outlier("Atr33")),0,120,label="Outliers removed mean's (<Atr33>={})".format(np.round(np.mean(filter_outlier("Atr33")),4)),alpha=0.99,color='b',linestyle="--",linewidth=4)
plt.vlines(np.mean(data["Atr33"]),0,120,label="All data mean's (<Atr33>={})".format(np.round(np.mean(data["Atr33"]),4)),alpha=0.99,color='r',linestyle="--",linewidth=4)
plt.legend(title="Absolute distribution",fontsize=11)
plt.ylabel("Counts",fontsize=14)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.subplot(122)
plt.hist(filter_outlier("Atr33"),label="Atr33 (Outliers removed) ({} rows)".format(len(filter_outlier("Atr33"))),alpha=0.4,cumulative=True,color='b')
plt.hist(data["Atr33"],label="Atr33 (All data) ({} rows)".format(len(data)),alpha=0.4,cumulative=True,color='r')
plt.vlines(np.median(filter_outlier("Atr33")),0,350,label="Outliers removed median's (<Atr33>={})".format(np.round(np.mean(filter_outlier("Atr33")),4)),alpha=0.99,color='b',linestyle="--",linewidth=6)
plt.vlines(np.median(data["Atr33"]),0,350,label="All data median's (<Atr33>={})".format(np.round(np.mean(data["Atr33"]),4)),alpha=0.99,color='r',linestyle="--",linewidth=3)

plt.legend(title="Cumulative distribution",fontsize=11)
plt.ylabel("Counts",fontsize=14)
plt.xticks(fontsize=14)
plt.yticks(fontsize=14)
plt.savefig("../../figures/ionosphere_hist2.png",bbox_inches ="tight")
plt.show()
```

Entonces como podemos ver cláramente la distribución de los datos cambian cuando eliminamos de nuestros datos los valores atípicos y por tanto también cambian las medidas de tendencia central, en particular la diferencia porcentual para el cálculo de la media en los datos originales y los datos cuando han sido removidos los valores atípicos es de:


```python
np.round(abs(np.mean(filter_outlier("Atr33"))-np.mean(data["Atr33"]))/np.mean(data["Atr33"])*100,2)
```




    794.06




```python
np.mean(filter_outlier("Atr33"))
```




    -0.10050096463022508




```python
np.mean(data["Atr33"])
```




    0.014480113960113956




```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```


```python

```

eff9a206b7016237a647fea29a2d094c0409c2a3
ipynb
Jupyter Notebook
Notebooks/descriptive_statistics.ipynb
sierraporta/Data_Mining_Excersices
3790466d1d8314d83178b61035fc6c28b567ab59
MIT
Notebooks/descriptive_statistics.ipynb
sierraporta/Data_Mining_Excersices
3790466d1d8314d83178b61035fc6c28b567ab59
MIT
Notebooks/descriptive_statistics.ipynb
sierraporta/Data_Mining_Excersices
3790466d1d8314d83178b61035fc6c28b567ab59
MIT
Qwen/Qwen-72B
1. YES
2. YES