Analisi del carrello in R
Christopher Bruffaerts
Statistician
Corso Market Basket

Carrello = insieme di articoli
Articoli

Esempi di carrelli:
Il tuo carrello al supermercato
Il tuo carrello Amazon
I tuoi corsi su DataCamp
I film che hai visto su Netflix
Cosa c’è in negozio?

Cosa prendi oggi?

Cosa c’è in negozio?
store = c("Bread", "Butter",
"Cheese", "Wine")
set.seed(1234)
n_items = 4
my_basket = data.frame(
TID = rep(1,n_items),
Product = sample(
store, n_items,
replace = TRUE))
Output R
my_basket
TID Product
1 1 Bread
2 1 Cheese
3 1 Cheese
4 1 Cheese
Il mio carrello originale
Un record per ogni articolo acquistato
TID Product
1 1 Bread
2 1 Cheese
3 1 Cheese
4 1 Cheese
Il mio carrello adattato
Un record per ogni articolo distinto acquistato
# A tibble: 2 x 3
TID Product Quantity
<dbl> <fct> <int>
1 1 Bread 1
2 1 Cheese 3
Rimodellare i dati del carrello
# Adjusting my basket
my_basket = my_basket %>%
add_count(Product) %>%
unique() %>%
rename(Quantity = n)
# Numero di articoli distinti
n_distinct(my_basket$Product)
2
# Dimensione totale del carrello
my_basket %>% summarize(sum(Quantity))
4
Visualizzare gli articoli nel carrello
# Plotting items
ggplot(my_basket,
aes(x=reorder(Product, Quantity),
y = Quantity)) +
geom_col() +
coord_flip() +
xlab("Items") +
ggtitle("Summary of items
in my basket")

Domanda: C’è relazione tra gli articoli nello stesso carrello?

Torniamo agli esempi
Il tuo carrello al supermercato, e.g. Spaghetti e salsa di pomodoro
Il tuo carrello Amazon, e.g. Telefono e cover
I tuoi corsi su DataCamp e.g. "Introduction to R" e "Intermediate R"
Analisi del carrello in R