title: Data Mining issue with the apriori algorithm in C#
body: <p>I am creating my own implementation of the apriori algorithm in C#. For this project, i'm not allowed to use other libraries, etc. for the apriori algorithm.</p>
  
  <p>Below is my <code>testData.json</code>. Please note that these are strings, meaning my itemsets might not just be a character like <code>A</code>, but a word like <code>candy</code>.</p>
  
  <p><strong>NOTE:</strong> I will be using a <code>20</code> (20%) support while testing.</p>
  
  <pre><code>{
      "transactions": [
          [ "B", "C" ],
          [ "B", "C", "D" ],
          [ "A", "D" ],
          [ "A", "B", "C", "D" ],
          [ "C", "D" ],
          [ "C", "D", "E" ],
          [ "A", "B" ]
      ]
  }
  </code></pre>
  
  <p>When I click a button to process data along with my needed values, <code>minSupport</code> and <code>minConfidence</code> (not needed yet), I Deserialize my JSON into an Object and save it into a public variable called <code>database</code> Below is the Database class.</p>
  
  <pre><code>public class Database
  {
      public List&lt;List&lt;string&gt;&gt; transactions { get; set; }
  }
  </code></pre>
  
  <p>When the button is clicked, i call the method <code>GenerateCandidateItemSet()</code> <strong>This is where i am having a problem.</strong> :</p>
  
  <pre><code>private Dictionary&lt;string, int&gt; C1 = new Dictionary&lt;string, int&gt;();
  private void GenerateCandidateItemSet()
  {
      foreach (List&lt;string&gt; transaction in database.transactions)
      {
          foreach (string item in transaction)
          {
              if (C1.ContainsKey(item))
              {
                  C1[item]++;
              }
              else
              {
                  C1.Add(item, 1);
              }
          }
      }
  
      // Check our frequency, remove items with low support
      foreach (string key in C1.Keys.ToList())
      {
          double frequency = (C1[key] * 100) / (database.transactions.Count);
          if (frequency &lt; minSupport)
          {
              C1.Remove(key);
          }
      }
  
      // Pairing check stuff
      List&lt;string[]&gt; itemPairs = new List&lt;string[]&gt;();
      List&lt;string&gt; items = C1.Keys.ToList();
  
      foreach (string item in items)
      {
          // FIX THIS LOOP LATER TO CONTAIN ALL PAIRS
          List&lt;string&gt; itemArray = new List&lt;string&gt;();
          if (item != items.Last())
          {
              itemArray.Add(item);
              itemArray.Add(items[items.IndexOf(item) + 1]);
              itemPairs.Add(itemArray.ToArray());
          }
      }
      GenerateItemSetRecursive(itemPairs);
  }
  </code></pre>
  
  <p>Right before the section: <code>//Pairing check stuff</code> the value of <code>C1</code> is:</p>
  
  <p><img src="https://i.stack.imgur.com/TCXpD.png" alt="enter image description here"></p>
  
  <p>When the loop completes, I need to get something like:</p>
  
  <pre><code>BC, BD, BA, CD, CA, DA
  </code></pre>
  
  <p>And if I was to plug in <code>AB, AD, BC, BD, CD</code>, the result would be <code>ABD, BCD</code> and so on.</p>
  
  <p>Basically, I am needing to find the <code>Frequent Itemsets</code> for the transactions.</p>
  
  <p><strong>Question:</strong> Considering i'm only getting <code>BC, CD, DA</code> for my itemPairs, instead of <code>BC, BD, BA, CD, CA, DA</code> i know my logic is wrong. What would my loop look like to get this to work?</p>