Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

association_rules() missing 1 required positional argument: 'num_itemsets' #1112

Open
AnAccountWithoutAName opened this issue Nov 6, 2024 · 4 comments
Labels

Comments

@AnAccountWithoutAName
Copy link

Hi,
I tried using the assosciative_rules() function for a project of mine and noticed that I was getting the following error:
TypeError: association_rules() missing 1 required positional argument: 'num_itemsets'
I suspect that this is an oversight in the source code as the previous release didn't have this bug. I hope that this would be addressed and patched.

Code to reproduce the bug

The example code from the User Guide of the association_rules() function can be used to reproduce this bug.
https://rasbt.github.io/mlxtend/user_guide/frequent_patterns/association_rules/

import pandas as pd
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori, fpmax, fpgrowth


dataset = [['Milk', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],
           ['Dill', 'Onion', 'Nutmeg', 'Kidney Beans', 'Eggs', 'Yogurt'],
           ['Milk', 'Apple', 'Kidney Beans', 'Eggs'],
           ['Milk', 'Unicorn', 'Corn', 'Kidney Beans', 'Yogurt'],
           ['Corn', 'Onion', 'Onion', 'Kidney Beans', 'Ice cream', 'Eggs']]

te = TransactionEncoder()
te_ary = te.fit(dataset).transform(dataset)
df = pd.DataFrame(te_ary, columns=te.columns_)

frequent_itemsets = fpgrowth(df, min_support=0.6, use_colnames=True)
### alternatively:
#frequent_itemsets = apriori(df, min_support=0.6, use_colnames=True)
#frequent_itemsets = fpmax(df, min_support=0.6, use_colnames=True)



from mlxtend.frequent_patterns import association_rules

association_rules(frequent_itemsets, metric="confidence", min_threshold=0.7)

Expected Results

image
Results from the User Guide of the association_rules() function.

Actual Results

Traceback (most recent call last):
File "c:\Users\siddh\OneDrive\Desktop\bug-report.py", line 25, in
association_rules(frequent_itemsets, metric="confidence", min_threshold=0.7)
TypeError: association_rules() missing 1 required positional argument: 'num_itemsets'

Versions

MLxtend 0.23.2
Windows-10-10.0.22631-SP0
Python 3.11.8 | packaged by Anaconda, Inc. | (main, Feb 26 2024, 21:34:05) [MSC v.1916 64 bit (AMD64)]
Scikit-learn 1.5.2
NumPy 1.26.4
SciPy 1.11.4

@stubborncake
Copy link

I see, you can return your mlxtend's version to 0.23.1

pip install mlxtend==0.23.1

@Srinivaskoruprolu007
Copy link

I think you can try giving the total number of rows to the params in the place of 'num_itemsets'

@soconnor00
Copy link

soconnor00 commented Dec 27, 2024

The num_itemsets argument either used to be optional or used to not exist, hence the example code not including it. So I'd bet that this is a bug.

If this was intentional, I'm confused as to why this argument is required. It seems to me like the desired value of num_itemsets is going to be equal to the length of the frequent_itemsets argument in the vast majority of cases, so I think this argument should be optional and set to len(frequent_itemsets) if not provided.

This would be one line of code, so I might just make a PR for it.

@soconnor00
Copy link

Upon looking at the PR this argument was added in, I'm not entirely sure why the num_itemsets argument exists or what it even is.

It's somewhat ambiguous as to whether it represents the length of the df or df_orig arguments, and either way it seems that its value could be derived from its corresponding DataFrame (whichever one it is).

Reading the PR also made me realize that I'm way out of my depth here, so I'll leave the creation of a new PR to someone more familiar with the codebase and the underlying math.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants