Equipo:
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
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)
skim(Base)
| 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 | ▇▆▂▁▁ |
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`.