Basket Analysis Correlations

Overview


One way to measure the degree to which the purchase of one product is associated with another product is to run a correlation between the two.

A correlation is a type of statistical moment that measures the degree to which two random variable are related. (see Covariance)

Implementation


Given a dataset of product purchases by a set of customers in a given time framme (see data for information)



The correlation between purchases of product 1 and product 4 is given, utitilizing the moments library.


let mt = await import('/lib/statistics/moments/v1.0.0/moments.mjs');
let numbers = data.map(p=>{
    return [p.product1, p.product4];
});
let correlations = mt.correlations(numbers);