How to automate mlxtend apriori algorithm to iterate over multiple datasets (Python) Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsIs FPGrowth still considered “state of the art” in frequent pattern mining?Question about (Python/Orange) Apriori associative algorithmWords to numbers faster lookupRun Apriori algorithm in python 2.7Same TF-IDF Vectorizer for 2 data inputsGetting count of frequent itemsets in Python mlxtendCombine Pandas DataFrames with year columnsMultivariate VAR model: ValueError: x already contains a constantDetermining the correlations between aggregated data and non aggregated dataIs the Apriori algorithm suitable for database tuples?

How to market an anarchic city as a tourism spot to people living in civilized areas?

How can players take actions together that are impossible otherwise?

Need a suitable toxic chemical for a murder plot in my novel

Active filter with series inductor and resistor - do these exist?

Simulating Exploding Dice

Why is there no army of Iron-Mans in the MCU?

How can I make names more distinctive without making them longer?

Problem when applying foreach loop

Notation for two qubit composite product state

How do I keep my slimes from escaping their pens?

Blender game recording at the wrong time

Can a monk deflect thrown melee weapons?

What are the performance impacts of 'functional' Rust?

Biased dice probability question

How to stop my camera from exagerrating differences in skin colour?

How do I automatically answer y in bash script?

What can I do if my MacBook isn’t charging but already ran out?

Single author papers against my advisor's will?

Why is "Captain Marvel" translated as male in Portugal?

Who can trigger ship-wide alerts in Star Trek?

Unable to start mainnet node docker container

What to do with post with dry rot?

What computer would be fastest for Mathematica Home Edition?

How do you clear the ApexPages.getMessages() collection in a test?



How to automate mlxtend apriori algorithm to iterate over multiple datasets (Python)



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsIs FPGrowth still considered “state of the art” in frequent pattern mining?Question about (Python/Orange) Apriori associative algorithmWords to numbers faster lookupRun Apriori algorithm in python 2.7Same TF-IDF Vectorizer for 2 data inputsGetting count of frequent itemsets in Python mlxtendCombine Pandas DataFrames with year columnsMultivariate VAR model: ValueError: x already contains a constantDetermining the correlations between aggregated data and non aggregated dataIs the Apriori algorithm suitable for database tuples?










0












$begingroup$


I'm using mlxtends apriori algorithm on transactional data, which works like a charm. My simple script looks like the following:



dataset = #some dataset

## Transform/prep dataset into list data
dataset_tx = dataset.groupby(['ReceiptCode'])['ItemCategoryName'].apply(list).values.tolist()

## Define classifier
te = TransactionEncoder()

## Binary-transform dataset
te_ary = te.fit(dataset_tx).transform(dataset_tx)

## Fit to new dataframe (sparse dataframe)
df = pd.SparseDataFrame(te_ary, columns=te.columns_)
frequent_itemsets = apriori(df, min_support=0.009, use_colnames=True)


and my dataset looks like this:



+----------------------+--+------------------+--+------------------+
| ReceiptCode | | ItemCategoryName | | StoreCountryName |
+----------------------+--+------------------+--+------------------+
| 0000P70322000031467 | | Food | | Denmark |
| 0000P70322000031867 | | Food | | Denmark |
| 0000P70322000051467 | | Interior | | Germany |
| 0000P70322000087468 | | Kitchen | | Switzerland |
| 0000P70322000031469 | | Leisure | | Germany |
| 0000P70322000031439 | | Food | | Switzerland |
+----------------------+--+------------------+--+------------------+


Now I would like to perform the same analysis but distinguished by the various countries (StoreCountryName in my dataframe). I know I can repeat the above code for each country, and name the variables accordingly, i.e. df_Denmark, df_Germany, etc.
However, I would like to automate this using a loop, a function or something else.



The wanted output would be a list of frequent itemsets for each country, or something similar. I just need to be able to distinguish between the outputs, but I have no idea how to achieve this.










share|improve this question









$endgroup$
















    0












    $begingroup$


    I'm using mlxtends apriori algorithm on transactional data, which works like a charm. My simple script looks like the following:



    dataset = #some dataset

    ## Transform/prep dataset into list data
    dataset_tx = dataset.groupby(['ReceiptCode'])['ItemCategoryName'].apply(list).values.tolist()

    ## Define classifier
    te = TransactionEncoder()

    ## Binary-transform dataset
    te_ary = te.fit(dataset_tx).transform(dataset_tx)

    ## Fit to new dataframe (sparse dataframe)
    df = pd.SparseDataFrame(te_ary, columns=te.columns_)
    frequent_itemsets = apriori(df, min_support=0.009, use_colnames=True)


    and my dataset looks like this:



    +----------------------+--+------------------+--+------------------+
    | ReceiptCode | | ItemCategoryName | | StoreCountryName |
    +----------------------+--+------------------+--+------------------+
    | 0000P70322000031467 | | Food | | Denmark |
    | 0000P70322000031867 | | Food | | Denmark |
    | 0000P70322000051467 | | Interior | | Germany |
    | 0000P70322000087468 | | Kitchen | | Switzerland |
    | 0000P70322000031469 | | Leisure | | Germany |
    | 0000P70322000031439 | | Food | | Switzerland |
    +----------------------+--+------------------+--+------------------+


    Now I would like to perform the same analysis but distinguished by the various countries (StoreCountryName in my dataframe). I know I can repeat the above code for each country, and name the variables accordingly, i.e. df_Denmark, df_Germany, etc.
    However, I would like to automate this using a loop, a function or something else.



    The wanted output would be a list of frequent itemsets for each country, or something similar. I just need to be able to distinguish between the outputs, but I have no idea how to achieve this.










    share|improve this question









    $endgroup$














      0












      0








      0





      $begingroup$


      I'm using mlxtends apriori algorithm on transactional data, which works like a charm. My simple script looks like the following:



      dataset = #some dataset

      ## Transform/prep dataset into list data
      dataset_tx = dataset.groupby(['ReceiptCode'])['ItemCategoryName'].apply(list).values.tolist()

      ## Define classifier
      te = TransactionEncoder()

      ## Binary-transform dataset
      te_ary = te.fit(dataset_tx).transform(dataset_tx)

      ## Fit to new dataframe (sparse dataframe)
      df = pd.SparseDataFrame(te_ary, columns=te.columns_)
      frequent_itemsets = apriori(df, min_support=0.009, use_colnames=True)


      and my dataset looks like this:



      +----------------------+--+------------------+--+------------------+
      | ReceiptCode | | ItemCategoryName | | StoreCountryName |
      +----------------------+--+------------------+--+------------------+
      | 0000P70322000031467 | | Food | | Denmark |
      | 0000P70322000031867 | | Food | | Denmark |
      | 0000P70322000051467 | | Interior | | Germany |
      | 0000P70322000087468 | | Kitchen | | Switzerland |
      | 0000P70322000031469 | | Leisure | | Germany |
      | 0000P70322000031439 | | Food | | Switzerland |
      +----------------------+--+------------------+--+------------------+


      Now I would like to perform the same analysis but distinguished by the various countries (StoreCountryName in my dataframe). I know I can repeat the above code for each country, and name the variables accordingly, i.e. df_Denmark, df_Germany, etc.
      However, I would like to automate this using a loop, a function or something else.



      The wanted output would be a list of frequent itemsets for each country, or something similar. I just need to be able to distinguish between the outputs, but I have no idea how to achieve this.










      share|improve this question









      $endgroup$




      I'm using mlxtends apriori algorithm on transactional data, which works like a charm. My simple script looks like the following:



      dataset = #some dataset

      ## Transform/prep dataset into list data
      dataset_tx = dataset.groupby(['ReceiptCode'])['ItemCategoryName'].apply(list).values.tolist()

      ## Define classifier
      te = TransactionEncoder()

      ## Binary-transform dataset
      te_ary = te.fit(dataset_tx).transform(dataset_tx)

      ## Fit to new dataframe (sparse dataframe)
      df = pd.SparseDataFrame(te_ary, columns=te.columns_)
      frequent_itemsets = apriori(df, min_support=0.009, use_colnames=True)


      and my dataset looks like this:



      +----------------------+--+------------------+--+------------------+
      | ReceiptCode | | ItemCategoryName | | StoreCountryName |
      +----------------------+--+------------------+--+------------------+
      | 0000P70322000031467 | | Food | | Denmark |
      | 0000P70322000031867 | | Food | | Denmark |
      | 0000P70322000051467 | | Interior | | Germany |
      | 0000P70322000087468 | | Kitchen | | Switzerland |
      | 0000P70322000031469 | | Leisure | | Germany |
      | 0000P70322000031439 | | Food | | Switzerland |
      +----------------------+--+------------------+--+------------------+


      Now I would like to perform the same analysis but distinguished by the various countries (StoreCountryName in my dataframe). I know I can repeat the above code for each country, and name the variables accordingly, i.e. df_Denmark, df_Germany, etc.
      However, I would like to automate this using a loop, a function or something else.



      The wanted output would be a list of frequent itemsets for each country, or something similar. I just need to be able to distinguish between the outputs, but I have no idea how to achieve this.







      python data-mining






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 2 at 7:40









      ArtemArtem

      12




      12




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48415%2fhow-to-automate-mlxtend-apriori-algorithm-to-iterate-over-multiple-datasets-pyt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48415%2fhow-to-automate-mlxtend-apriori-algorithm-to-iterate-over-multiple-datasets-pyt%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

          Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?