Determinar la influencia de los componentes de un ordenador en su precio.
Tratamieno de la BBDD
port2 = read.csv("BBDD_Portatiles.csv")
head(port2)
## Nombre Marca SO RAM DiscoDuroGB
## 1 Acer Aspire Go 15 Portátil AG15-42P ACER Windows 11 8 512
## 2 Acer A315-59 ACER FreeDOS 16 512
## 3 Acer Aspire 5 Portátil A515-57 ACER Windows 11 16 1024
## 4 Acer Aspire 3 Portátil A317-54 ACER Windows 11 8 512
## 5 Acer Aspire 3 A315-59 ACER No 16 1024
## 6 Acer Nitro 16 Portátil gaming AN16-73 ACER Windows 11 16 1024
## ProcesadorCPU NúcleosCPU VelocidadMaxProcesador GPU
## 1 AMD Ryzen 5 6 4.3 AMD Radeon Graphics
## 2 Intel Core i7 10 4.7 Intel Iris X
## 3 Intel Core i5 8 2.0 Intel UHD Graphics
## 4 Intel Core i5 10 1.3 Intel Iris X
## 5 Intel Core i5 10 4.4 Intel UHD Graphics
## 6 Intel Core i7 16 2.2 NVIDIA GeForce RTX 4050
## NúcleosGPU Pantalla Peso Tactil Web Precio RankingMarca
## 1 NA 15.6 1.78 No Acer 599 346
## 2 NA 15.6 1.7 No Mediamarkt 627 346
## 3 NA 15.6 1.76 No Acer 899 346
## 4 NA 17.3 2.23 No Acer 799 346
## 5 NA 15.6 1.82 No PCcomponentes 602 346
## 6 NA 16 2.45 No Acer 1499 346
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
## 1
## 2
## 3
## 4
## 5
## 6
Primeramente, empezaremos creando una nueva variable que indique si el modelo dispone de GPU integrada o dedicada
unique(port2$GPU)
## [1] "AMD Radeon Graphics" "Intel Iris X"
## [3] "Intel UHD Graphics" "NVIDIA GeForce RTX 4050"
## [5] "Adreno Onboard Graphics" "NVIDIA GeForce RTX 2050"
## [7] "Dimensity Onboard Graphics" ""
## [9] "NVIDIA GeForce RTX 4060" "M4"
## [11] "Intel Arc Graphics" "NVIDIA GeForce RTX"
## [13] "Intel Arc GPU" "Radeon Onboard Graphics"
## [15] "Intel Graphics" "Intel"
## [17] "Intel UHD" "Intel Arc"
## [19] "Intel " "NVIDIA GeForce RTX 4070"
## [21] "NVIDIA GeForce RTX 3050" "NVIDIA GeForce RTX 5090"
## [23] "NVIDIA GeForce RTX 4080" "NVIDIA GeForce RTX 4090"
## [25] "NVIDIA GeForce RTX 3080" "NVIDIA GeForce RTX 3070"
## [27] "Intel Iris" "M3"
Depuracion de formato
Hacer tactil binario:
port2$Tactil <- ifelse(port2$Tactil == "Sí", 1,
ifelse(port2$Tactil == "No", 0, NA))
Creación del dataframe auxiliar
colnames(port2)
## [1] "Nombre" "Marca"
## [3] "SO" "RAM"
## [5] "DiscoDuroGB" "ProcesadorCPU"
## [7] "NúcleosCPU" "VelocidadMaxProcesador"
## [9] "GPU" "NúcleosGPU"
## [11] "Pantalla" "Peso"
## [13] "Tactil" "Web"
## [15] "Precio" "RankingMarca"
## [17] "OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS"
descPort2 = data.frame(
variable = colnames(port2),
tipo = c("text", # Nombre
"categorical", # Marca
"categorical", # SO
"numerical", # RAM
"numerical", # DiscoDuro
"categorical", # ProcesadorCPU
"numerical", # NúcleosCPU
"numerical", # VelocidadMaxProcesador
"categorical", # GPU
"numerical", # NúcleosGPU
"numerical", # Pantalla
"numerical", # Peso
"binary", # Tactil
"categorical", # Web
"numerical", # Precio
"numerical", # RankingMarca
"text" # OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
# "binary", # gpu_dedicada
# "categorical" #Precio_clase
),
stringsAsFactors = FALSE
)
rownames(descPort2) = descPort2$variable
unique(port2$ProcesadorCPU)
## [1] "AMD Ryzen 5" "Intel Core i7"
## [3] "Intel Core i5" "Qualcomm Snapdragon X"
## [5] "Intel Core Ultra 7" "Intel Celeron N4500"
## [7] "AMD Ryzen 7" "Intel Core i3"
## [9] "M4" "M4 Pro"
## [11] "M4 Max" "AMD Ryzen AI 9 HX"
## [13] "Intel Core Ultra 5" "Intel Core Ultra 9"
## [15] "Intel N100" "Intel Celeron N"
## [17] "Qualcomm Snapdragon X Plus" "Qualcomm Snapdragon X Elite"
## [19] "Intel Core i9" "AMD Ryzen 9"
## [21] "M3" "M3 Pro"
Hay que: -quitar generaciones -Revisar mayusculas -Quitar espacios
Quitar espacios
# Limpiar espacios y convertir a factor donde corresponda
for (col in descPort2$variable[descPort2$tipo %in% c("text", "categorical")]) {
port2[[col]] <- trimws(as.character(port2[[col]])) # Quitar espacios
}
# Convertir solo las variables "categorical" a factor
for (col in descPort2$variable[descPort2$tipo == "categorical"]) {
port2[[col]] <- as.factor(port2[[col]])
}
Generaciones y mayúsculas revisadas en el excel directamente.
print(descPort2)
## variable
## Nombre Nombre
## Marca Marca
## SO SO
## RAM RAM
## DiscoDuroGB DiscoDuroGB
## ProcesadorCPU ProcesadorCPU
## NúcleosCPU NúcleosCPU
## VelocidadMaxProcesador VelocidadMaxProcesador
## GPU GPU
## NúcleosGPU NúcleosGPU
## Pantalla Pantalla
## Peso Peso
## Tactil Tactil
## Web Web
## Precio Precio
## RankingMarca RankingMarca
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
## tipo
## Nombre text
## Marca categorical
## SO categorical
## RAM numerical
## DiscoDuroGB numerical
## ProcesadorCPU categorical
## NúcleosCPU numerical
## VelocidadMaxProcesador numerical
## GPU categorical
## NúcleosGPU numerical
## Pantalla numerical
## Peso numerical
## Tactil binary
## Web categorical
## Precio numerical
## RankingMarca numerical
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS text
SO
unique(port2$SO)
## [1] Windows 11 FreeDOS No Windows 11 Pro
## [5] ChromeOS macOS Windows 10 Windows 11 pro
## [9] Ubuntu LINUX Windows Windows 11 Advance
## 11 Levels: ChromeOS FreeDOS macOS No Ubuntu LINUX Windows ... Windows 11 Pro
# Limpiar espacios
port2$SO <- trimws(port2$SO)
# Unificar valores
port2$SO <- ifelse(port2$SO %in% c("No"), "Sin SO", port2$SO)
port2$SO <- ifelse(port2$SO == "LINUX", "Linux", port2$SO)
port2$SO <- ifelse(port2$SO == "Windows", "Windows (sin especificar)", port2$SO)
port2$SO <- ifelse(port2$SO == "Windows 11 Advance", "Windows 11", port2$SO)
port2$SO <- ifelse(port2$SO == "Windows 11 pro", "Windows 11 Pro", port2$SO)
GPU
unique(port2$GPU)
## [1] AMD Radeon Graphics Intel Iris X
## [3] Intel UHD Graphics NVIDIA GeForce RTX 4050
## [5] Adreno Onboard Graphics NVIDIA GeForce RTX 2050
## [7] Dimensity Onboard Graphics
## [9] NVIDIA GeForce RTX 4060 M4
## [11] Intel Arc Graphics NVIDIA GeForce RTX
## [13] Intel Arc GPU Radeon Onboard Graphics
## [15] Intel Graphics Intel
## [17] Intel UHD Intel Arc
## [19] NVIDIA GeForce RTX 4070 NVIDIA GeForce RTX 3050
## [21] NVIDIA GeForce RTX 5090 NVIDIA GeForce RTX 4080
## [23] NVIDIA GeForce RTX 4090 NVIDIA GeForce RTX 3080
## [25] NVIDIA GeForce RTX 3070 Intel Iris
## [27] M3
## 27 Levels: Adreno Onboard Graphics ... Radeon Onboard Graphics
port2$GPU[port2$GPU == ""] = NA
port2$GPU[port2$GPU == "Nvidia GeForce RTX 4060"] <- "NVIDIA GeForce RTX 4060"
port2$GPU[port2$GPU == "Intel Iris"] <- "Intel Iris X"
port2$GPU[port2$GPU == "Intel Arc"] <- "Intel Arc Graphics"
port2$GPU[port2$GPU == "Intel Arc GPU"] <- "Intel Arc Graphics"
port2$GPU[port2$GPU == "Intel"] <- "Intel Graphics"
port2$GPU[port2$GPU == "Intel UHD"] <- "Intel UHD Graphics"
unique(port2$GPU)
## [1] AMD Radeon Graphics Intel Iris X
## [3] Intel UHD Graphics NVIDIA GeForce RTX 4050
## [5] Adreno Onboard Graphics NVIDIA GeForce RTX 2050
## [7] Dimensity Onboard Graphics <NA>
## [9] NVIDIA GeForce RTX 4060 M4
## [11] Intel Arc Graphics NVIDIA GeForce RTX
## [13] Radeon Onboard Graphics Intel Graphics
## [15] NVIDIA GeForce RTX 4070 NVIDIA GeForce RTX 3050
## [17] NVIDIA GeForce RTX 5090 NVIDIA GeForce RTX 4080
## [19] NVIDIA GeForce RTX 4090 NVIDIA GeForce RTX 3080
## [21] NVIDIA GeForce RTX 3070 M3
## 27 Levels: Adreno Onboard Graphics ... Radeon Onboard Graphics
Web
unique(port2$Web)
## [1] Acer Mediamarkt PCcomponentes ElCorteIngles
## [5] Amazon Apple Hipercor ElcorteIngles
## [9] FNAC Dell HP Idealo
## [13] Huawei Lenovo MSI Razer
## [17] Carrefour Samsung El Corte Inglés
## [21] MediaMarkt
## 21 Levels: Acer Amazon Apple Carrefour Dell El Corte Inglés ... Samsung
port2$Web <- as.character(port2$Web)
port2$Web[port2$Web == "PCcomponentes"] <- "PcComponentes"
port2$Web[port2$Web %in% c("ElcorteIngles", "El Corte Inglés")] <- "El Corte Inglés"
port2$Web[port2$Web == "FNAC"] <- "Fnac"
port2$Web[port2$Web == ""] <- NA
unique(port2$Web)
## [1] "Acer" "Mediamarkt" "PcComponentes" "ElCorteIngles"
## [5] "Amazon" "Apple" "Hipercor" "El Corte Inglés"
## [9] "Fnac" "Dell" "HP" "Idealo"
## [13] "Huawei" "Lenovo" "MSI" "Razer"
## [17] "Carrefour" "Samsung" NA "MediaMarkt"
write.xlsx(port2, "Port_Nuestra_dep.xlsx")
write.csv(port2, "Port_Nuestra_dep.csv", row.names = FALSE)
Aquí se guarda el data.frame y se vuelve a cargar, por motivos del trabajo paralelo con otros objetivos
df =read.csv("Port_Nuestra_dep.csv", header = TRUE, sep = ",")
df = df[-291, ]
head(df)
## Nombre Marca SO RAM DiscoDuroGB
## 1 Acer Aspire Go 15 Portátil AG15-42P ACER Windows 11 8 512
## 2 Acer A315-59 ACER FreeDOS 16 512
## 3 Acer Aspire 5 Portátil A515-57 ACER Windows 11 16 1024
## 4 Acer Aspire 3 Portátil A317-54 ACER Windows 11 8 512
## 5 Acer Aspire 3 A315-59 ACER Sin SO 16 1024
## 6 Acer Nitro 16 Portátil gaming AN16-73 ACER Windows 11 16 1024
## ProcesadorCPU NúcleosCPU VelocidadMaxProcesador GPU
## 1 AMD Ryzen 5 6 4.3 AMD Radeon Graphics
## 2 Intel Core i7 10 4.7 Intel Iris X
## 3 Intel Core i5 8 2.0 Intel UHD Graphics
## 4 Intel Core i5 10 1.3 Intel Iris X
## 5 Intel Core i5 10 4.4 Intel UHD Graphics
## 6 Intel Core i7 16 2.2 NVIDIA GeForce RTX 4050
## NúcleosGPU Pantalla Peso Tactil Web Precio RankingMarca
## 1 NA 15.6 1.78 0 Acer 599 346
## 2 NA 15.6 1.7 0 Mediamarkt 627 346
## 3 NA 15.6 1.76 0 Acer 899 346
## 4 NA 17.3 2.23 0 Acer 799 346
## 5 NA 15.6 1.82 0 PcComponentes 602 346
## 6 NA 16 2.45 0 Acer 1499 346
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
## 1
## 2
## 3
## 4
## 5
## 6
summary(df)
## Nombre Marca SO RAM
## Length:321 Length:321 Length:321 Min. : 4.00
## Class :character Class :character Class :character 1st Qu.: 16.00
## Mode :character Mode :character Mode :character Median : 16.00
## Mean : 23.86
## 3rd Qu.: 32.00
## Max. :128.00
##
## DiscoDuroGB ProcesadorCPU NúcleosCPU VelocidadMaxProcesador
## Length:321 Length:321 Min. : 1.0 Min. :1.000
## Class :character Class :character 1st Qu.:10.0 1st Qu.:4.300
## Mode :character Mode :character Median :10.0 Median :4.800
## Mean :11.6 Mean :4.467
## 3rd Qu.:14.0 3rd Qu.:5.100
## Max. :24.0 Max. :5.800
## NA's :17 NA's :127
## GPU NúcleosGPU Pantalla Peso
## Length:321 Min. : 8.00 Length:321 Length:321
## Class :character 1st Qu.:10.00 Class :character Class :character
## Mode :character Median :10.00 Mode :character Mode :character
## Mean :16.06
## 3rd Qu.:20.00
## Max. :40.00
## NA's :212
## Tactil Web Precio RankingMarca
## Min. :0.00000 Length:321 Min. : 202 Min. : 1
## 1st Qu.:0.00000 Class :character 1st Qu.: 799 1st Qu.: 1
## Median :0.00000 Mode :character Median :1591 Median : 47
## Mean :0.09091 Mean :1873 Mean :100
## 3rd Qu.:0.00000 3rd Qu.:2344 3rd Qu.:136
## Max. :1.00000 Max. :8574 Max. :526
## NA's :13 NA's :29
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
## Length:321
## Class :character
## Mode :character
##
##
##
##
Creación de una variable que represente el precio de manera categórica
df$Precio_clase = cut(df$Precio,
breaks = quantile(df$Precio, probs = seq(0, 1, 0.25), na.rm = TRUE),
include.lowest = TRUE,
labels = c("Muy bajo", "Medio-bajo", "Medio-alto", "Muy alto"))
gpus_dedicadas = c(
"Intel Arc Graphics",
# NVIDIA RTX
"NVIDIA GeForce RTX",
"NVIDIA GeForce RTX 2050",
"NVIDIA GeForce RTX 3050",
"NVIDIA GeForce RTX 3070",
"NVIDIA GeForce RTX 3080",
"NVIDIA GeForce RTX 4050",
"NVIDIA GeForce RTX 4060",
"NVIDIA GeForce RTX 4070",
"NVIDIA GeForce RTX 4080",
"NVIDIA GeForce RTX 4090"
)
df$gpu_dedicada = ifelse(df$GPU %in% gpus_dedicadas, 1, 0)
unique(df$GPU[df$gpu_dedicada == 0]) # Solo integradas
## [1] "AMD Radeon Graphics" "Intel Iris X"
## [3] "Intel UHD Graphics" "Adreno Onboard Graphics"
## [5] "Dimensity Onboard Graphics" NA
## [7] "M4" "Radeon Onboard Graphics"
## [9] "Intel Graphics" "NVIDIA GeForce RTX 5090"
## [11] "M3"
print("-----------------------------------------------------------------------------------------------------------------" )
## [1] "-----------------------------------------------------------------------------------------------------------------"
unique(df$GPU[df$gpu_dedicada == 1]) # Solo dedicadas
## [1] "NVIDIA GeForce RTX 4050" "NVIDIA GeForce RTX 2050"
## [3] "NVIDIA GeForce RTX 4060" "Intel Arc Graphics"
## [5] "NVIDIA GeForce RTX" "NVIDIA GeForce RTX 4070"
## [7] "NVIDIA GeForce RTX 3050" "NVIDIA GeForce RTX 4080"
## [9] "NVIDIA GeForce RTX 4090" "NVIDIA GeForce RTX 3080"
## [11] "NVIDIA GeForce RTX 3070"
Tabla auxiliar de df
colnames(df)
## [1] "Nombre" "Marca"
## [3] "SO" "RAM"
## [5] "DiscoDuroGB" "ProcesadorCPU"
## [7] "NúcleosCPU" "VelocidadMaxProcesador"
## [9] "GPU" "NúcleosGPU"
## [11] "Pantalla" "Peso"
## [13] "Tactil" "Web"
## [15] "Precio" "RankingMarca"
## [17] "OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS" "Precio_clase"
## [19] "gpu_dedicada"
desc = data.frame(
variable = colnames(df),
tipo = c("text", # Nombre
"categorical", # Marca
"categorical", # SO
"numerical", # RAM
"numerical", # DiscoDuro
"categorical", # ProcesadorCPU
"numerical", # NúcleosCPU
"numerical", # VelocidadMaxProcesador
"categorical", # GPU
"numerical", # NúcleosGPU
"numerical", # Pantalla
"numerical", # Peso
"binary", # Tactil
"categorical", # Web
"numerical", # Precio
"numerical", # RankingMarca
"text", # OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
"binary", # gpu_dedicada
"categorical" #Precio_clase
),
stringsAsFactors = FALSE
)
rownames(desc) = desc$variable
vars_num = desc$variable[desc$tipo == "numerical"]
Transformacione de dato en formato erróneo
convertir_decimal = function(x) {
as.numeric(gsub(",", ".", x))
}
df$VelocidadMaxProcesador = convertir_decimal(df$VelocidadMaxProcesador)
df$Pantalla = convertir_decimal(df$Pantalla)
df$Peso = convertir_decimal(df$Peso)
df$DiscoDuroGB = as.numeric(gsub("[^0-9\\.]", "", df$DiscoDuroGB))
for (var in vars_num) {
print(paste(var, ":", class(df[[var]])))}
## [1] "RAM : integer"
## [1] "DiscoDuroGB : numeric"
## [1] "NúcleosCPU : integer"
## [1] "VelocidadMaxProcesador : numeric"
## [1] "NúcleosGPU : integer"
## [1] "Pantalla : numeric"
## [1] "Peso : numeric"
## [1] "Precio : integer"
## [1] "RankingMarca : integer"
La RTX 5090 no existe, debe ser un error en la introduccción de datos.
unique(df$GPU[df$gpu_dedicada == 0])
## [1] "AMD Radeon Graphics" "Intel Iris X"
## [3] "Intel UHD Graphics" "Adreno Onboard Graphics"
## [5] "Dimensity Onboard Graphics" NA
## [7] "M4" "Radeon Onboard Graphics"
## [9] "Intel Graphics" "NVIDIA GeForce RTX 5090"
## [11] "M3"
df$GPU[df$GPU == "NVIDIA GeForce RTX 5090"] = "NVIDIA GeForce RTX 4090"
Nueva variable para distinguir entre GPUs integradas y dedicadas.
gpus_dedicadas = c(
"Intel Arc Graphics",
# NVIDIA RTX
"NVIDIA GeForce RTX",
"NVIDIA GeForce RTX 2050",
"NVIDIA GeForce RTX 3050",
"NVIDIA GeForce RTX 3070",
"NVIDIA GeForce RTX 3080",
"NVIDIA GeForce RTX 4050",
"NVIDIA GeForce RTX 4060",
"NVIDIA GeForce RTX 4070",
"NVIDIA GeForce RTX 4080",
"NVIDIA GeForce RTX 4090"
)
df$gpu_dedicada = ifelse(df$GPU %in% gpus_dedicadas, 1, 0)
unique(df$GPU[df$gpu_dedicada == 0]) # Solo integradas
## [1] "AMD Radeon Graphics" "Intel Iris X"
## [3] "Intel UHD Graphics" "Adreno Onboard Graphics"
## [5] "Dimensity Onboard Graphics" NA
## [7] "M4" "Radeon Onboard Graphics"
## [9] "Intel Graphics" "M3"
print("-----------------------------------------------------------------------------------------------------------------" )
## [1] "-----------------------------------------------------------------------------------------------------------------"
unique(df$GPU[df$gpu_dedicada == 1]) # Solo dedicadas
## [1] "NVIDIA GeForce RTX 4050" "NVIDIA GeForce RTX 2050"
## [3] "NVIDIA GeForce RTX 4060" "Intel Arc Graphics"
## [5] "NVIDIA GeForce RTX" "NVIDIA GeForce RTX 4070"
## [7] "NVIDIA GeForce RTX 3050" "NVIDIA GeForce RTX 4090"
## [9] "NVIDIA GeForce RTX 4080" "NVIDIA GeForce RTX 3080"
## [11] "NVIDIA GeForce RTX 3070"
Estos datos de los núcleos de las GPU han sido estimados y extraídos a partir fuentes oficiales de los fabricantes, con ayuda de la IA.
df$NúcleosGPU[df$NúcleosGPU == 0] = NA
df$NúcleosGPU[df$GPU == "AMD Radeon Graphics"] = 512
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Intel Iris X"] = 768
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Intel UHD Graphics"] = 192
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Adreno Onboard Graphics"] = 128
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Dimensity Onboard Graphics"] = 128
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == ""] = 0
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "M3"] = 8
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "M4"] = 10
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Radeon Onboard Graphics"] = 512
df$NúcleosGPU[is.na(df$NúcleosGPU) & df$GPU == "Intel Graphics"] = 192
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 3050"] = 2560
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 3070"] = 5120
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 3080"] = 6144
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 4050"] = 2560
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 4060"] = 3072
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 4070"] = 4608
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 4080"] = 7424
df$NúcleosGPU[df$GPU == "NVIDIA GeForce RTX 4090"] = 9728
df$NúcleosGPU[df$GPU == "Intel Arc Graphics"] = 1024
df$NúcleosGPU[df$GPU == "AMD Radeon Graphics"] = 1536
table(df$gpu_dedicada, df$NúcleosGPU)
##
## 8 10 14 16 20 32 40 128 192 512 768 1024 1536 2560 3072 4608 5120 6144
## 0 9 44 1 10 12 6 13 8 78 5 50 0 17 0 0 0 0 0
## 1 0 0 0 0 0 0 0 0 0 0 0 23 0 6 9 10 2 2
##
## 7424 9728
## 0 0 0
## 1 4 5
table(df$NúcleosGPU)
##
## 8 10 14 16 20 32 40 128 192 512 768 1024 1536 2560 3072 4608
## 9 44 1 10 12 6 13 8 78 5 50 23 17 6 9 10
## 5120 6144 7424 9728
## 2 2 4 5
Trabajar los anómalos
df[df == ""] <- NA
summary(df)
## Nombre Marca SO RAM
## Length:321 Length:321 Length:321 Min. : 4.00
## Class :character Class :character Class :character 1st Qu.: 16.00
## Mode :character Mode :character Mode :character Median : 16.00
## Mean : 23.86
## 3rd Qu.: 32.00
## Max. :128.00
##
## DiscoDuroGB ProcesadorCPU NúcleosCPU VelocidadMaxProcesador
## Min. : 128.0 Length:321 Min. : 1.0 Min. :1.000
## 1st Qu.: 512.0 Class :character 1st Qu.:10.0 1st Qu.:4.300
## Median : 512.0 Mode :character Median :10.0 Median :4.800
## Mean : 969.8 Mean :11.6 Mean :4.467
## 3rd Qu.:1024.0 3rd Qu.:14.0 3rd Qu.:5.100
## Max. :8000.0 Max. :24.0 Max. :5.800
## NA's :17 NA's :127
## GPU NúcleosGPU Pantalla Peso
## Length:321 Min. : 8.0 Min. :12.40 Min. :0.895
## Class :character 1st Qu.: 32.0 1st Qu.:14.00 1st Qu.:1.560
## Mode :character Median : 192.0 Median :15.60 Median :1.650
## Mean : 949.7 Mean :15.04 Mean :1.786
## 3rd Qu.: 768.0 3rd Qu.:15.60 3rd Qu.:1.880
## Max. :9728.0 Max. :18.00 Max. :3.600
## NA's :7 NA's :68
## Tactil Web Precio RankingMarca
## Min. :0.00000 Length:321 Min. : 202 Min. : 1
## 1st Qu.:0.00000 Class :character 1st Qu.: 799 1st Qu.: 1
## Median :0.00000 Mode :character Median :1591 Median : 47
## Mean :0.09091 Mean :1873 Mean :100
## 3rd Qu.:0.00000 3rd Qu.:2344 3rd Qu.:136
## Max. :1.00000 Max. :8574 Max. :526
## NA's :13 NA's :29
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS Precio_clase gpu_dedicada
## Length:321 Muy bajo :84 Min. :0.0000
## Class :character Medio-bajo:77 1st Qu.:0.0000
## Mode :character Medio-alto:80 Median :0.0000
## Muy alto :80 Mean :0.2056
## 3rd Qu.:0.0000
## Max. :1.0000
##
df$Tactil[is.na(df$Tactil)] = 0
df %>%
summarise(across(everything(), list(
Total_NA = ~sum(is.na(.)),
Porcentaje_NA = ~round(mean(is.na(.)) * 100, 2)
)))
## Nombre_Total_NA Nombre_Porcentaje_NA Marca_Total_NA Marca_Porcentaje_NA
## 1 0 0 0 0
## SO_Total_NA SO_Porcentaje_NA RAM_Total_NA RAM_Porcentaje_NA
## 1 0 0 0 0
## DiscoDuroGB_Total_NA DiscoDuroGB_Porcentaje_NA ProcesadorCPU_Total_NA
## 1 0 0 0
## ProcesadorCPU_Porcentaje_NA NúcleosCPU_Total_NA NúcleosCPU_Porcentaje_NA
## 1 0 17 5.3
## VelocidadMaxProcesador_Total_NA VelocidadMaxProcesador_Porcentaje_NA
## 1 127 39.56
## GPU_Total_NA GPU_Porcentaje_NA NúcleosGPU_Total_NA NúcleosGPU_Porcentaje_NA
## 1 2 0.62 7 2.18
## Pantalla_Total_NA Pantalla_Porcentaje_NA Peso_Total_NA Peso_Porcentaje_NA
## 1 0 0 68 21.18
## Tactil_Total_NA Tactil_Porcentaje_NA Web_Total_NA Web_Porcentaje_NA
## 1 0 0 0 0
## Precio_Total_NA Precio_Porcentaje_NA RankingMarca_Total_NA
## 1 0 0 29
## RankingMarca_Porcentaje_NA OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS_Total_NA
## 1 9.03 318
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS_Porcentaje_NA Precio_clase_Total_NA
## 1 99.07 0
## Precio_clase_Porcentaje_NA gpu_dedicada_Total_NA gpu_dedicada_Porcentaje_NA
## 1 0 0 0
sum(df$Marca=='Apple')
## [1] 88
Imputación de datos faltantes.
categ = desc$variable[desc$tipo == "categorical"]
for (cc in categ) {
df[,cc] = factor(df[,cc])
}
# Realizamos la imputación
dfImp = mice(df, m = 1)
##
## iter imp variable
## 1 1 NúcleosCPU* VelocidadMaxProcesador* GPU NúcleosGPU* Peso* RankingMarca*
## 2 1 NúcleosCPU* VelocidadMaxProcesador GPU NúcleosGPU* Peso* RankingMarca*
## 3 1 NúcleosCPU* VelocidadMaxProcesador GPU NúcleosGPU* Peso* RankingMarca*
## 4 1 NúcleosCPU* VelocidadMaxProcesador* GPU NúcleosGPU* Peso* RankingMarca*
## 5 1 NúcleosCPU* VelocidadMaxProcesador GPU NúcleosGPU* Peso* RankingMarca*
## Warning: Number of logged events: 54
# Recuperamos los datos imputados
dfImp = mice::complete(dfImp)
summary(df)
## Nombre Marca SO RAM
## Length:321 Apple :88 Windows 11 :123 Min. : 4.00
## Class :character DELL :53 macOS : 88 1st Qu.: 16.00
## Mode :character HP :38 Windows 11 Pro: 51 Median : 16.00
## ASUS :23 FreeDOS : 31 Mean : 23.86
## LENOVO :23 Sin SO : 15 3rd Qu.: 32.00
## SAMSUNG:22 Ubuntu LINUX : 5 Max. :128.00
## (Other):74 (Other) : 8
## DiscoDuroGB ProcesadorCPU NúcleosCPU
## Min. : 128.0 Intel Core i5 :56 Min. : 1.0
## 1st Qu.: 512.0 M4 :44 1st Qu.:10.0
## Median : 512.0 Intel Core Ultra 7:39 Median :10.0
## Mean : 969.8 Intel Core Ultra 5:34 Mean :11.6
## 3rd Qu.:1024.0 Intel Core i7 :31 3rd Qu.:14.0
## Max. :8000.0 M4 Pro :22 Max. :24.0
## (Other) :95 NA's :17
## VelocidadMaxProcesador GPU NúcleosGPU
## Min. :1.000 M4 :85 Min. : 8.0
## 1st Qu.:4.300 Intel Graphics :55 1st Qu.: 32.0
## Median :4.800 Intel Iris X :52 Median : 192.0
## Mean :4.467 Intel UHD Graphics:28 Mean : 949.7
## 3rd Qu.:5.100 Intel Arc Graphics:23 3rd Qu.: 768.0
## Max. :5.800 (Other) :76 Max. :9728.0
## NA's :127 NA's : 2 NA's :7
## Pantalla Peso Tactil Web
## Min. :12.40 Min. :0.895 Min. :0.00000 Apple :66
## 1st Qu.:14.00 1st Qu.:1.560 1st Qu.:0.00000 Dell :44
## Median :15.60 Median :1.650 Median :0.00000 Mediamarkt :44
## Mean :15.04 Mean :1.786 Mean :0.08723 PcComponentes:38
## 3rd Qu.:15.60 3rd Qu.:1.880 3rd Qu.:0.00000 Amazon :27
## Max. :18.00 Max. :3.600 Max. :1.00000 ElCorteIngles:26
## NA's :68 (Other) :76
## Precio RankingMarca OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS
## Min. : 202 Min. : 1 Length:321
## 1st Qu.: 799 1st Qu.: 1 Class :character
## Median :1591 Median : 47 Mode :character
## Mean :1873 Mean :100
## 3rd Qu.:2344 3rd Qu.:136
## Max. :8574 Max. :526
## NA's :29
## Precio_clase gpu_dedicada
## Muy bajo :84 0:255
## Medio-bajo:77 1: 66
## Medio-alto:80
## Muy alto :80
##
##
##
dfImp %>%
summarise(across(everything(), list(
Total_NA = ~sum(is.na(.)),
Porcentaje_NA = ~round(mean(is.na(.)) * 100, 2)
)))
## Nombre_Total_NA Nombre_Porcentaje_NA Marca_Total_NA Marca_Porcentaje_NA
## 1 0 0 0 0
## SO_Total_NA SO_Porcentaje_NA RAM_Total_NA RAM_Porcentaje_NA
## 1 0 0 0 0
## DiscoDuroGB_Total_NA DiscoDuroGB_Porcentaje_NA ProcesadorCPU_Total_NA
## 1 0 0 0
## ProcesadorCPU_Porcentaje_NA NúcleosCPU_Total_NA NúcleosCPU_Porcentaje_NA
## 1 0 0 0
## VelocidadMaxProcesador_Total_NA VelocidadMaxProcesador_Porcentaje_NA
## 1 0 0
## GPU_Total_NA GPU_Porcentaje_NA NúcleosGPU_Total_NA NúcleosGPU_Porcentaje_NA
## 1 0 0 0 0
## Pantalla_Total_NA Pantalla_Porcentaje_NA Peso_Total_NA Peso_Porcentaje_NA
## 1 0 0 0 0
## Tactil_Total_NA Tactil_Porcentaje_NA Web_Total_NA Web_Porcentaje_NA
## 1 0 0 0 0
## Precio_Total_NA Precio_Porcentaje_NA RankingMarca_Total_NA
## 1 0 0 0
## RankingMarca_Porcentaje_NA OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS_Total_NA
## 1 0 318
## OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS_Porcentaje_NA Precio_clase_Total_NA
## 1 99.07 0
## Precio_clase_Porcentaje_NA gpu_dedicada_Total_NA gpu_dedicada_Porcentaje_NA
## 1 0 0 0
Análisis de datos Creación de un df sin outliers
# Paso 1: Calcular Q1, Q3 e IQR
q1 = quantile(dfImp$Precio, 0.25, na.rm = TRUE)
q3 = quantile(dfImp$Precio, 0.75, na.rm = TRUE)
iqr = q3 - q1
# Paso 2: Calcular límites inferior y superior
limite_inf = q1 - 1.5 * iqr
limite_sup = q3 + 1.5 * iqr
# Paso 3: Filtrar el dataframe
df_sin_outliers = dfImp[dfImp$Precio >= limite_inf & dfImp$Precio <= limite_sup, ]
nrow(dfImp) - nrow(df_sin_outliers)
## [1] 20
df_num = dfImp[ , vars_num]
PCA Quitar para el pca: VelocidadMaxProcesador,Peso,OTRAS
df_pca = dfImp[, !(names(dfImp) %in% c("OTRAS.CARACTERÍSTICAS.Q.CONSIDERÉIS", "Peso", "VelocidadMaxProcesador"))]
df_pca$vDiscoDuroGB <- as.numeric(factor(dfImp$DiscoDuroGB))
# Variables cualitativas suplementarias
vars_sup_quali <- c("Nombre", "GPU", "Web", "Marca", "SO", "ProcesadorCPU", "Precio_clase", "gpu_dedicada")
# Asegurarte de que estén como factor
df_pca[ , vars_sup_quali] <- lapply(df_pca[ , vars_sup_quali], as.factor)
# Asegurarte de que DiscoDuroGB esté como numérica
df_pca$DiscoDuroGB <- as.numeric(as.character(df_pca$DiscoDuroGB))
# Índices de variables cualitativas suplementarias
quali.sup.vars <- which(names(df_pca) %in% vars_sup_quali)
# Índices de variables cuantitativas suplementarias (ajusta si aplica)
quanti.sup.vars <- which(names(df_pca) %in% c("DiscoDuroGB",'Precio'))
# Ejecutar PCA
res.pca <- PCA(df_pca,
scale.unit = TRUE,
graph = TRUE,
ncp = 10,
quali.sup = quali.sup.vars,
quanti.sup = quanti.sup.vars)
# Obtener eigenvalores
eig.val <- get_eigenvalue(res.pca)
VPmedio <- 100 * (1 / nrow(eig.val))
# Graficar eigenvalores
fviz_eig(res.pca, addlabels = TRUE) +
geom_hline(yintercept = VPmedio, linetype = 2, color = "red")
# Mostrar primeros 6 eigenvalores
kable(eig.val[1:6,])
| eigenvalue | variance.percent | cumulative.variance.percent | |
|---|---|---|---|
| Dim.1 | 2.2519506 | 32.170723 | 32.17072 |
| Dim.2 | 1.7137292 | 24.481846 | 56.65257 |
| Dim.3 | 1.0319036 | 14.741479 | 71.39405 |
| Dim.4 | 0.7180208 | 10.257440 | 81.65149 |
| Dim.5 | 0.4868903 | 6.955576 | 88.60706 |
| Dim.6 | 0.4428203 | 6.326004 | 94.93307 |
# Biplot de individuos y variables, coloreando por GPU dedicada
fviz_pca_biplot(res.pca,
label = "var", # Muestra las variables
habillage = "gpu_dedicada", # Agrupa por esta variable (debe ser factor en df_pca)
addEllipses = FALSE, # Añade elipses de concentración
repel =FALSE # Evita solapamiento de etiquetas
)
Algunos de las características que más afectan al precio es el RAM, los GB del disco duro y los núcleos de la GPU
fviz_pca_biplot(res.pca,
repel = TRUE,
col.var = "#2E9FDF",
col.ind = "#696969")
fviz_contrib(res.pca, choice = "var", axes = 1, top = 10) # Para el componente 1
fviz_contrib(res.pca, choice = "var", axes = 2, top = 10) # Para el componente 2
fviz_pca_ind(res.pca,
geom = "point",
col.ind = "contrib", # Colorea según calidad de representación
gradient.cols = c("#00AFBB", "#E7B800", "#FC4E07"),
repel = TRUE) # Evita sobreposición de etiquetas
corrplots
vars_num = desc$variable[desc$tipo == "numerical"]
df_num = dfImp[ , vars_num]
cor_kendall = cor(df_num, method = "kendall")
cor_kendall = cor_kendall[!rownames(cor_kendall) %in% "RankingMarca",
!colnames(cor_kendall) %in% "RankingMarca"]
corrplot(cor_kendall, method = "color", type = "upper", tl.cex = 0.8, number.cex = 0.7, addCoef.col = "black")
vars_num = desc$variable[desc$tipo == "numerical"]
df_num = df_sin_outliers[ , vars_num]
matriz_cor = cor(df_num)
corrplot(matriz_cor, method = "color", type = "upper", # “circle”, “square”, “ellipse”, “number”, “shade”, “color”, “pie”
tl.cex = 0.8, number.cex = 0.7, addCoef.col = "black")
vars = c("RAM", "DiscoDuroGB", "NúcleosCPU", "VelocidadMaxProcesador", "NúcleosGPU")
# Convertir a numérico por si acaso
dfImp[vars] = lapply(dfImp[vars], function(x) as.numeric(as.character(x)))
# Bucle para crear y mostrar los gráficos
for (var in vars) {
p = ggplot(df, aes_string(x = var, y = "Precio")) +
geom_point(alpha = 0.6, color = "steelblue") +
geom_smooth(method = "", se = FALSE, color = "red") +
labs(title = paste("Precio vs", var),
x = var,
y = "Precio (€)") +
theme_minimal()
print(p)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation idioms with `aes()`.
## ℹ See also `vignette("ggplot2-in-packages")` for more information.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Computation failed in `stat_smooth()`.
## Caused by error in `get()`:
## ! primer argumento inválido
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Computation failed in `stat_smooth()`.
## Caused by error in `get()`:
## ! primer argumento inválido
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 17 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Computation failed in `stat_smooth()`.
## Caused by error in `get()`:
## ! primer argumento inválido
## Warning: Removed 17 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 127 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Computation failed in `stat_smooth()`.
## Caused by error in `get()`:
## ! primer argumento inválido
## Warning: Removed 127 rows containing missing values or values outside the scale range
## (`geom_point()`).
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 7 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Computation failed in `stat_smooth()`.
## Caused by error in `get()`:
## ! primer argumento inválido
## Warning: Removed 7 rows containing missing values or values outside the scale range
## (`geom_point()`).
# Filtrar solo filas con GPU dedicada
df_gpu_dedicada = dfImp[dfImp$gpu_dedicada == 1, ]
# Calcular correlación (evitando NA)
correlacion = cor(df_gpu_dedicada$Precio, df_gpu_dedicada$NúcleosGPU)
print(paste("Correlación Precio ~ NúcleosGPU(dedicada):", round(correlacion, 3)))
## [1] "Correlación Precio ~ NúcleosGPU(dedicada): 0.725"
# Scatterplot
ggplot(df_gpu_dedicada, aes(x = NúcleosGPU, y = Precio)) +
geom_point(color = "darkblue", alpha = 0.6) +
geom_smooth(method = "lm", se = FALSE, color = "red") +
labs(
title = "Precio vs Núcleos de GPU (solo GPU dedicada)",
x = "Núcleos GPU",
y = "Precio (€)"
) +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
AFC
vars_cat = desc$variable[desc$tipo %in% c("categorical", "binary")]
df_cat = df[ , vars_cat]
df_cat = data.frame(lapply(df_cat, as.factor))
mca = MCA(df_cat, graph = FALSE)
fviz_mca_var(mca, repel = TRUE)
fviz_mca_ind(mca, habillage = df$Precio_clase, addEllipses = TRUE, repel = TRUE) #vemos que afecta más
fviz_mca_biplot(mca, habillage = df$Precio_clase, addEllipses = TRUE, repel = TRUE)
dfImp %>%
group_by(SO) %>%
summarise(
media = mean(Precio, na.rm = TRUE),
mediana = median(Precio, na.rm = TRUE),
n = n()
)
## # A tibble: 9 × 4
## SO media mediana n
## <fct> <dbl> <dbl> <int>
## 1 ChromeOS 410 431 4
## 2 FreeDOS 881. 627 31
## 3 macOS 3148. 2689 88
## 4 Sin SO 521. 549 15
## 5 Ubuntu LINUX 1586 1551 5
## 6 Windows (sin especificar) 599 599 2
## 7 Windows 10 648. 648. 2
## 8 Windows 11 1508. 999 123
## 9 Windows 11 Pro 1794. 1888 51
vars_cat = desc$variable[desc$tipo %in% c("categorical", "binary")]
vars_cat = setdiff(vars_cat, c("Marca", "Web","Precio_clase")) # elimina Marca y Web y precioclase
resultados_anova = data.frame(Variable = character(), p_valor = numeric())
for (var in vars_cat) {
# Crear fórmula
f = as.formula(paste("Precio ~", var))
# Ejecutar ANOVA
modelo = aov(f, data = df)
# Extraer p-valor
p_valor = summary(modelo)[[1]][["Pr(>F)"]][1]
# Guardar resultados
resultados_anova = rbind(resultados_anova, data.frame(Variable = var, p_valor = p_valor))
}
resultados_anova$p_valor = signif(resultados_anova$p_valor, digits = 4)
resultados_anova = resultados_anova[order(resultados_anova$p_valor), ]
print(resultados_anova)
## Variable p_valor
## 2 ProcesadorCPU 7.083e-97
## 3 GPU 3.536e-47
## 1 SO 1.267e-25
## 5 gpu_dedicada 5.127e-03
## 4 Tactil 2.914e-02
library(ggplot2)
ggplot(dfImp, aes(y = SO, x = Precio)) +
geom_boxplot() +
theme_minimal() +
labs(title = "Distribución del precio por sistema operativo")
ggplot(dfImp, aes(x = Marca, y = Precio)) +
geom_boxplot() +
theme_minimal() +
labs(title = "Distribución del precio por Marca")
desc$variable[desc$tipo %in% c("categorical", "binary")]
## [1] "Marca" "SO" "ProcesadorCPU" "GPU"
## [5] "Tactil" "Web" "Precio_clase" "gpu_dedicada"
ggplot(dfImp, aes(x = Precio,y = ProcesadorCPU)) +
geom_boxplot() +
theme_minimal() +
labs(title = "Distribución del precio por Procesador")
ggplot(dfImp, aes(x = Precio,y = GPU)) +
geom_boxplot() +
theme_minimal() +
labs(title = "Distribución del precio por GPU")
`
ggplot(df, aes(y = GPU, x = Precio, fill = factor(gpu_dedicada))) +
geom_boxplot() +
scale_fill_manual(values = c("lightblue", "orange"),
labels = c("Integrada", "Dedicada"),
name = "Tipo de GPU") +
theme_minimal() +
labs(
title = "Precio por GPU, según si es integrada o dedicada",
x = "GPU",
y = "Precio (€)"
)
ggplot(dfImp, aes(y = factor(gpu_dedicada), x = Precio)) +
geom_boxplot(fill = "skyblue") +
scale_y_discrete(labels = c("0" = "Sin GPU dedicada", "1" = "Con GPU dedicada")) +
labs(
title = "Distribución del precio según tipo de GPU",
y = "Tipo de GPU",
x = "Precio (€)"
) +
theme_minimal()
ggplot(dfImp, aes(x = Precio)) +
geom_boxplot(fill = "darkorange") +
labs(
title = "Distribución del precio de los portátiles",
) +
theme_minimal()
write.csv(dfImp, "dfImp.csv", row.names = FALSE)
write.csv(df_pca, "dfpca.csv", row.names = FALSE)
write.csv(df, "dfDEF.csv", row.names = FALSE)
```