Basket Analysis Data

Overview


Basket data typically comes as a set of records representing a purchase. The following show a set of purchases for a set of customers. Each record represents a single customer over a given time frame, or period. Each column represents a separate product, and the number in the column represents how many units of product was purchased.

Purchase/Non Purchase


Sometimes, it is not important how many items of a particular product is purchased, but just whether the product was purchased at least once. In such a case, the above dataset would be transformed into one where the numbers are converted to 1 if they were greater than 1.

The following simple script utitilizes the map function to accomplish the transformation.


let data2 = data.map(p=>{
	let item = {};
	for(let key in p){
		if(p[key]>0) item[key] = 1;
		else item[key] =0
	}
	return item;
});