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); }
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); }
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); }