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?
- If you are using the graphical interface, (1) choose the "Calculate_stats_for_a_transaction_database_with_utility_period" algorithm, (2) choose the input file DB_FOSHU.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_period DB_FOSHU.txt no_output_file in a folder containing spmf.jar and the input file DB_FOSHU.txt. - If you are using the source code version of SPMF, launch the file "MainTestStatsUtilityPeriodDB.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 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:
- a set of items (the second column of the table),
- the sum of the utilities (e.g. profit) of items having positive utilities in this transaction (the third column of the table),
- the utility of each item for this transaction (e.g. profit generated by this item for this transaction)(the fourth column of the table).
- the time period where this transaction occurred (the fifth column).
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.
- 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 a positive integer such as 0,1,2.... indicating the time period of the transaction
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.