Skip to main content
edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
added 113 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Optimizing Apriori algorithm - Python pandasusing Pandas

I want to optimize my Apriori algorithm for speed.:

>>> trans
        1  2    3    4
0                     
11      a  b    c  NaN
666     a  d    e  NaN
10101   b  c    d  NaN
1010    a  b    c    d
414147  b  c  NaN  NaN
10101   a  b    d  NaN
1242    d  e  NaN  NaN
101     a  b    c  NaN
411     c  d    e  NaN
444     a  b    c  NaN

[10 rows x 4 columns]
>>> trans
        1  2    3    4
0                     
11      a  b    c  NaN
666     a  d    e  NaN
10101   b  c    d  NaN
1010    a  b    c    d
414147  b  c  NaN  NaN
10101   a  b    d  NaN
1242    d  e  NaN  NaN
101     a  b    c  NaN
411     c  d    e  NaN
444     a  b    c  NaN

[10 rows x 4 columns]
Ap=apriori(trans)
print Ap
>>> 
   Pattern  Support
0        a      0.6
1        b      0.7
2        c      0.7
3        d      0.6
4        e      0.3
5      a,b      0.5
6      a,c      0.4
7      a,d      0.3
8      a,e      0.1
9      b,c      0.6
10     b,d      0.3
12     c,d      0.3
13     c,e      0.1
14     d,e      0.3
15   a,b,c      0.4
16   a,b,d      0.2
18   a,c,d      0.1
20   a,d,e      0.1
21   b,c,d      0.2
24   c,d,e      0.1
Ap=apriori(trans)
print Ap
>>> 
   Pattern  Support
0        a      0.6
1        b      0.7
2        c      0.7
3        d      0.6
4        e      0.3
5      a,b      0.5
6      a,c      0.4
7      a,d      0.3
8      a,e      0.1
9      b,c      0.6
10     b,d      0.3
12     c,d      0.3
13     c,e      0.1
14     d,e      0.3
15   a,b,c      0.4
16   a,b,d      0.2
18   a,c,d      0.1
20   a,d,e      0.1
21   b,c,d      0.2
24   c,d,e      0.1

I want to know if this can be optimized further so that it can run faster on large datasets. I also want to know if there a way to use purely pandasPandas without combinations from itertools.

Optimizing Apriori algorithm - Python pandas

I want to optimize my Apriori algorithm for speed.

>>> trans
        1  2    3    4
0                     
11      a  b    c  NaN
666     a  d    e  NaN
10101   b  c    d  NaN
1010    a  b    c    d
414147  b  c  NaN  NaN
10101   a  b    d  NaN
1242    d  e  NaN  NaN
101     a  b    c  NaN
411     c  d    e  NaN
444     a  b    c  NaN

[10 rows x 4 columns]
Ap=apriori(trans)
print Ap
>>> 
   Pattern  Support
0        a      0.6
1        b      0.7
2        c      0.7
3        d      0.6
4        e      0.3
5      a,b      0.5
6      a,c      0.4
7      a,d      0.3
8      a,e      0.1
9      b,c      0.6
10     b,d      0.3
12     c,d      0.3
13     c,e      0.1
14     d,e      0.3
15   a,b,c      0.4
16   a,b,d      0.2
18   a,c,d      0.1
20   a,d,e      0.1
21   b,c,d      0.2
24   c,d,e      0.1

I want to know if this can be optimized further so that it can run faster on large datasets. I also want to know if there a way to use purely pandas without combinations from itertools.

Apriori algorithm using Pandas

I want to optimize my Apriori algorithm for speed:

>>> trans
        1  2    3    4
0                     
11      a  b    c  NaN
666     a  d    e  NaN
10101   b  c    d  NaN
1010    a  b    c    d
414147  b  c  NaN  NaN
10101   a  b    d  NaN
1242    d  e  NaN  NaN
101     a  b    c  NaN
411     c  d    e  NaN
444     a  b    c  NaN

[10 rows x 4 columns]
Ap=apriori(trans)
print Ap
>>> 
   Pattern  Support
0        a      0.6
1        b      0.7
2        c      0.7
3        d      0.6
4        e      0.3
5      a,b      0.5
6      a,c      0.4
7      a,d      0.3
8      a,e      0.1
9      b,c      0.6
10     b,d      0.3
12     c,d      0.3
13     c,e      0.1
14     d,e      0.3
15   a,b,c      0.4
16   a,b,d      0.2
18   a,c,d      0.1
20   a,d,e      0.1
21   b,c,d      0.2
24   c,d,e      0.1

I want to know if this can be optimized further so that it can run faster on large datasets. I also want to know if there a way to use purely Pandas without combinations from itertools.

added 7 characters in body; edited tags; edited title; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Optomizing Optimizing Apriori Algorithm pythonalgorithm - Python pandas

As seen below:

When you input a dataframe of transactionsWhen you input a dataframe of transactions:

It will yield:It will yield:

I want to know if this can be optimized further so that it runscan run faster on large datasets and I is. I also want to know if there a way to use purely pandas without combinations from itertools.

Optomizing Apriori Algorithm python pandas

As seen below:

When you input a dataframe of transactions

It will yield:

I want to know if this can be optimized further so that it runs faster on large datasets and I is there a way to use purely pandas without combinations from itertools.

Optimizing Apriori algorithm - Python pandas

When you input a dataframe of transactions:

It will yield:

I want to know if this can be optimized further so that it can run faster on large datasets. I also want to know if there a way to use purely pandas without combinations from itertools.

Source Link
user3084006
  • 161
  • 1
  • 1
  • 4
Loading