Comparar modelos de supervisados a través de la aplicación de algoritmos de predicción de precios de automóviles determinando el estadístico del error cuadrático medio (rmse).
Se cargan los datos previamente preparados de la dirección https://raw.githubusercontent.com/rpizarrog/Analisis-Inteligente-de-datos/main/datos/CarPrice_Assignment_Numericas_Preparado.csv
Se crean datos de entrenamiento al 80%
Se crean datos de validación al 20%
Se crea el modelo regresión múltiple con datos de entrenamiento
Con este modelo se responde a preguntas tales como:
¿cuáles son variables que están por encima del 90% de confianza como predictores?,
¿Cuál es el valor de R Square Adjusted o que tanto representan las variables dependientes al precio del vehículo?
Se generan predicciones con datos de validación
Se determina el estadístico RMSE para efectos de comparación
Se crea el modelo árboles de regresión con los datos de entrenamiento
Se identifica la importancia de las variables sobre el precio
Se visualiza el árbol de regresión y sus reglas de asociación
Se hacen predicciones con datos de validación
Se determinar el estadístico RMSE para efectos de comparación
Se construye el modelo bosques aleatorios con datos de entrenamiento y con 20 árboles simulados
Se identifica la importancia de las variables sobre el precio
Se generan predicciones con datos de validación
Se determina el estadístico RMSE para efectos de comparación
Al final del caso, se describe una interpretación personal
# Librerías
library(readr)
library(PerformanceAnalytics) # Para correlaciones gráficas
library(dplyr)
library(knitr) # Para datos tabulares
library(kableExtra) # Para datos tabulares amigables
library(ggplot2) # Para visualizar
library(plotly) # Para visualizar
library(caret) # Para particionar
library(Metrics) # Para determinar rmse
library(rpart) # Para árbol
library(rpart.plot) # Para árbol
library(randomForest) # Para random forest
library(caret) # Para hacer divisiones o particiones
library(reshape) # Para renombrar columnas
datos <- read.csv("https://raw.githubusercontent.com/rpizarrog/Analisis-Inteligente-de-datos/main/datos/CarPrice_Assignment_Numericas_Preparado.csv")
str(datos)
## 'data.frame': 205 obs. of 16 variables:
## $ X : int 1 2 3 4 5 6 7 8 9 10 ...
## $ symboling : int 3 3 1 2 2 2 1 1 1 0 ...
## $ wheelbase : num 88.6 88.6 94.5 99.8 99.4 ...
## $ carlength : num 169 169 171 177 177 ...
## $ carwidth : num 64.1 64.1 65.5 66.2 66.4 66.3 71.4 71.4 71.4 67.9 ...
## $ carheight : num 48.8 48.8 52.4 54.3 54.3 53.1 55.7 55.7 55.9 52 ...
## $ curbweight : int 2548 2548 2823 2337 2824 2507 2844 2954 3086 3053 ...
## $ enginesize : int 130 130 152 109 136 136 136 136 131 131 ...
## $ boreratio : num 3.47 3.47 2.68 3.19 3.19 3.19 3.19 3.19 3.13 3.13 ...
## $ stroke : num 2.68 2.68 3.47 3.4 3.4 3.4 3.4 3.4 3.4 3.4 ...
## $ compressionratio: num 9 9 9 10 8 8.5 8.5 8.5 8.3 7 ...
## $ horsepower : int 111 111 154 102 115 110 110 110 140 160 ...
## $ peakrpm : int 5000 5000 5000 5500 5500 5500 5500 5500 5500 5500 ...
## $ citympg : int 21 21 19 24 18 19 19 19 17 16 ...
## $ highwaympg : int 27 27 26 30 22 25 25 25 20 22 ...
## $ price : num 13495 16500 16500 13950 17450 ...
| Col | Nombre | Descripción |
|---|---|---|
| 1 | Symboling | Its assigned insurance risk rating, A value of +3 indicates that the auto is risky, -3 that it is probably pretty safe.(Categorical) |
| 2 | wheelbase | Weelbase of car (Numeric). Distancia de ejes en pulgadas. |
| 3 | carlength | Length of car (Numeric). Longitud |
| 4 | carwidth | Width of car (Numeric). Amplitud |
| 5 | carheight | height of car (Numeric). Altura |
| 6 | curbweight | The weight of a car without occupants or baggage. (Numeric). Peso del auto |
| 7 | enginesize | Size of car (Numeric). Tamaño del carro en … |
| 8 | boreratio | Boreratio of car (Numeric). Eficiencia de motor |
| 9 | stroke | Stroke or volume inside the engine (Numeric). Pistones, tiempos, combustión |
| 10 | compressionratio | compression ratio of car (Numeric). Comprensión o medición de presión en motor |
| 11 | horsepower | Horsepower (Numeric). Poder del carro |
| 12 | peakrpm | car peak rpm (Numeric). Picos de revoluciones por minuto |
| 13 | citympg | Mileage in city (Numeric). Consumo de gasolina |
| 14 | highwaympg | Mileage on highway (Numeric). Consumo de gasolina |
| 16 | price (Dependent variable) |
Price of car (Numeric). Precio del carro en dólares |
kable(head(datos, 10), caption = "Datos de precios de carros") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| X | symboling | wheelbase | carlength | carwidth | carheight | curbweight | enginesize | boreratio | stroke | compressionratio | horsepower | peakrpm | citympg | highwaympg | price |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3 | 88.6 | 168.8 | 64.1 | 48.8 | 2548 | 130 | 3.47 | 2.68 | 9.0 | 111 | 5000 | 21 | 27 | 13495.00 |
| 2 | 3 | 88.6 | 168.8 | 64.1 | 48.8 | 2548 | 130 | 3.47 | 2.68 | 9.0 | 111 | 5000 | 21 | 27 | 16500.00 |
| 3 | 1 | 94.5 | 171.2 | 65.5 | 52.4 | 2823 | 152 | 2.68 | 3.47 | 9.0 | 154 | 5000 | 19 | 26 | 16500.00 |
| 4 | 2 | 99.8 | 176.6 | 66.2 | 54.3 | 2337 | 109 | 3.19 | 3.40 | 10.0 | 102 | 5500 | 24 | 30 | 13950.00 |
| 5 | 2 | 99.4 | 176.6 | 66.4 | 54.3 | 2824 | 136 | 3.19 | 3.40 | 8.0 | 115 | 5500 | 18 | 22 | 17450.00 |
| 6 | 2 | 99.8 | 177.3 | 66.3 | 53.1 | 2507 | 136 | 3.19 | 3.40 | 8.5 | 110 | 5500 | 19 | 25 | 15250.00 |
| 7 | 1 | 105.8 | 192.7 | 71.4 | 55.7 | 2844 | 136 | 3.19 | 3.40 | 8.5 | 110 | 5500 | 19 | 25 | 17710.00 |
| 8 | 1 | 105.8 | 192.7 | 71.4 | 55.7 | 2954 | 136 | 3.19 | 3.40 | 8.5 | 110 | 5500 | 19 | 25 | 18920.00 |
| 9 | 1 | 105.8 | 192.7 | 71.4 | 55.9 | 3086 | 131 | 3.13 | 3.40 | 8.3 | 140 | 5500 | 17 | 20 | 23875.00 |
| 10 | 0 | 99.5 | 178.2 | 67.9 | 52.0 | 3053 | 131 | 3.13 | 3.40 | 7.0 | 160 | 5500 | 16 | 22 | 17859.17 |
Datos de entrenamiento al 80% de los datos y 20% los datos de validación.
n <- nrow(datos)
set.seed(1747) # Semilla
entrena <- createDataPartition(y = datos$price, p = 0.80, list = FALSE, times = 1)
# Datos entrenamiento
datos.entrenamiento <- datos[entrena, ] # [renglones, columna]
# Datos validación
datos.validacion <- datos[-entrena, ]
kable(head(datos.entrenamiento, 10), caption = "Datos de Entrenamient. Precios de carros") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| X | symboling | wheelbase | carlength | carwidth | carheight | curbweight | enginesize | boreratio | stroke | compressionratio | horsepower | peakrpm | citympg | highwaympg | price | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2 | 2 | 3 | 88.6 | 168.8 | 64.1 | 48.8 | 2548 | 130 | 3.47 | 2.68 | 9.0 | 111 | 5000 | 21 | 27 | 16500.00 |
| 3 | 3 | 1 | 94.5 | 171.2 | 65.5 | 52.4 | 2823 | 152 | 2.68 | 3.47 | 9.0 | 154 | 5000 | 19 | 26 | 16500.00 |
| 4 | 4 | 2 | 99.8 | 176.6 | 66.2 | 54.3 | 2337 | 109 | 3.19 | 3.40 | 10.0 | 102 | 5500 | 24 | 30 | 13950.00 |
| 5 | 5 | 2 | 99.4 | 176.6 | 66.4 | 54.3 | 2824 | 136 | 3.19 | 3.40 | 8.0 | 115 | 5500 | 18 | 22 | 17450.00 |
| 6 | 6 | 2 | 99.8 | 177.3 | 66.3 | 53.1 | 2507 | 136 | 3.19 | 3.40 | 8.5 | 110 | 5500 | 19 | 25 | 15250.00 |
| 8 | 8 | 1 | 105.8 | 192.7 | 71.4 | 55.7 | 2954 | 136 | 3.19 | 3.40 | 8.5 | 110 | 5500 | 19 | 25 | 18920.00 |
| 9 | 9 | 1 | 105.8 | 192.7 | 71.4 | 55.9 | 3086 | 131 | 3.13 | 3.40 | 8.3 | 140 | 5500 | 17 | 20 | 23875.00 |
| 10 | 10 | 0 | 99.5 | 178.2 | 67.9 | 52.0 | 3053 | 131 | 3.13 | 3.40 | 7.0 | 160 | 5500 | 16 | 22 | 17859.17 |
| 11 | 11 | 2 | 101.2 | 176.8 | 64.8 | 54.3 | 2395 | 108 | 3.50 | 2.80 | 8.8 | 101 | 5800 | 23 | 29 | 16430.00 |
| 12 | 12 | 0 | 101.2 | 176.8 | 64.8 | 54.3 | 2395 | 108 | 3.50 | 2.80 | 8.8 | 101 | 5800 | 23 | 29 | 16925.00 |
kable(head(datos.validacion, 10), caption = "Datos de Validación. Precios de carros") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| X | symboling | wheelbase | carlength | carwidth | carheight | curbweight | enginesize | boreratio | stroke | compressionratio | horsepower | peakrpm | citympg | highwaympg | price | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 3 | 88.6 | 168.8 | 64.1 | 48.8 | 2548 | 130 | 3.47 | 2.68 | 9.00 | 111 | 5000 | 21 | 27 | 13495 |
| 7 | 7 | 1 | 105.8 | 192.7 | 71.4 | 55.7 | 2844 | 136 | 3.19 | 3.40 | 8.50 | 110 | 5500 | 19 | 25 | 17710 |
| 15 | 15 | 1 | 103.5 | 189.0 | 66.9 | 55.7 | 3055 | 164 | 3.31 | 3.19 | 9.00 | 121 | 4250 | 20 | 25 | 24565 |
| 22 | 22 | 1 | 93.7 | 157.3 | 63.8 | 50.8 | 1876 | 90 | 2.97 | 3.23 | 9.41 | 68 | 5500 | 37 | 41 | 5572 |
| 24 | 24 | 1 | 93.7 | 157.3 | 63.8 | 50.8 | 2128 | 98 | 3.03 | 3.39 | 7.60 | 102 | 5500 | 24 | 30 | 7957 |
| 29 | 29 | -1 | 103.3 | 174.6 | 64.6 | 59.8 | 2535 | 122 | 3.34 | 3.46 | 8.50 | 88 | 5000 | 24 | 30 | 8921 |
| 30 | 30 | 3 | 95.9 | 173.2 | 66.3 | 50.2 | 2811 | 156 | 3.60 | 3.90 | 7.00 | 145 | 5000 | 19 | 24 | 12964 |
| 32 | 32 | 2 | 86.6 | 144.6 | 63.9 | 50.8 | 1819 | 92 | 2.91 | 3.41 | 9.20 | 76 | 6000 | 31 | 38 | 6855 |
| 37 | 37 | 0 | 96.5 | 157.1 | 63.9 | 58.3 | 2024 | 92 | 2.92 | 3.41 | 9.20 | 76 | 6000 | 30 | 34 | 7295 |
| 41 | 41 | 0 | 96.5 | 175.4 | 62.5 | 54.1 | 2372 | 110 | 3.15 | 3.58 | 9.00 | 86 | 5800 | 27 | 33 | 10295 |
Se construye el modelo de regresión lineal múltiple (rm)
# Modelo de regresión lineal múltiple para observar variables de importancia
modelo_rm <- lm(formula = price ~ symboling + wheelbase + carlength + carwidth + carheight + curbweight + enginesize + boreratio + stroke + compressionratio + horsepower + peakrpm + citympg + highwaympg ,
data = datos.entrenamiento)
summary(modelo_rm)
##
## Call:
## lm(formula = price ~ symboling + wheelbase + carlength + carwidth +
## carheight + curbweight + enginesize + boreratio + stroke +
## compressionratio + horsepower + peakrpm + citympg + highwaympg,
## data = datos.entrenamiento)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8894.3 -1782.9 -204.9 1454.1 14810.9
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) -6.245e+04 1.869e+04 -3.342 0.00105 **
## symboling 1.501e+02 2.653e+02 0.566 0.57236
## wheelbase 1.663e+02 1.188e+02 1.400 0.16364
## carlength -9.793e+01 6.661e+01 -1.470 0.14362
## carwidth 6.288e+02 2.972e+02 2.115 0.03604 *
## carheight 2.119e+02 1.660e+02 1.276 0.20379
## curbweight 1.634e+00 1.926e+00 0.848 0.39756
## enginesize 1.128e+02 1.489e+01 7.576 3.41e-12 ***
## boreratio -7.365e+02 1.417e+03 -0.520 0.60406
## stroke -2.808e+03 8.857e+02 -3.171 0.00184 **
## compressionratio 2.254e+02 9.280e+01 2.428 0.01635 *
## horsepower 2.925e+01 1.842e+01 1.588 0.11438
## peakrpm 2.343e+00 7.991e-01 2.932 0.00390 **
## citympg -2.839e+02 2.061e+02 -1.378 0.17037
## highwaympg 2.039e+02 1.824e+02 1.118 0.26548
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3254 on 150 degrees of freedom
## Multiple R-squared: 0.8512, Adjusted R-squared: 0.8373
## F-statistic: 61.27 on 14 and 150 DF, p-value: < 2.2e-16
¿cuáles son variables que están por encima del 90% de confianza como predictores?
El coeficiente de intersección tiene un nivel de confianza del 95%.
Las variables wheelbase, carwidth y citympg tienen un nivel de confianza del 90% (.)
Las variable compressionratio tiene un nivel de confianza del 95% (*)
Las variables stroke y peakrpm tienen un nivel de confianza como predictores del 99% (**)
La variable enginesize tiene un nivel de confianza como predictor del 99.9% (***)
¿Cuál es el valor de R Square Adjusted o que tanto representan las variables dependientes al precio del vehículo?
En modelos lineales múltiples el estadístico Adjusted R-squared: 0.8351 significa que las variables independientes explican aproximadamente el 83.51% de la variable dependiente precio.
predicciones_rm <- predict(object = modelo_rm, newdata = datos.validacion)
predicciones_rm
## 1 7 15 22 24 29 30 32
## 12138.069 18945.083 17322.827 5576.970 8432.753 12015.358 14943.144 7973.895
## 37 41 43 45 49 52 57 60
## 9481.431 8298.722 10369.965 6256.041 30843.370 6412.056 8312.395 10347.507
## 69 94 107 108 120 123 126 129
## 25050.565 5961.498 22386.474 15152.190 8432.753 7104.683 20027.101 26011.578
## 132 142 143 144 150 152 153 174
## 10847.191 8978.496 8434.963 11156.745 10249.438 6610.959 6570.100 9063.805
## 182 187 194 195 196 201 204 205
## 19489.096 10410.532 11363.091 16619.062 17244.036 18553.600 19650.131 19257.342
comparaciones <- data.frame(precio_real = datos.validacion$price, precio_predicciones = predicciones_rm)
kable(head(comparaciones, 10), caption = "Regresión Lineal Múltiple. Comparación precios reales VS predicción de precios. 10 primeras predicciones") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| precio_real | precio_predicciones | |
|---|---|---|
| 1 | 13495 | 12138.069 |
| 7 | 17710 | 18945.083 |
| 15 | 24565 | 17322.827 |
| 22 | 5572 | 5576.970 |
| 24 | 7957 | 8432.753 |
| 29 | 8921 | 12015.358 |
| 30 | 12964 | 14943.144 |
| 32 | 6855 | 7973.895 |
| 37 | 7295 | 9481.431 |
| 41 | 10295 | 8298.722 |
rmse_rm <- rmse(comparaciones$precio_real, comparaciones$precio_predicciones)
rmse_rm
## [1] 3022.24
Se construye el modelo de árbol de regresión (ar)
modelo_ar <- rpart(formula = price ~ symboling + wheelbase + carlength + carwidth + carheight + curbweight + enginesize + boreratio + stroke + compressionratio + horsepower + peakrpm + citympg + highwaympg ,
data = datos.entrenamiento )
modelo_ar
## n= 165
##
## node), split, n, deviance, yval
## * denotes terminal node
##
## 1) root 165 10673790000 13278.410
## 2) enginesize< 182 150 2932214000 11165.660
## 4) curbweight< 2659.5 101 659596300 8731.114
## 8) curbweight< 2295 59 90036910 7277.280 *
## 9) curbweight>=2295 42 269675000 10773.400 *
## 5) curbweight>=2659.5 49 440084300 16183.800 *
## 3) enginesize>=182 15 376414800 34405.970 *
Pendiente
rpart.plot(modelo_ar)
predicciones_ar <- predict(object = modelo_ar, newdata = datos.validacion)
predicciones_ar
## 1 7 15 22 24 29 30 32
## 10773.40 16183.80 16183.80 7277.28 7277.28 10773.40 16183.80 7277.28
## 37 41 43 45 49 52 57 60
## 7277.28 10773.40 7277.28 7277.28 34405.97 7277.28 10773.40 10773.40
## 69 94 107 108 120 123 126 129
## 34405.97 7277.28 16183.80 16183.80 7277.28 7277.28 16183.80 34405.97
## 132 142 143 144 150 152 153 174
## 10773.40 7277.28 7277.28 10773.40 10773.40 7277.28 7277.28 10773.40
## 182 187 194 195 196 201 204 205
## 16183.80 7277.28 10773.40 16183.80 16183.80 16183.80 16183.80 16183.80
comparaciones <- data.frame(precio_real = datos.validacion$price, precio_predicciones = predicciones_ar)
kable(head(comparaciones, 10), caption = "Arbol de regresión. Comparación precios reales VS predicción de precios. 10 primeras predicciones") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| precio_real | precio_predicciones | |
|---|---|---|
| 1 | 13495 | 10773.40 |
| 7 | 17710 | 16183.80 |
| 15 | 24565 | 16183.80 |
| 22 | 5572 | 7277.28 |
| 24 | 7957 | 7277.28 |
| 29 | 8921 | 10773.40 |
| 30 | 12964 | 16183.80 |
| 32 | 6855 | 7277.28 |
| 37 | 7295 | 7277.28 |
| 41 | 10295 | 10773.40 |
rmse_ar <- rmse(comparaciones$precio_real, comparaciones$precio_predicciones)
rmse_ar
## [1] 2876.144
Se construye el modelo de árbol de regresión (ar)
modelo_rf <- randomForest(x = datos.entrenamiento[,c("symboling", "wheelbase",
"carlength", "carwidth", "carheight", "curbweight",
"enginesize", "boreratio", "stroke",
"compressionratio", "horsepower", "peakrpm",
"citympg", "highwaympg" )],
y = datos.entrenamiento[,'price'],
importance = TRUE,
keep.forest = TRUE,
ntree=20)
modelo_rf
##
## Call:
## randomForest(x = datos.entrenamiento[, c("symboling", "wheelbase", "carlength", "carwidth", "carheight", "curbweight", "enginesize", "boreratio", "stroke", "compressionratio", "horsepower", "peakrpm", "citympg", "highwaympg")], y = datos.entrenamiento[, "price"], ntree = 20, importance = TRUE, keep.forest = TRUE)
## Type of random forest: regression
## Number of trees: 20
## No. of variables tried at each split: 4
##
## Mean of squared residuals: 5568113
## % Var explained: 91.39
as.data.frame(modelo_rf$importance) %>%
arrange(desc(IncNodePurity))
## %IncMSE IncNodePurity
## enginesize 33795967.01 3631107806
## curbweight 12624036.87 1635136541
## horsepower 7861515.52 1220947997
## highwaympg 10402181.62 1161175603
## carwidth 4721160.47 691870439
## citympg 4719455.33 665451013
## wheelbase 4237638.90 465366469
## carlength 3129507.26 333191770
## peakrpm 1036193.87 140670017
## carheight 391855.35 70885235
## boreratio 180669.67 63490166
## stroke -22570.84 50660635
## compressionratio 410176.81 48447015
## symboling 152770.17 8096262
predicciones_rf <- predict(object = modelo_rf, newdata = datos.validacion)
predicciones_rf
## 1 7 15 22 24 29 30 32
## 15201.839 19710.568 19266.290 5841.463 8309.896 9636.920 13347.316 6431.781
## 37 41 43 45 49 52 57 60
## 7187.869 9971.077 10024.135 6513.540 35151.055 6384.911 12214.871 10853.674
## 69 94 107 108 120 123 126 129
## 28528.142 7848.703 17298.183 16144.738 8309.896 7509.672 16793.830 32059.573
## 132 142 143 144 150 152 153 174
## 10853.568 7944.005 7981.380 9272.173 12621.840 6451.209 6451.209 10980.179
## 182 187 194 195 196 201 204 205
## 16545.351 8247.272 12512.112 16506.892 16550.743 17835.562 17695.815 18375.478
comparaciones <- data.frame(precio_real = datos.validacion$price, precio_predicciones = predicciones_rf)
kable(head(comparaciones, 10), caption = "Random Forest. Comparación precios reales VS predicción de precios. 10 primeras predicciones") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| precio_real | precio_predicciones | |
|---|---|---|
| 1 | 13495 | 15201.839 |
| 7 | 17710 | 19710.568 |
| 15 | 24565 | 19266.290 |
| 22 | 5572 | 5841.463 |
| 24 | 7957 | 8309.896 |
| 29 | 8921 | 9636.920 |
| 30 | 12964 | 13347.316 |
| 32 | 6855 | 6431.781 |
| 37 | 7295 | 7187.869 |
| 41 | 10295 | 9971.077 |
rmse_rf <- rmse(comparaciones$precio_real, comparaciones$precio_predicciones)
rmse_rf
## [1] 2181.429
Se comparan las predicciones
comparaciones <- data.frame(cbind(datos.validacion[,-1], predicciones_rm, predicciones_ar, predicciones_rf))
Se visualizan las predicciones de cada modelo
kable(comparaciones, caption = "Predicciones de los modelos") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| symboling | wheelbase | carlength | carwidth | carheight | curbweight | enginesize | boreratio | stroke | compressionratio | horsepower | peakrpm | citympg | highwaympg | price | predicciones_rm | predicciones_ar | predicciones_rf | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 3 | 88.6 | 168.8 | 64.1 | 48.8 | 2548 | 130 | 3.47 | 2.680 | 9.00 | 111 | 5000 | 21 | 27 | 13495.0 | 12138.069 | 10773.40 | 15201.839 |
| 7 | 1 | 105.8 | 192.7 | 71.4 | 55.7 | 2844 | 136 | 3.19 | 3.400 | 8.50 | 110 | 5500 | 19 | 25 | 17710.0 | 18945.083 | 16183.80 | 19710.568 |
| 15 | 1 | 103.5 | 189.0 | 66.9 | 55.7 | 3055 | 164 | 3.31 | 3.190 | 9.00 | 121 | 4250 | 20 | 25 | 24565.0 | 17322.827 | 16183.80 | 19266.290 |
| 22 | 1 | 93.7 | 157.3 | 63.8 | 50.8 | 1876 | 90 | 2.97 | 3.230 | 9.41 | 68 | 5500 | 37 | 41 | 5572.0 | 5576.970 | 7277.28 | 5841.463 |
| 24 | 1 | 93.7 | 157.3 | 63.8 | 50.8 | 2128 | 98 | 3.03 | 3.390 | 7.60 | 102 | 5500 | 24 | 30 | 7957.0 | 8432.753 | 7277.28 | 8309.896 |
| 29 | -1 | 103.3 | 174.6 | 64.6 | 59.8 | 2535 | 122 | 3.34 | 3.460 | 8.50 | 88 | 5000 | 24 | 30 | 8921.0 | 12015.358 | 10773.40 | 9636.920 |
| 30 | 3 | 95.9 | 173.2 | 66.3 | 50.2 | 2811 | 156 | 3.60 | 3.900 | 7.00 | 145 | 5000 | 19 | 24 | 12964.0 | 14943.144 | 16183.80 | 13347.316 |
| 32 | 2 | 86.6 | 144.6 | 63.9 | 50.8 | 1819 | 92 | 2.91 | 3.410 | 9.20 | 76 | 6000 | 31 | 38 | 6855.0 | 7973.895 | 7277.28 | 6431.781 |
| 37 | 0 | 96.5 | 157.1 | 63.9 | 58.3 | 2024 | 92 | 2.92 | 3.410 | 9.20 | 76 | 6000 | 30 | 34 | 7295.0 | 9481.431 | 7277.28 | 7187.869 |
| 41 | 0 | 96.5 | 175.4 | 62.5 | 54.1 | 2372 | 110 | 3.15 | 3.580 | 9.00 | 86 | 5800 | 27 | 33 | 10295.0 | 8298.722 | 10773.40 | 9971.077 |
| 43 | 1 | 96.5 | 169.1 | 66.0 | 51.0 | 2293 | 110 | 3.15 | 3.580 | 9.10 | 100 | 5500 | 25 | 31 | 10345.0 | 10369.965 | 7277.28 | 10024.135 |
| 45 | 1 | 94.5 | 155.9 | 63.6 | 52.0 | 1874 | 90 | 3.03 | 3.110 | 9.60 | 70 | 5400 | 38 | 43 | 8916.5 | 6256.041 | 7277.28 | 6513.540 |
| 49 | 0 | 113.0 | 199.6 | 69.6 | 52.8 | 4066 | 258 | 3.63 | 4.170 | 8.10 | 176 | 4750 | 15 | 19 | 35550.0 | 30843.370 | 34405.97 | 35151.055 |
| 52 | 1 | 93.1 | 159.1 | 64.2 | 54.1 | 1900 | 91 | 3.03 | 3.150 | 9.00 | 68 | 5000 | 31 | 38 | 6095.0 | 6412.056 | 7277.28 | 6384.911 |
| 57 | 3 | 95.3 | 169.0 | 65.7 | 49.6 | 2380 | 70 | 3.33 | 3.255 | 9.40 | 101 | 6000 | 17 | 23 | 11845.0 | 8312.395 | 10773.40 | 12214.871 |
| 60 | 1 | 98.8 | 177.8 | 66.5 | 53.7 | 2385 | 122 | 3.39 | 3.390 | 8.60 | 84 | 4800 | 26 | 32 | 8845.0 | 10347.507 | 10773.40 | 10853.674 |
| 69 | -1 | 110.0 | 190.9 | 70.3 | 58.7 | 3750 | 183 | 3.58 | 3.640 | 21.50 | 123 | 4350 | 22 | 25 | 28248.0 | 25050.565 | 34405.97 | 28528.142 |
| 94 | 1 | 94.5 | 170.2 | 63.8 | 53.5 | 2024 | 97 | 3.15 | 3.290 | 9.40 | 69 | 5200 | 31 | 37 | 7349.0 | 5961.498 | 7277.28 | 7848.703 |
| 107 | 1 | 99.2 | 178.5 | 67.9 | 49.7 | 3139 | 181 | 3.43 | 3.270 | 9.00 | 160 | 5200 | 19 | 25 | 18399.0 | 22386.474 | 16183.80 | 17298.183 |
| 108 | 0 | 107.9 | 186.7 | 68.4 | 56.7 | 3020 | 120 | 3.46 | 3.190 | 8.40 | 97 | 5000 | 19 | 24 | 11900.0 | 15152.190 | 16183.80 | 16144.738 |
| 120 | 1 | 93.7 | 157.3 | 63.8 | 50.8 | 2128 | 98 | 3.03 | 3.390 | 7.60 | 102 | 5500 | 24 | 30 | 7957.0 | 8432.753 | 7277.28 | 8309.896 |
| 123 | 1 | 93.7 | 167.3 | 63.8 | 50.8 | 2191 | 98 | 2.97 | 3.230 | 9.40 | 68 | 5500 | 31 | 38 | 7609.0 | 7104.683 | 7277.28 | 7509.672 |
| 126 | 3 | 94.5 | 168.9 | 68.3 | 50.2 | 2778 | 151 | 3.94 | 3.110 | 9.50 | 143 | 5500 | 19 | 27 | 22018.0 | 20027.101 | 16183.80 | 16793.830 |
| 129 | 3 | 89.5 | 168.9 | 65.0 | 51.6 | 2800 | 194 | 3.74 | 2.900 | 9.50 | 207 | 5900 | 17 | 25 | 37028.0 | 26011.578 | 34405.97 | 32059.573 |
| 132 | 2 | 96.1 | 176.8 | 66.6 | 50.5 | 2460 | 132 | 3.46 | 3.900 | 8.70 | 90 | 5100 | 23 | 31 | 9895.0 | 10847.191 | 10773.40 | 10853.567 |
| 142 | 0 | 97.2 | 172.0 | 65.4 | 52.5 | 2145 | 108 | 3.62 | 2.640 | 9.50 | 82 | 4800 | 32 | 37 | 7126.0 | 8978.496 | 7277.28 | 7944.005 |
| 143 | 0 | 97.2 | 172.0 | 65.4 | 52.5 | 2190 | 108 | 3.62 | 2.640 | 9.50 | 82 | 4400 | 28 | 33 | 7775.0 | 8434.963 | 7277.28 | 7981.380 |
| 144 | 0 | 97.2 | 172.0 | 65.4 | 52.5 | 2340 | 108 | 3.62 | 2.640 | 9.00 | 94 | 5200 | 26 | 32 | 9960.0 | 11156.745 | 10773.40 | 9272.173 |
| 150 | 0 | 96.9 | 173.6 | 65.4 | 54.9 | 2650 | 108 | 3.62 | 2.640 | 7.70 | 111 | 4800 | 23 | 23 | 11694.0 | 10249.438 | 10773.40 | 12621.840 |
| 152 | 1 | 95.7 | 158.7 | 63.6 | 54.5 | 2040 | 92 | 3.05 | 3.030 | 9.00 | 62 | 4800 | 31 | 38 | 6338.0 | 6610.959 | 7277.28 | 6451.209 |
| 153 | 1 | 95.7 | 158.7 | 63.6 | 54.5 | 2015 | 92 | 3.05 | 3.030 | 9.00 | 62 | 4800 | 31 | 38 | 6488.0 | 6570.100 | 7277.28 | 6451.209 |
| 174 | -1 | 102.4 | 175.6 | 66.5 | 54.9 | 2326 | 122 | 3.31 | 3.540 | 8.70 | 92 | 4200 | 29 | 34 | 8948.0 | 9063.805 | 10773.40 | 10980.179 |
| 182 | -1 | 104.5 | 187.8 | 66.5 | 54.1 | 3151 | 161 | 3.27 | 3.350 | 9.20 | 156 | 5200 | 19 | 24 | 15750.0 | 19489.096 | 16183.80 | 16545.351 |
| 187 | 2 | 97.3 | 171.7 | 65.5 | 55.7 | 2275 | 109 | 3.19 | 3.400 | 9.00 | 85 | 5250 | 27 | 34 | 8495.0 | 10410.532 | 7277.28 | 8247.272 |
| 194 | 0 | 100.4 | 183.1 | 66.9 | 55.1 | 2563 | 109 | 3.19 | 3.400 | 9.00 | 88 | 5500 | 25 | 31 | 12290.0 | 11363.091 | 10773.40 | 12512.112 |
| 195 | -2 | 104.3 | 188.8 | 67.2 | 56.2 | 2912 | 141 | 3.78 | 3.150 | 9.50 | 114 | 5400 | 23 | 28 | 12940.0 | 16619.062 | 16183.80 | 16506.893 |
| 196 | -1 | 104.3 | 188.8 | 67.2 | 57.5 | 3034 | 141 | 3.78 | 3.150 | 9.50 | 114 | 5400 | 23 | 28 | 13415.0 | 17244.036 | 16183.80 | 16550.743 |
| 201 | -1 | 109.1 | 188.8 | 68.9 | 55.5 | 2952 | 141 | 3.78 | 3.150 | 9.50 | 114 | 5400 | 23 | 28 | 16845.0 | 18553.600 | 16183.80 | 17835.562 |
| 204 | -1 | 109.1 | 188.8 | 68.9 | 55.5 | 3217 | 145 | 3.01 | 3.400 | 23.00 | 106 | 4800 | 26 | 27 | 22470.0 | 19650.131 | 16183.80 | 17695.815 |
| 205 | -1 | 109.1 | 188.8 | 68.9 | 55.5 | 3062 | 141 | 3.78 | 3.150 | 9.50 | 114 | 5400 | 19 | 25 | 22625.0 | 19257.342 | 16183.80 | 18375.478 |
Se compara el RMSE
rmse <- data.frame(rm = rmse_rm, ar = rmse_ar, rf = rmse_rf)
kable(rmse, caption = "Estadístico RMSE de cada modelo") %>%
kable_styling(full_width = F, bootstrap_options = c("striped", "bordered", "condensed")) %>%
kable_paper("hover")
| rm | ar | rf |
|---|---|---|
| 3022.24 | 2876.144 | 2181.429 |
Se cargaron datos numéricos de precios de automóviles basados en algunas variables numéricas.
El modelo de regresión linea múltiple destaca variables estadísticamente significativas: Las variable compressionratio tiene un nivel de confianza del 95%; las variables stroke y peakrpm tienen un nivel de confianza como predictores del 99% y la variable enginesize tiene un nivel de confianza como predictor del 99.9%.
El modelo de árbol de regresión sus variables de importancia fueron: enginesize, highwaympg, curbweight y horsepower.
El modelo de bosque aleatorio considera variables de importancia tales como: enginesize, curbweight, horsepower, citympg y carwidth.
A destacar la variable enginesize en todos los modelos como importante y significativa y las variables enginesize, curbweight y horsepower como importantes en los modelos árbol de regresión y bosque aleatorio.
El mejor modelo conforme al estadístico raiz del error cuadrático medio (rmse) fue el de bosques aleatorios con estos datos de entrenamiento y validación y con el porcentaje de datos de entrenamiento y validación de 80% y 20%.