Fix Item Identifiers in a Transaction Database with Utility (SPMF documentation)
This example explains how to fix item identifiers in a transaction database using the SPMF open-source data mining library.
How to run this example?
- If you are using the graphical interface, (1) choose the "Fix_item_ids_in_transaction_database_with_utility" algorithm, (2) choose the input file DB_Utility_broken.txt (3) set the output file to "output.txt, (4) set the value to be added to item identifiers to "-1" and (5) click "Run algorithm".
- If you want to execute this example from the command
line, then execute this command:
java -jar spmf.jar run Fix_item_ids_in_transaction_database_with_utility DB_Utility_broken.txt output.txt -1 in a folder containing spmf.jar and the input file DB_Utility_broken.txt. - If you are using the source code version of SPMF, launch the file " MainTestFixItemIDsTransactionDatabaseWithUtility.java" in the package ca.pfv.SPMF.tests.
What is this tool?
The tool "Fix_item_ids_in_transaction_database_with_utility" is a small program that can be used to quickly increase or decrease the item identifiers of all items in a given transaction database file with utility information in SPMF format. This tool was created because some algorithms requires that all item identifiers be positive (e.g. 1, 2, 3...), but some datasets were containing an item "0". In this type of cases, this tool can be used to quickly fix the database by incrementing all item identifiers by 1 or some other values.
What is the input?
The input is a transaction database with utility information in SPMF format that need to be fixed.
A transaction database with utility information is defined as follows. Let's consider the following database consisting of 3 transactions (t1,t2...t3) and 7 items (1, 2, 3, 4, 5, 6, 7). This database is provided in the text file "DB_Utility_broken.txt" in the package ca.pfv.spmf.tests of the SPMF distribution.
| Items | Transaction utility | Item utilities for this transaction | |
| t1 | 4 6 2 3 5 7 | 30 | 1 3 5 10 6 5 |
| t2 | 4 6 3 5 | 20 | 3 3 8 6 |
| t3 | 4 2 5 | 8 | 1 5 2 |
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).
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 4, 6, 2, 3, 5 and 7. The amount of money spent for each item is respectively 1 $, 3 $, 5 $, 10 $, 6 $ and 5 $. The total amount of money spent in this transaction is 1 + 3 + 5 + 10 + 6 + 5 = 30 $.
What is the output?
The output is a transaction database with utility information where all item ids in transactions are incremented by a user-defined value. For example, lets say that we choose the value "-1" for this example, which means that we want to decrease all the item identifiers by 1. The output is the following modified database:
| Items | Transaction utility | Item utilities for this transaction | |
| t1 | 3 5 1 2 4 6 | 30 | 1 3 5 10 6 5 |
| t2 | 3 5 2 4 | 20 | 3 3 8 6 |
| t3 | 3 1 4 | 8 | 1 5 2 |
Input file format
The input file format s 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.
For example, for the previous example, the input file is defined as follows:
4 6 2 3 5 7:30:1 3 5 10 6 5
4 6 3 5:20:3 3 8 6
4 2 5:8:1 5 2
Output file format
The output file format is the same as the input format. But the items identifiers are changed by adding the user specified value (in this example: "-1")
3 5 1 2 4 6:30:1 3 5 10 6 5
3 5 2 4:20:3 3 8 6
3 1 4:8:1 5 2