Equipo:

  • Carolina Velarde Díaz A01720509
  • Chantal Aimeé Simó García A00827554
  • Kízari Hernández Huerta A00828451
  • Ximena Araceli Martínez Flores A00829670

Carga de datos

catalogo<-read_csv('~/Documents/8/Bloques/Planeación estratégica basada en analítica prescriptiva/catalogo.csv')
## Rows: 102 Columns: 9
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (6): nombre, mls, gms, sku, familia, categoria
## dbl (2): id_producto, precio_unidad
## lgl (1): activo
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
clientes<-read_csv('~/Documents/8/Bloques/Planeación estratégica basada en analítica prescriptiva/clientes.csv')
## Rows: 100 Columns: 24
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (16): nom_estab, raz_social, per_ocu, tipo_vial, nom_vial, edificio, edi...
## dbl  (8): id_cliente, lat, long, cod_postal, cve_ent, cve_mun, cve_loc, manzana
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
detalle<-read_csv('~/Documents/8/Bloques/Planeación estratégica basada en analítica prescriptiva/detalle.csv')
## Rows: 154059 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (4): id_detalle, id_pedido, id_producto, cantidad
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
pedido<-read_csv('~/Documents/8/Bloques/Planeación estratégica basada en analítica prescriptiva/pedido.csv')
## Rows: 30000 Columns: 5
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): fechapedido, fechaentrega
## dbl (2): id_pedido, id_cliente
## lgl (1): cancelado
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
prospectos<-read_csv('~/Documents/8/Bloques/Planeación estratégica basada en analítica prescriptiva/prospectos.csv')
## Rows: 10000 Columns: 28
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (21): nombre_act, nom_estab, raz_social, per_ocu, tipo_vial, nom_vial, e...
## dbl  (7): lat, long, cod_postal, cve_ent, cve_mun, cve_loc, manzana
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Unión de bases de datos

# Unión 
Base1<-merge(detalle,catalogo,by.x='id_producto',by.y='id_producto',all.x=TRUE)
Base2<-merge(pedido,clientes,by.x='id_cliente',by.y='id_cliente',all.x=TRUE)
Base<-merge(Base1,Base2,by.x='id_pedido',by.y='id_pedido',all.x=TRUE)
Base$ventas<-Base$cantidad*Base$precio_unidad
rm(Base1,Base2)

Análisis exploratorio de la base de datos unida

skim(Base)
Data summary
Name Base
Number of rows 154059
Number of columns 40
_______________________
Column type frequency:
character 24
logical 2
numeric 14
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
nombre 0 1.00 3 15 0 102 0
mls 0 1.00 3 4 0 8 0
gms 0 1.00 2 3 0 6 0
sku 0 1.00 10 10 0 102 0
familia 0 1.00 5 9 0 6 0
categoria 0 1.00 6 9 0 2 0
fechapedido 0 1.00 8 8 0 1155 0
fechaentrega 209 1.00 8 8 0 989 0
nom_estab 0 1.00 11 60 0 52 0
raz_social 104609 0.32 5 52 0 20 0
per_ocu 0 1.00 14 18 0 5 0
tipo_vial 0 1.00 5 18 0 7 0
nom_vial 0 1.00 7 36 0 49 0
edificio 132037 0.14 11 24 0 5 0
edificio_e 132119 0.14 6 11 0 4 0
tipo_asent 0 1.00 6 14 0 5 0
nomb_asent 0 1.00 6 30 0 42 0
tipoCenCom 130673 0.15 15 33 0 3 0
nom_CenCom 130673 0.15 10 24 0 9 0
num_local 136068 0.12 1 7 0 7 0
entidad 0 1.00 9 9 0 1 0
municipio 0 1.00 7 24 0 9 0
localidad 0 1.00 8 24 0 9 0
ageb 0 1.00 2 4 0 48 0

Variable type: logical

skim_variable n_missing complete_rate mean count
activo 0 1 1.00 TRU: 154059
cancelado 0 1 0.05 FAL: 146232, TRU: 7827

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id_pedido 0 1.00 14996.79 8657.03 1.00 7489.00 14995.00 22483.00 30000.00 ▇▇▇▇▇
id_producto 0 1.00 51.52 29.44 1.00 26.00 52.00 77.00 102.00 ▇▇▇▇▇
id_detalle 0 1.00 77030.00 44473.15 1.00 38515.50 77030.00 115544.50 154059.00 ▇▇▇▇▇
cantidad 0 1.00 18.42 7.74 1.00 15.00 20.00 24.00 31.00 ▃▂▆▇▃
precio_unidad 0 1.00 87.95 50.26 12.00 37.00 103.00 124.00 250.00 ▇▃▇▁▁
id_cliente 0 1.00 30.04 24.16 1.00 13.00 25.00 35.00 100.00 ▇▇▁▂▂
lat 0 1.00 25.68 0.07 25.41 25.67 25.68 25.70 25.96 ▁▁▇▂▁
long 0 1.00 -100.30 0.06 -100.48 -100.33 -100.31 -100.28 -100.14 ▁▂▇▂▁
cod_postal 1362 0.99 65068.73 1158.71 64000.00 64000.00 64530.00 66267.00 67300.00 ▇▂▁▅▂
cve_ent 0 1.00 19.00 0.00 19.00 19.00 19.00 19.00 19.00 ▁▁▇▁▁
cve_mun 0 1.00 36.33 9.26 6.00 39.00 39.00 39.00 49.00 ▁▂▁▇▂
cve_loc 0 1.00 1.00 0.00 1.00 1.00 1.00 1.00 1.00 ▁▁▇▁▁
manzana 0 1.00 15.64 11.96 1.00 5.00 14.00 24.00 58.00 ▇▃▃▁▁
ventas 0 1.00 1622.53 1214.97 12.00 520.00 1455.00 2520.00 7750.00 ▇▆▂▁▁

Histogramas de variables númericas de interés

a<-ggplot(Base,aes(x=cantidad)) + 
  geom_histogram(aes(y=..density..),colour='black',fill='#07AAA4') +
  geom_vline(aes(xintercept=mean(cantidad)),
            color='black',linetype='dashed',size=1) +
  geom_density(alpha=.2,fill='#058A85') +
  labs(title='Histograma variable Cantidad') +
  xlab('cantidad') + 
  ylab('count') +
  theme_light()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
ggplotly(a)
## Warning: The dot-dot notation (`..density..`) was deprecated in ggplot2 3.4.0.
## ℹ Please use `after_stat(density)` instead.
## ℹ The deprecated feature was likely used in the ggplot2 package.
##   Please report the issue at <https://github.com/tidyverse/ggplot2/issues>.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
b<-ggplot(Base,aes(x=ventas)) + 
  geom_histogram(aes(y=..density..),colour='black',fill='#07AAA4') +
  geom_vline(aes(xintercept=mean(ventas)),
            color='black',linetype='dashed',size=1) +
  geom_density(alpha=.2,fill='#058A85') +
  labs(title='Histograma variable Ventas') +
  xlab('ventas') + 
  ylab('count') +
  theme_light()
ggplotly(b)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
c<-ggplot(Base,aes(x=precio_unidad)) + 
  geom_histogram(aes(y=..density..),colour='black',fill='#07AAA4') +
  geom_vline(aes(xintercept=mean(precio_unidad)),
            color='black',linetype='dashed',size=1) +
  geom_density(alpha=.2,fill='#058A85') +
  labs(title='Histograma variable Precio por unidad') +
  xlab('precio unidad') + 
  ylab('count') +
  theme_light()
ggplotly(c)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Análisis exploratorio de base de datos prospectos

skim(prospectos)
Data summary
Name prospectos
Number of rows 10000
Number of columns 28
_______________________
Column type frequency:
character 21
numeric 7
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
nombre_act 0 1.00 7 106 0 27 0
nom_estab 0 1.00 3 117 0 7767 0
raz_social 8310 0.17 3 82 0 1249 0
per_ocu 0 1.00 14 18 0 7 0
tipo_vial 31 1.00 5 18 0 16 0
nom_vial 0 1.00 1 41 0 3000 0
edificio 9232 0.08 1 42 0 107 0
edificio_e 9180 0.08 5 15 0 15 0
tipo_asent 31 1.00 5 21 0 29 0
nomb_asent 0 1.00 2 48 0 2528 0
tipoCenCom 9170 0.08 10 33 0 11 0
nom_CenCom 9168 0.08 3 49 0 344 0
num_local 9207 0.08 1 17 0 403 0
entidad 0 1.00 6 9 0 2 0
municipio 0 1.00 4 25 0 47 0
localidad 0 1.00 4 49 0 103 0
ageb 0 1.00 2 4 0 1335 0
AGEB_int 0 1.00 8 13 0 153 0
geohash5km 0 1.00 5 5 0 167 0
tipoUniEco 0 1.00 4 8 0 2 0
fecha_alta 0 1.00 7 7 0 21 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
lat 0 1.00 25.66 0.45 19.93 25.66 25.69 25.76 27.25 ▁▁▁▇▁
long 0 1.00 -100.25 0.17 -100.64 -100.34 -100.28 -100.19 -99.17 ▃▇▁▁▁
cod_postal 78 0.99 65895.15 1552.16 50300.00 64700.00 66260.00 67113.00 77777.00 ▁▁▇▃▁
cve_ent 0 1.00 18.98 0.25 15.00 19.00 19.00 19.00 19.00 ▁▁▁▁▇
cve_mun 0 1.00 30.41 13.03 1.00 21.00 33.00 39.00 51.00 ▃▃▅▇▃
cve_loc 0 1.00 11.03 52.13 1.00 1.00 1.00 1.00 464.00 ▇▁▁▁▁
manzana 0 1.00 19.45 26.01 1.00 7.00 17.00 28.00 800.00 ▇▁▁▁▁