Apriori Report

Embed Size (px)

Citation preview

  • 8/8/2019 Apriori Report

    1/17

    Apriori Algorithm Report

    Report of Apriori algorithm Developed by :

    Dave Yogesh D. (07IT07 (07))

    Panchal Bhargav D. (07IT21 (20))Pambhar Sagar M. (07IT19 (18))

    Patel Chintan J. (07IT26)Patel Prayag . (07IT35)

    Patel Jaimin D. (07It29 (28))Seheju Vineet.(07IT51 (50))

    Patel Sandeep G. (07It38(37))

    Panchal Milan.(07IT22(21))

    Kapdiya Deep.(07IT11)

  • 8/8/2019 Apriori Report

    2/17

    Apriori Algorithm Report

    Program.cs

    using System;

    using System.Collections.Generic;

    using System.Text;

    using System.Collections;

    class Program

    {

    static void Main11()

    {

    DateTime dt;

    dt = DateTime.Now;

    //TimeSpan start = dt.TimeOfDay;

    Console.WriteLine(dt);

    //string file = @"c:\test1.csv";

    string sup = "2";

    string com = "0";

    double support = double.Parse(sup);

    double comf = double.Parse(com);

    CSVReader cr = new CSVReader();

    ItemSet data = cr.Read();

    Console.WriteLine(r.Count);

    Program p = new Program();

    ItemSet a= p.apriori( data, support,comf);

    for (int i = 0; i < a.Count;i++ )

    {

    ItemSet cur = (ItemSet)a[i];

    for (int j = 0; j < cur.Count; j++) {ItemSet now = (ItemSet)cur[j];

    foreach (DataItem item in now)

    {

    Console.Write( " "+ item.Id + ":" +

    item.ItemName+" ");

    }

    Console.WriteLine(" "+now.ICount);

    }

    }// TimeSpan end = dt.TimeOfDay;

    DateTime dt1 = DateTime.Now;

    Console.WriteLine(dt1);

    //TimeSpan final = end - start;

    //Console.WriteLine(final);

    Console.Read();

    }

  • 8/8/2019 Apriori Report

    3/17

    Apriori Algorithm Report

    private ItemSet FindOneColSet(ItemSet data, double

    support,double comf)

    {

    ItemSet cur=null;

    ItemSet result = new ItemSet();

    ItemSet set=null;

    ItemSet newset=null;

    DataItem cd=null;

    DataItem td=null;

    bool flag = true;

    for (int i = 0; i < data.Count; i++) {

    cur = (ItemSet)data[i];

    for (int j = 0; j < cur.Count; j++) {

    cd = (DataItem)cur[j];

    for (int n = 0; n < result.Count; n++) {

    set = (ItemSet)result[n];

    td= (DataItem)set[0];

    if (cd.Id == td.Id)

    {

    set.ICount++;

    flag = false;

    break;

    }

    flag=true;

    }

    if (flag) {

    newset = new ItemSet();

    newset.Add(cd);

    result.Add(newset);

    newset.ICount = 1;

    }

    }

    }

    ItemSet finalResult = new ItemSet();

    for (int i = 0; i < result.Count; i++){

    ItemSet con = (ItemSet)result[i];

    if (con.ICount >= support && con.ICount>=comf)

    {

    finalResult.Add(con);

    }

  • 8/8/2019 Apriori Report

    4/17

    Apriori Algorithm Report

    }

    //finalResult.Sort();

    return finalResult;

    }

    private ItemSet apriori(ItemSet data, double support,double

    comf)

    {

    ItemSet result = new ItemSet();

    ItemSet li = new ItemSet();

    ItemSet conList = new ItemSet();

    ItemSet subConList = new ItemSet();

    ItemSet subDataList = new ItemSet();

    int k = 2;

    li.Add( new ItemSet());

    li.Add(this.FindOneColSet(data, support,comf));

    while (((ItemSet)li[k-1]).Count != 0)

    {

    conList = AprioriGenerate((ItemSet)li[k - 1],k-1,

    support);

    for (int i = 0; i < data.Count; i++)

    {

    subDataList = SubSet((ItemSet)data[i], k);

    for (int j = 0; j < subDataList.Count; j++)

    {

    for (int n = 0; n < conList.Count; n++){

    ((ItemSet)subDataList[j]).Sort();

    ((ItemSet)conList[n]).Sort();

    if

    (((ItemSet)subDataList[j]).Equals(conList[n]))

    {

    ((ItemSet)conList[n]).ICount++;

    }

    }

    }

    }

    li.Add(new ItemSet());

    for (int i = 0; i < conList.Count; i++)

    {

    ItemSet con = (ItemSet)conList[i];

    if (con.ICount >= support)

    {

  • 8/8/2019 Apriori Report

    5/17

    Apriori Algorithm Report

    ((ItemSet)li[k]).Add(con);

    }

    }

    k++;

    }

    for (int i = 0; i < li.Count; i++)

    {

    result.Add(li[i]);

    }

    return result;

    }

    private ItemSet AprioriGenerate(ItemSet li,int k, double

    support)

    {

    ItemSet curList = null;

    ItemSet durList = null;

    ItemSet candi = null;

    ItemSet result = new ItemSet();

    for (int i = 0; i < li.Count; i++)

    {

    for (int j = 0; j < li.Count; j++){

    bool flag = true ;

    curList = (ItemSet)li[i];

    durList = (ItemSet)li[j];

    for (int n = 2; n < k; n++)

    {

    if (((DataItem)curList[n - 2]).Id ==

    ((DataItem)durList[n - 2]).Id)

    {

    flag = true;

    }

    else {

    break;

    flag = false;

    }

  • 8/8/2019 Apriori Report

    6/17

    Apriori Algorithm Report

    }

    if (flag && ((DataItem)curList[k - 1] ).Id 0)

    {

    colSet.Add(new DataItem(y, head[y -

    1]));

    }

    }

    rowSet.Add(colSet);

    }

    return rowSet;

    }}

  • 8/8/2019 Apriori Report

    13/17

    Apri ri Algorith R port

    y Follow the below mentioned details indicates how Aprioriworks.

  • 8/8/2019 Apriori Report

    14/17

    Apriori Algorith R port

  • 8/8/2019 Apriori Report

    15/17

    Apriori Algorith R port

  • 8/8/2019 Apriori Report

    16/17

    Apriori Algorith R port

  • 8/8/2019 Apriori Report

    17/17

    Apriori Algorith R port