예제 #1
0
        //[Test]
        public void TestMethod1()
        {
            ItemsetCollection collection = new ItemsetCollection {
                list1, list2, list3, list4
            };
            ItemsetCollection L     = AprioriMining.Apriori(collection, 50);
            ItemsetCollection Check = GetItems();

            Assert.AreEqual(Check, L);
        }
예제 #2
0
        public void Apriori() //Test of Apriori for support = 50%
        {
            ItemsetCollection collection = new ItemsetCollection {
                list1, list2, list3, list4
            };
            ItemsetCollection L     = AprioriMining.Apriori(collection, 50);
            ItemsetCollection Check = GetItems();

            Assert.AreEqual(Check.Count, L.Count);               //Checking items count in itemsetcollection
            for (int k = 0; k < Check.Count; k++)                //Loop for all itmesets
            {
                Assert.AreEqual(Check[k].Support, L[k].Support); //Checking support of itemset
                Assert.AreEqual(Check[k].Count, L[k].Count);     // Checking number count of itmes in itemset
                Assert.AreEqual(Check[k].Sum(), L[k].Sum());     //Checking summary of all numbers in list
            }
        }
예제 #3
0
        public void Mine() //Test of minig asscociationrules for conffidence = 80
        {
            ItemsetCollection collection = new ItemsetCollection {
                list1, list2, list3, list4
            };
            ItemsetCollection      L        = AprioriMining.Apriori(collection, 50);
            List <AssociationRule> AllRules = AprioriMining.Mine(collection, L, 80);
            List <AssociationRule> Check    = GetRules();

            Assert.AreEqual(Check.Count, AllRules.Count);                     //Checking rules count in rules collection
            for (int k = 0; k < Check.Count; k++)                             //Loop for all rules
            {
                Assert.AreEqual(Check[k].Confidence, AllRules[k].Confidence); //Checking confidence of rule
                Assert.AreEqual(Check[k].X.Count, AllRules[k].X.Count);       // Checking numbers count of itmes in X
                Assert.AreEqual(Check[k].X.Sum(), AllRules[k].X.Sum());       //Checking summary of all numbers in X
                Assert.AreEqual(Check[k].Y.Count, AllRules[k].Y.Count);       // Checking numbers count of itmes in Y
                Assert.AreEqual(Check[k].Y.Sum(), AllRules[k].Y.Sum());       //Checking summary of all numbers in Y
            }
        }
예제 #4
0
        private void TestApriori()
        {
            ItemsetCollection collection = new ItemsetCollection {
                list1, list2, list3, list4
            };
            ItemsetCollection L     = AprioriMining.Apriori(collection, 50);
            ItemsetCollection Check = GetItems();
            Itemset           i     = new Itemset();

            i.Add(1);
            i.Support = 10;
            i.Tid     = 0;
            Itemset j = new Itemset();

            j.Add(1);
            j.Support = 10;
            j.Tid     = 0;

            Assert.AreEqual(Check[0].Sum(), j.ToList());
        }
예제 #5
0
        private void PopulateChart()
        {
            try
            {
                var     filmList  = db.Movies.ToList();
                Itemset myItemset = new Itemset();
                foreach (var i in filmList)
                {
                    myItemset.Add(i.MyMovieID);
                }

                ItemsetCollection myItemsetCollection = new ItemsetCollection();
                var MovieList = db.UserMovieLists.Select(u => u);
                foreach (var u in MovieList)
                {
                    var query = from a in db.Ratings
                                join b in db.UserMovieLists
                                on a.UserMovieLIstID equals b.UserMovieListID
                                into temp
                                from b in temp.DefaultIfEmpty()
                                where a.UserMovieLIstID == u.UserMovieListID
                                where a.UserRatingID >= 5
                                select new
                    {
                        a.MyMovieID,
                    };
                    Itemset tempItemset = new Itemset();
                    ;
                    if (myItemset != null)
                    {
                        if (query.Count() > 1)
                        {
                            foreach (var r in query.Take(25))
                            {
                                tempItemset.Add(r.MyMovieID);
                            }
                            myItemsetCollection.Add(tempItemset);
                        }
                    }
                }

                List <double> supportList = new List <double>();
                double        support1    = 30;
                double        support2    = 27.5;
                double        support3    = 25;
                double        support4    = 22.5;
                double        support5    = 20;
                supportList.Add(support5);
                supportList.Add(support4);
                supportList.Add(support3);
                supportList.Add(support2);
                supportList.Add(support1);

                foreach (var ele in supportList)
                {
                    int timeStart, timeStop, timeElapsed;
                    timeStart = Environment.TickCount;
                    ItemsetCollection L = AprioriMining.Apriori(myItemsetCollection, ele);
                    timeStop    = Environment.TickCount;
                    timeElapsed = (timeStop - timeStart) / 1000;
                    this.chart1.Series["Apriori"].Points.AddXY(ele, timeElapsed);
                }

                foreach (var ele in supportList)
                {
                    int timeStart, timeStop, timeElapsed;
                    timeStart = Environment.TickCount;
                    ItemsetCollection L = AprioriMining.AprioriTid(myItemsetCollection, ele);
                    timeStop    = Environment.TickCount;
                    timeElapsed = (timeStop - timeStart) / 1000;
                    this.chart1.Series["AprioriTid"].Points.AddXY(ele, timeElapsed);
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }
예제 #6
0
        private void AddRules()
        {
            try
            {
                var     filmList  = db.Movies.ToList();
                Itemset myItemset = new Itemset();
                foreach (var i in filmList)
                {
                    myItemset.Add(i.MyMovieID);
                }

                ItemsetCollection myItemsetCollection = new ItemsetCollection();
                var MovieList = db.UserMovieLists.Select(u => u);
                foreach (var u in MovieList)
                {
                    var query = from a in db.Ratings
                                join b in db.UserMovieLists
                                on a.UserMovieLIstID equals b.UserMovieListID
                                into temp
                                from b in temp.DefaultIfEmpty()
                                where a.UserMovieLIstID == u.UserMovieListID
                                where a.UserRatingID >= 5
                                select new
                    {
                        a.MyMovieID,
                    };
                    Itemset tempItemset = new Itemset();
                    ;
                    if (myItemset != null)
                    {
                        if (query.Count() > 1)
                        {
                            foreach (var r in query.Take(25))
                            {
                                tempItemset.Add(r.MyMovieID);
                            }
                            myItemsetCollection.Add(tempItemset);
                        }
                    }
                }

                ItemsetCollection      L        = AprioriMining.Apriori(myItemsetCollection, 20);
                List <AssociationRule> allRules = AprioriMining.Mine(myItemsetCollection, L, 20);

                var ruleX = db.RulesX.Select(x => x);
                db.RulesX.RemoveRange(ruleX);
                db.SaveChanges();
                var ruleY = db.RulesY.Select(x => x);
                db.RulesY.RemoveRange(ruleY);
                db.SaveChanges();
                var myRule = db.Rules.Select(x => x);
                db.Rules.RemoveRange(myRule);
                db.SaveChanges();
                var ruleXmovie = db.RuleXMovie.Select(x => x);
                db.RuleXMovie.RemoveRange(ruleXmovie);
                db.SaveChanges();
                var ruleYMovie = db.RuleYMovie.Select(x => x);
                db.RuleYMovie.RemoveRange(ruleYMovie);

                foreach (var r in allRules)
                {
                    var rule = new MyRule();
                    var X    = new RuleX();
                    var Y    = new RuleY();
                    db.RulesX.Add(X);
                    db.SaveChanges();
                    db.RulesY.Add(Y);
                    db.SaveChanges();
                    rule.Support   = r.Support;
                    rule.Confidene = r.Confidence;
                    rule.RuleXID   = X.RuleXID;
                    rule.RuleYID   = Y.RuleYID;
                    db.Rules.Add(rule);
                    db.SaveChanges();

                    foreach (var x in r.X)
                    {
                        var rm = new RuleXMyMovie();
                        rm.RuleX_RuleXID     = X.RuleXID;
                        rm.MyMovie_MyMovieID = x;
                        db.RuleXMovie.Add(rm);
                        db.SaveChanges();
                    }
                    foreach (var y in r.Y)
                    {
                        var rm = new RuleYMyMovie();
                        rm.RuleY_RuleYID     = Y.RuleYID;
                        rm.MyMovie_MyMovieID = y;
                        db.RuleYMovie.Add(rm);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.ToString());
            }
        }