Calculate Statistics for a Transaction Database with Utility and Time Period Information (SPMF documentation)

This example explains how to calculate statistics for a transaction database with utility and time period information using the SPMF open-source data mining library.

How to run this example?

What is this tool?

This tool is a tool for generating statistics about a transaction database that contains utility and time period information. This tool can be used to know for example what is the average length of transaction in a database, and what is the total utility of the database. This type of database is used as input by some on-hself high utility itemset mining algorithms such as FOSHU.

What is the input?

The input is a transaction database with information about the utility of items and their shelf time time. For example, let's consider the following database consisting of 5 transactions (t1,t2, ..., t5) and 7 items (1, 2, 3, 4, 5, 6, 7). This database is provided in the text file "DB_FOSHU.txt" in the package ca.pfv.spmf.tests of the SPMF distribution.

Transaction Items Transaction utility (positive) Item utilities for this transaction Time period
t1 1 3 4 3 -5 1 2 0
t2 1 3 5 7 17 -10 6 6 5 0
t3 1 2 3 4 5 6 25 -5 4 1 12 3 5 1
t4 2 3 4 5 20 8 3 6 3 1
t5 2 3 5 7 11 4 2 3 2 2

Each line of the database represents a transaction and contains the following information:

Note that the value in the third column for each line is the sum of the positive values in the fourth column. Moreoever, note that utility values may be positive or negative integers. Time periods are values numbered 0,1,2,3..., which may represent for example periods such as "summer", "fall", "winter" and "spring".

What are real-life examples of such a database? There are several applications in real life. The main application is for customer transaction databases. Imagine that each transaction represents the items purchased by a customer. The first customer named "t1" bought items 1, 3 and 4. The amount of profit generated by the sale of each of these item is respectively -5 $, 1 $ and 2 $. The total amount of money spent in this transaction is -5 + 1 + 2 = 3 $. This transaction was done during time period "0", which may for example represents the summer.

What is the output?

The output is statistics about the transaction database. For example, if we use the tool on the previous database given as example, we get the following statistics:

---------- Utility transaction database with time information----------
Number of transations : 5
Transactions time range from: 0 to 2
Total utility : 76
Number of distinct items : 7
Maximum Id of item : 7
Average length of transaction : 4.2
Maximum length of transaction : 6
Average utility per item: 2.6666666666666665 standard deviation: 4.6222374847122865 variance: 21.365079365079364
Database density: 60.0 %

Note: the database density is calculated as the average transaction length divided by the number of distinct items.

Input file format

The input file format is defined as follows. It is a text file. Each lines represents a transaction. Each line is composed of three sections, as follows.

For example, for the previous example, the input file is defined as follows:

1 3 4:3:-5 1 2:0
1 3 5 7:17:-10 6 6 5:0
1 2 3 4 5 6:25:-5 4 1 12 3 5:1
2 3 4 5:20:8 3 6 3:1
2 3 5 7:11:4 2 3 2:2

Consider the first line. It means that the transaction {1,3, 4} has a total utility of 3 and that items 1, 3 and 4 respectively have a utility of -5, 1 and 2 in this transaction. The following lines follow the same format.