Skip to content

Commit

Permalink
Merge pull request #30 from JaredSchwartz/Remove-LuxurySparse-dependency
Browse files Browse the repository at this point in the history
Remove LuxurySparse dependency
  • Loading branch information
JaredSchwartz authored Aug 4, 2024
2 parents 1aede5c + 99ade32 commit 1d8b60f
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 149 deletions.
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ version = "0.3.1"
[deps]
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
LuxurySparse = "d05aeea4-b7d4-55ac-b691-9e7fabb07ba2"
Mmap = "a63ad114-7e13-5084-954f-fe012c677804"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
DataFrames = "1"
LuxurySparse = "0.7"
Combinatorics = "1.0.2"
julia = "1.6.7"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Load data to create a Transactions object or alternatively convert an existing 1
```julia
data = load_transactions("retail.txt",' ')

data = transactions(df)
data = Transactions(df)
```

Generate association rules using _A Priori_ with 10% minimum support and a max rule length of 3.
Expand Down
62 changes: 3 additions & 59 deletions docs/src/transactions.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,14 @@
# Transactions Objects
## Transactions
```Julia
struct Transactions
matrix::SparseMatrixCSC{Bool,Int64}
colkeys::Dict{Int,String}
linekeys::Dict{Int,String}
end
```@docs
Transactions
```
The `Transactions` struct consists of three fields:
- `matrix`: Sparse matrix showing the locations of the items (columns) in the transactions(rows)
- `colkeys`: Dictionary mapping column indexes to their original values in the source
- `linekeys`: Dictionary mapping line indexes to their original values in the source (or generated index number)

## load_transactions
Note: this reads basket-format data, not tabular data!


```@docs
load_transactions(file::String, delimiter::Char; id_col::Bool = false, skiplines::Int = 0)
```

Reads transaction data from a file basket-format file, where each line is a list of items, and returns a Transactions object.


Parameters:

- `file`: Path to the input file
- `delimiter`: Character used to separate items in each transaction
- `id_col`: Set to true if the first item in each line is a transaction identifier (default: false)
- `skiplines`: Number of header lines to skip (optional)
- `nlines`:Number of lines to read (optional)

Returns:
- `Transactions`: A Transactions object with a sparse matrix representing the treansactions (rows) and items (columns) as well as dictionary keys for the names of the rows and columns

## transactions
```@docs
transactions(df::DataFrame;indexcol::Union{Symbol,Nothing}=nothing)
```
Converts a one-hot encoded DataFrame into a Transactions object.

Parameters:

- `df`: Input `DataFrame`
- `indexcol`: Column to use as the index (optional)

## txns\_to\_df
```@docs
txns_to_df(txns::Transactions; indexcol::Bool= false)
```
Parameters:
- `txns`: The `Transactions` object to be converted.
- `id_col`: If true, an additional 'Index' column is added to the DataFrame containing the values from the linekeys dictionary.

Returns
- `DataFrame`: A one-hot encoded DataFrame representation of the Transactions object.


Usage Examples

```julia
# Load transactions from a file
txns = load_transactions("transactions.txt", ' ', id_col=true, skiplines=1)

# Convert a DataFrame to Transactions
df = DataFrame(Index = [1,2,3], A=[1,0,1], B=[0,1,1], C=[1,1,0])

txns = transactions(df, indexcol=:Index)
```
```
2 changes: 1 addition & 1 deletion src/RuleMiner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

module RuleMiner

using DataFrames, LuxurySparse, Mmap, Base.Threads, SparseArrays, Combinatorics
using DataFrames, Mmap, Base.Threads, SparseArrays, Combinatorics

include("transactions.jl")
# Frequent Itemset Mining
Expand Down
Loading

0 comments on commit 1d8b60f

Please sign in to comment.