Good morning guys, I have problem in C# coding where my scope is in data mining of association rules....below are description of my problem....can yours give me where my mistakes that should i fix it...i can find item support for 1-itemset but failed to find item support for k-itemset......i seek help from advance...
======================================================
46 31 9 25 12 45 33
25 12 28 36 38
25 12 9 36 38
12 9 36 25 28 34
36 9 12 16 25 28 44
12 25 28 16 21
11 36 25 12 45 44
46 25 12 9 16 28 44
28 17 32 44 12
31 44 32 28 9
--> this is a dataset that i ake it as my experiments
=====================================================
int size = -1;
string output = "";
string output1 = "";
string output2 = "";
string text = File.ReadAllText(@"C:\Users\ACER\Desktop\Apriori Demo\UCI
dataset\sample.txt"); //D:\PITA\projek\nursery.txt
size = text.Length;
string b;
b = text.Replace("\r\n", " ");
output += b;
string[] c = output.Split(' ');
List
cc.Sort();
var fr = cc.GroupBy(n => n).Select(n => new { Value = n.Key, Count =
n.Count() });
foreach (var f in fr)
{
string text2 = (string.Format("{0} : {1}/10 : {2}%", f.Value, f.Count,
(f.Count/f.Count)*100));
output1 += text2 + "\n" ;
}
richTextBox4.Text = output1;
--> this is c# coding for 1-itemset....and its work!!
=====================================================
Output:
11 : 1/10 : 100%
12 : 9/10 : 100%
16 : 3/10 : 100%
17 : 1/10 : 100%
21 : 1/10 : 100%
25 : 8/10 : 100%
28 : 7/10 : 100%
31 : 2/10 : 100%
32 : 2/10 : 100%
33 : 1/10 : 100%
34 : 1/10 : 100%
36 : 5/10 : 100%
38 : 2/10 : 100%
44 : 5/10 : 100%
45 : 2/10 : 100%
46 : 2/10 : 100%
9 : 6/10 : 100%
--> this is output for 1-itemset....
======================================================
below are combination itemset code where i can find what itemset combination but im stuck when to find it itemsupport for combination data
lbCombinations.Items.Clear();
int n = richTextBox4.Lines.Length;
int k = 2;
Combination c = new Combination(n, k);
string[] result = new string[k];
string output1 = "";
while (c != null)
{
result = c.ApplyTo(richTextBox7.Lines);
StringBuilder sb = new StringBuilder();
sb.Append("{ ");
for (int i = 0; i < result.Length; ++i)
{
List
ccc.Sort();
var fru = ccc.GroupBy(m => n).Select(m => new { Value = m.Key,
Count = m.Count(), Key = m.Key, Min = m.Min(), Max =
m.Max() });
foreach (var f in fru)
{
sb.AppendFormat("{0} ", result[i]);
}
}
sb.Append("}: ");
for (int i = 0; i < 1; ++i)
{
List
ccc.Sort();
var fru = ccc.GroupBy(m => m).Select(m => new { Value = m.Key,
Count = m.Count(), Key = m.Key, Min = m.Min(), Max =
m.Max() });
foreach(var f in fru)
{
sb.AppendFormat("{0}", f.Key);
}
}
lbCombinations.Items.Add(sb.ToString());
c = c.Successor();
}
======================================================
p/s: its successfully generated combination itemset but the item support i failed get it... :(
{11 12} : 11 12
{11 16} : 11 16
{11 17} : 11 17
{11 21} : 11 21
{11 25} : 11 25
{11 28} : 11 28
{11 31} : 11 31
{11 32} : 11 32
{11 34} : 11 34
{11 36} : 11 36
{11 38} : 11 38
....
....
....
{46 9 } : 46 9
=====================================================
where, its must produce output like this......
{11 12} : 1/10
{11 16} : 0/10
{11 17} : 0/10
{11 21} : 0/10
{11 25} : 1/10
{11 28} : 0/10
{11 31} : 0/10
{11 32} : 0/10
{11 34} : 0/10
{11 36} : 1/10
{11 38} : 0/10
....
....
....
{46 9 } : 2/10
======================================================
i hope guts can give me a way to solve this problem....thank you....sorry for any convenience...
brunda kPosted May 13, 2012, 6:47 AM
Combinations comb = new Combinations(c, 2);
foreach (var f in comb)
{
try
{
int MatchedCount = 0;
var fileContents = from line in File.ReadAllLines(@"E:\sample.txt")
where line.Contains(f[0].ToString()) & line.Contains(f[1].ToString())
select new { Line = line };
foreach (var item in fileContents)
{
MatchedCount++;
}
string sb1 = "{" + f[0].ToString() + " " + f[1].ToString() + "} : " + MatchedCount.ToString() + "/10";
lbCombinations.Items.Add(sb1.ToString());
}
catch (Exception ex) { }
}
paan coolPosted May 10, 2012, 6:58 AM
using
using
namespace
{
System;System.Text;CombinationsLibpublic class Combination{
{
private long n = 0;private long k = 0;private long[] data = null;public Combination(long n, long k)if (n < 0 || k < 0) // normally require n >= k}
throw new Exception("Negative parameter in constructor");this.n = n;this.k = k;this.data = new long[k];for (long i = 0; i < k; ++i)this.data[i] = i;// Combination(n,k)
public Combination(long n, long k, long[] a) // Combination from a[]{
}
if (k != a.Length)throw new Exception("Array length does not equal k");this.n = n;this.k = k;this.data = new long[k];for (long i = 0; i < a.Length; ++i)this.data[i] = a[i];if (!this.IsValid())throw new Exception("Bad value from array");// Combination(n,k,a){
public bool IsValid()if (this.data.Length != this.k)return false; // corrupted{
for (long i = 0; i < this.k; ++i)if (this.data[i] < 0 || this.data[i] > this.n - 1)return false; // value out of range
for (long j = i + 1; j < this.k; ++j)if (this.data[i] >= this.data[j])return false; // duplicate or not lexicographic}
}
return true;// IsValid(){
sb.Append(
sb.AppendFormat(
sb.Append(
}
public override string ToString()StringBuilder sb = new StringBuilder();"{ ");for (long i = 0; i < this.k; ++i)"{0} {1}", this.data[i], " ");"}");return sb.ToString();// ToString(){
ans.data[i] =
++ans.data[i];
ans.data[j + 1] = ans.data[j] + 1;
}
public Combination Successor()if (this.data.Length == 0 ||this.data[0] == this.n - this.k)return null;Combination ans = new Combination(this.n, this.k);long i;for (i = 0; i < this.k; ++i)this.data[i];for (i = this.k - 1; i > 0 && ans.data[i] == this.n - this.k + i; --i) ;for (long j = i; j < this.k - 1; ++j)return ans;// Successor(){
ans.data[i] = i;
}
public Combination First()Combination ans = new Combination(this.n, this.k);for (long i = 0; i < ans.k; ++i)return ans;// First(){
result[i] = strarr[
}
public string[] ApplyTo(string[] strarr)if (strarr.Length != this.n)throw new Exception("Array size not equal to Combination order in ApplyTo()");string[] result = new string[this.k];for (long i = 0; i < result.Length; ++i)this.data[i]];return result;// ApplyTo(){
public static long Choose(long n, long k)if (n < 0 || k < 0)throw new Exception("Invalid negative parameter in Choose()");if (n < k)return 0; // special case
if (n == k)return 1;long delta, iMax;if (k < n - k) // ex: Choose(100,3){
delta = n - k;
iMax = k;
}
else // ex: Choose(100,97){
delta = k;
iMax = n - k;
}
{
long ans = delta + 1;for (long i = 2; i <= iMax; ++i)checked { ans = (ans * (delta + i)) / i; } // Throws OverFlow Exception
//Console.WriteLine(" i = " + i + " n = " + n + " k = " + k + " delta = " + delta + " iMax = " + iMax + " ans = " + ans);}
}
return ans;// Choose()}
// class Combination}
// ns CombinationsLibbrunda kPosted May 10, 2012, 2:24 AM