View a cost utility transaction database file with the transaction database Viewer (SPMF documentation)
Cost utility transaction databases are a type of data taken as input by data mining algorithms offered in SPMF such as LCIM.
SPMF offers a tool to view the content of a cost utility transaction database. This tool is called the SPMF cost utility transaction database viewer.
This page explains how to use this tool with an example.
How to run this example?
If you want to run this example from the graphical interface of SPMF, (1) choose the algorithm "Open_cost_utility_transaction_database_file_with_viewer", (2) choose the DB_cost.txt file as input, and then (3) click "run algorithm" .
- If you want to run this example from the source code of SPMF, run the file MainTestCostUtilityTransactionViewer, which is located in the package ca.pfv.spmf.tests
- If you want to execute this example from the command line interface of SPMF, then execute this command:
java -jar spmf.jar run Open_cost_utility_transaction_database_file_with_viewer DB_cost.txt
in a folder containing spmf.jar and the file DB_cost.txt which is included with SPMF.
What is displayed?
After running the example, the content of the file will be displayed by the tool. The picture below shows the user interface of this viewer.
The window A) show in the picture below is the main window. It displays the cost utility transaction database using a table. The table has four rows in this example. Each row (except the last one) is a transaction from the cost utility transaction database.
Imagine that each transaction represents the treatments (items) taken by a patient in a hospital.
Take the first row as example.
The cell in the first column indicates that the ID of this transaction is 0.
The cell in the second column indicates that this transaction 0 contains the item 1 and the cost was 5 $.
The cell in the third column indicates that this transaction 0 contains the item 2 and the cost was 10 $.
The cell in the fourth column indicates that this transaction 0 contains the item 3 and the cost was 1 $.
The cell in the fifth column indicates that this transaction 0 contains the item 4 and the cost was 6 $.
The cell in the sixth column indicates that this transaction 0 contains the item 5 and the cost was 3 $.
The cell in the fifth column indicates that this transaction 0 contains the item 6 and the cost was 5 $.
The cell in the sixth column indicates that this transaction 0 does not contain the item 7.
The cell in the seventh column indicates that the benefits (utility) obtained from this transaction is 40. This may
The other transactions follow the same format.
Then the last line of the table provides the sum of each column. For example, the cell in the last row and second column indicates that the total cost for item 1 in this database is 5 + 5 + 10 = 20 $.
This view as a table can be useful to understand the content of a cost utility transaction database file.
Besides, there are buttons that provides additional features:
- By clicking on the button "View transaction length distribution ", a new window is opened, presented as window B) in the picture below. This window displays the frequency histogram of the different transaction lengths in the current file. The number of transactions is the Y axis and the different transaction lengths are the X axis. There are some buttons in this window to export the data from the frequency histogram as a CSV file so that it can be imported in other software (e.g. Excel), or as a picture. Besides some options are provided to adjust the bar width and the order in which the X axis is sorted.
- By clicking on the button "View transaction utility distribution ", a new window is opened, presented as window C) in the picture below. This window displays the frequency histogram of the different transaction lengths in the current file in terms of utility.. The number of transactions is the Y axis and the different transaction utility values are the X axis. There are some buttons in this window to export the data from the frequency histogram as a CSV file so that it can be imported in other software (e.g. Excel), or as a picture. Besides some options are provided to adjust the bar width and the order in which the X axis is sorted.
What is the input?
The algorithm takes as input a cost utility transaction database in SPMF format, as used by algorithms such as LCIM.
The database used in this example is provided in the text file "DB_cost.txt" in the package ca.pfv.spmf.tests of the SPMF distribution.
The input file format of LCIM 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 cost of each item in this transaction (an integer), separated by single spaces.
For example, this is the content of the example file "DB_cost.txt":
3 5 1 2 4 6:40:1 3 5 10 6 5
3 5 2 4:20:3 3 8 6
3 1 4:18:1 5 2
3 5 1 7:37:6 6 10 5
3 5 2 7:21:2 3 4 2
Consider the first line. It means that the transaction {3, 5, 1, 2, 4, 6} has a total utility of 40 and that items 3, 5, 1, 2, 4 and 6 respectively have a cost of 1, 3, 5, 10, 6 and 5 in this transaction. The following lines follow the same format.