# Importación de librerías
# Manipulación de datos
import pandas as pd
import numpy as np
# Visualización
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import seaborn as sns
# Estadísticas
from funpymodeling.exploratory import status
# Machine Learning
from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.tree import plot_tree
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
from IPython.display import Image
ed_sexual_DF = pd.read_excel("Educacion Sexual.xlsx")
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 15157 entries, 0 to 15156
Data columns (total 6 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 id 15157 non-null int64
1 edad 15157 non-null int64
2 anios_educ 15157 non-null int64
3 en_pareja 15157 non-null int64
4 num_hijos 15157 non-null int64
5 bajo_socioecon 15157 non-null int64
dtypes: int64(6)
memory usage: 710.6 KB
ed_sexual_DF.drop(columns="id", inplace=True)
edadint64
15 - 18
anios_educint64
7 - 12
0
18
9
1
16
7
2
15
9
3
17
9
4
18
9
5
17
9
6
18
9
7
16
12
8
16
7
9
17
7
edadint64
15 - 19
anios_educint64
8 - 12
15147
17
9
15148
19
9
15149
16
9
15150
17
9
15151
17
8
15152
19
12
15153
19
9
15154
15
9
15155
15
9
15156
17
8
variableobject
q_nanint64
0
edad
0
1
anios_educ
0
2
en_pareja
0
3
num_hijos
0
4
bajo_socioecon
0
edadfloat64
anios_educfloat64
count
15157
15157
mean
16.962
8.507
std
1.413
1.176
min
15
6
25%
16
8
50%
17
9
75%
18
9
max
19
12
61.44% de las parejas tienen hijos
Profundidad del árbol: 5
Número de nodos terminales: 31
% de aciertos sobre el set de entrenamiento: 91.13
% de aciertos sobre el set de evaluación: 91.09
Modelo: Árbol de Decisión
Raíz del error cuadrático medio en Train: 0.3155
Raíz del error cuadrático medio en Test: 0.3154
Modelo: Vecinos más cercanos
Raíz del error cuadrático medio en Train: 0.3216
Raíz del error cuadrático medio en Test: 0.3167
Modelo: Regresión Lineal
Raíz del error cuadrático medio en Train: 0.3251
Raíz del error cuadrático medio en Test: 0.3183
Profundidad del árbol: 6
Número de nodos terminales: 58