예제 #1
0
        private DataTable ReadDataSet(string path)
        {
            _logger.PrintMilestone("Started execution. Reading dataset.");
            var dataset = _fsHelper.GetDataSet(path, ";");

            _logger.PrintExecutionTime("Loaded dataset.");
            return(dataset);
        }
예제 #2
0
        static void Main(string[] args)
        {
            _logger   = Logger.GetInstance();
            _fsHelper = new FSHelper();
            _logger.PrintMilestone("Reading configuration...");
            string datasetPath             = ConfigurationManager.AppSettings.Get("path_dataset");
            string attributesPath          = ConfigurationManager.AppSettings.Get("path_attributes");
            string unused_consequents_path = ConfigurationManager.AppSettings.Get("path_unused");
            string itemsetPathFormat       = ConfigurationManager.AppSettings.Get("path_itemset_format");
            string rulesPathFormat         = ConfigurationManager.AppSettings.Get("path_rules_format");

            _logger.PrintMilestone("Configuration successfully read.");

            _miner = new Miner();

            _logger.PrintMilestone("Started execution. Reading dataset.");

            var dt = _fsHelper.GetDataSet(datasetPath, ";");

            _logger.PrintExecutionTime("Loaded dataset.");

            _logger.PrintMilestone("Reading attributes.");
            consequents = _fsHelper.LoadUnusedConsequents(unused_consequents_path);
            attributes  = _fsHelper.GetAttributesList(attributesPath, unused_consequents_path);

            foreach (DataRow tRow in dt.Rows)
            {
                foreach (var att in attributes)
                {
                    att.Add(tRow[att.Name].ToString(), tRow["id"].ToString());
                }
            }

            SaveAsFeatures(dt, @"E:\Data\featurebundle.txt");

            dt.Dispose();
            _logger.PrintExecutionTime("Attributes read.");
            Attribute.TotalElements = dt.Rows.Count;

            _logger.PrintMilestone("Starting to combine attributes...");
            _logger.BeginLap();

            // Get initial, 2-tier itemsets to build the rest on them.
            CombineAttributesAndValues(attributes.ToArray(), 0, attributes.Count - 1, 0, 2);
            _logger.PrintLap(string.Format("Generated {0}-tier itemsets ({1} entries).", 2, currentTierItemsets.Count));
            SubmitItemset();
            _fsHelper.SaveItemsets(lastTierItemsets, string.Format(itemsetPathFormat, 2));

            for (int i = 3; i < attributes.Count; i++)
            {
                foreach (Itemset itemset in lastTierItemsets)
                {
                    CombineAttributeWithItemset(itemset, attributes.ToArray());
                }
                SubmitItemset();
                if (lastTierItemsets.Count > 0)
                {
                    _logger.PrintLap(string.Format("Generated {0}-tier itemsets ({1} entries).", i, lastTierItemsets.Count));
                    _fsHelper.SaveItemsets(lastTierItemsets, string.Format(itemsetPathFormat, i));
                }
                else
                {
                    lastItemsetTier = i - 1;
                    _logger.PrintMilestone(string.Format("No itemsets found for Tier {0}. No further itemsets will be generated.", i));
                    break;
                }
            }
            _logger.PrintExecutionTime(string.Format("Generated itemsets, {0} entries total.", itemsets.Count));

            _logger.PrintMilestone("Starting rules generation...");
            _logger.BeginLap();
            for (var i = 2; i <= lastItemsetTier; i++)
            {
                var tier = _fsHelper.LoadItemsets(string.Format(itemsetPathFormat, i)).OrderBy(x => x.Support).ToArray();
                foreach (Itemset itemset in tier)
                {
                    BuildRules(itemset);
                }
                _logger.PrintLap(string.Format("Generated {0}-tier rules.", i));
            }
            _logger.PrintMilestone(string.Format("Ended rules generation. Total: {0} rules.", rules.Count()));
            var ordered = rules.OrderByDescending(x => x.confidence).ToArray();

            System.IO.File.WriteAllLines(string.Format(rulesPathFormat, MinSupport, MinConfidence), ordered.Select(x => x.ToString()));
        }