示例#1
0
        static void CheckFeatureReordering(string dataPath)
        {
            var model = GetModel(dataPath, null);

            ModelSummary(model);

            Console.WriteLine("\nReordered");
            var reorderMapping = GetReorderMapping("reorder.csv");
            var reorderedModel = FeatureReorderer.ReorderXGBoost(model, reorderMapping);

            ModelSummary(reorderedModel);
        }
示例#2
0
        private static XGBoost GetModel(string dataPath, short[] reorderMapping)
        {
            var filename    = Path.Combine(dataPath, @"model_xbg_trees.txt");
            var treesString = File.ReadAllText(filename);
            var model       = XGBoost.Create(treesString);

            if (reorderMapping != null)
            {
                model = FeatureReorderer.ReorderXGBoost(model, reorderMapping);
            }
            return(model);
        }
示例#3
0
        static void DoFeatureReordering(string dataPath)
        {
            var model            = GetModel(dataPath, null);
            int numTrees         = model.Trees.Length;
            var timer            = new Timer(SaveBestFeatures, dataPath, 60_000, 60_000);
            var greedyReorderMap = FeatureReorderer.Greedy(model, numTrees);

            timer.Dispose();
            SaveBestFeatures(null);
            var allFeatureIndices = new HashSet <short>(greedyReorderMap);

            for (short i = 0; i < greedyReorderMap.Length; i++)
            {
                if (!allFeatureIndices.Contains(i))
                {
                    Console.WriteLine("The reorder mapping is not valid: not found index " + i);
                    break;
                }
            }
        }
        public void TestXGBoostEvaluateTimingReordered()
        {
            var filename1      = @"../../../../datasets/xgboost/reorder.csv";
            var reorderMapping = File.ReadAllLines(filename1)
                                 .Select(m => short.Parse(m))
                                 .ToArray();

            var filename    = @"../../../../datasets/xgboost/model_xbg_trees.txt";
            var treesString = File.ReadAllText(filename);
            var model       = XGBoost.Create(treesString);

            model = FeatureReorderer.ReorderXGBoost(model, reorderMapping);

            var filename2     = @"../../../../datasets/xgboost/xgboost_test_cases_no_feature_names.txt";
            var samplesString = File.ReadLines(filename2);
            var samples       = new Dictionary <string, float[]>();

            foreach (var line in samplesString.Skip(1))
            {
                var parts        = line.Split(',');
                var sample       = parts[0];
                var featureIndex = int.Parse(parts[1]);
                if (featureIndex >= 0 && featureIndex < reorderMapping.Length)
                {
                    featureIndex = reorderMapping[featureIndex];
                }
                var value = float.Parse(parts[2]);
                if (!samples.ContainsKey(sample))
                {
                    samples.Add(sample, new float[1000]);
                }
                samples[sample][featureIndex] = value;
            }

            DoXGBoostEvaluateTimingFlat(model, samples);
        }