Calculate Statistics for a Transaction Database with Utility and Time Information (SPMF documentation)
This example explains how to calculate statistics for a transaction database with utility and time information using the SPMF open-source data mining library.
How to run this example?
- If you are using the graphical interface, (1) choose the "Calculate_stats_for_a_transaction_database_with_utility_time" algorithm, (2) choose the input file DB_LTHUI.txt (3) click "Run algorithm".
- If you want to execute this example from the command
line, then execute this command:
java -jar spmf.jar run Calculate_stats_for_a_transaction_database_with_utility_time DB_LTHUI.txt no_output_file in a folder containing spmf.jar and the input file DB_LTHUI.txt. - If you are using the source code version of SPMF, launch the file "MainTestStatsUtilityTimeDB.java" in the package ca.pfv.SPMF.tests.
What is this tool?
This tool is a tool for generating statistics about a transaction database that contains utility and timeinformation. 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 high utility itemset mining algorithms such as LTHUI-Miner.
What is the input?
The input is a transaction database with utility information.
Let's consider the following database consisting of 8 transactions (t1,t2...t8) and 5 items (1, 2, 3, 4, 5), and each transaction is associated with a timestamp. This database is provided in the text file "DB_utility_time.txt" in the package ca.pfv.spmf.tests of the SPMF distribution.
Items |
Transaction utility |
Item utilities for this transaction |
Timestamp |
|
t1 |
2 3 5 |
9 |
4 2 3 |
1 |
t2 |
2 3 4 5 |
18 |
8 3 4 3 |
3 |
t3 |
2 3 4 5 |
9 |
4 2 10 3 |
3 |
t4 |
1 2 3 4 5 |
58 |
10 20 2 20 6 |
5 |
t5 |
1 3 5 |
22 |
10 6 6 |
6 |
t6 |
2 3 5 |
14 |
8 3 3 |
7 |
t7 |
1 3 4 |
16 |
10 2 4 |
9 |
t8 |
1 3 5 |
22 |
10 6 6 |
10 |
Each line of the database is:
- a set of items (the first column of the table),
- the sum of the utilities (e.g. profit) of these items in this transaction (the second column of the table),
- the utility of each item for this transaction (e.g. profit generated by this item for this transaction)(the third column of the table).
- the timestamp which indicated when this transaction was made(the fourth column of the table)
Note that the value in the second column for each line is the sum of the values in the third column.
What are real-life examples of such a database? There are several applications in real life. One application is a customer transaction database. Imagine that each transaction represents the items purchased by a customer. The first customer named "t1" bought items 2, 3 and 5. The amount of money spent for each item is respectively 4 $, 2 $ and 3 $. The total amount of money spent in this transaction is 4 + 2 + 3 = 9 $. And the purchase was made in
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:
Number of transations : 9
Transactions time range from: 1 to 12
Total utility : 177
Number of distinct items : 5
Maximum Id of item : 5
Average length of transaction : 2.88
Maximum length of transaction : 4
Average utility per item: 6.8076923076923075 standard deviation: 6.486786752072548 variance: 42.07840236686391
Database density: 57.599999999999994 %
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 line represents a transaction. Each line is composed of four sections, as follows.
- First, the items contained in the transaction are listed. An item is represented by a positive integer. Each item is separated from the next item by a single space. It is assumed that all items within a same transaction (line) are sorted according to a total order (e.g. ascending order) and that no item can appear twice within the same transaction.
- Second, the symbol ":" appears and is followed by the transaction utility (an integer).
- Third, the symbol ":" appears and is followed by the utility of each item in this transaction (an integer), separated by single spaces.
- Fourth, the symbol ":" appears and is followed by the timestamp (an integer) indicating when the transaction were made.
For example, for the previous example, the input file is defined as follows:
2 3 5:9:4 2 3:1
2 3 4 5:18:8 3 4 3:3
2 3 4 5:9:4 2 10 3:3
1 2 3 4 5:58:10 20 2 20 6:5
1 3 5:22:10 6 6:6
2 3 5:14:8 3 3:7
1 3 4:16:10 2 4:9
1 3 5:22:10 6 6:10
Consider the first line. It means that the transaction {2, 3, 5} has a total utility of 9 and that items 2, 3 and 5 respectively have a utility of 4, 2 and 3 in this transaction, and the transaction were made at time 1. The following lines follow the same format.