├── .gitattributes
├── .gitignore
├── LICENSE.md
├── README.md
├── XgbFeatureInteractions.sln
├── XgbFeatureInteractions
├── App.config
├── FIScoreComparer.cs
├── FeatureInteraction.cs
├── FeatureInteractions.cs
├── FeatureScoreComparer.cs
├── GlobalSettings.cs
├── GlobalStats.cs
├── Program.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── SplitValueHistogram.cs
├── XgbFeatureInteractions.csproj
├── XgbModel.cs
├── XgbModelParser.cs
├── XgbTree.cs
├── XgbTreeNode.cs
└── packages.config
├── bin
├── XgbFeatureInteractions.exe
├── XgbFeatureInteractions.exe.config
└── lib
│ ├── EPPlus.dll
│ └── NGenerics.dll
├── doc
├── ScoresExample.png
└── ScoresExample_small.png
└── xgbfi_cc
├── xgbfi.cc
└── xgbfi.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 |
44 | # Build results
45 |
46 | [Dd]ebug/
47 | [Rr]elease/
48 | x64/
49 | build/
50 | [Bb]in/
51 | [Oo]bj/
52 |
53 | # MSTest test Results
54 | [Tt]est[Rr]esult*/
55 | [Bb]uild[Ll]og.*
56 |
57 | *_i.c
58 | *_p.c
59 | *.ilk
60 | *.meta
61 | *.obj
62 | *.pch
63 | *.pdb
64 | *.pgc
65 | *.pgd
66 | *.rsp
67 | *.sbr
68 | *.tlb
69 | *.tli
70 | *.tlh
71 | *.tmp
72 | *.tmp_proj
73 | *.log
74 | *.vspscc
75 | *.vssscc
76 | .builds
77 | *.pidb
78 | *.log
79 | *.scc
80 |
81 | # Visual C++ cache files
82 | ipch/
83 | *.aps
84 | *.ncb
85 | *.opensdf
86 | *.sdf
87 | *.cachefile
88 |
89 | # Visual Studio profiler
90 | *.psess
91 | *.vsp
92 | *.vspx
93 |
94 | # Guidance Automation Toolkit
95 | *.gpState
96 |
97 | # ReSharper is a .NET coding add-in
98 | _ReSharper*/
99 | *.[Rr]e[Ss]harper
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | *.ncrunch*
109 | .*crunch*.local.xml
110 |
111 | # Installshield output folder
112 | [Ee]xpress/
113 |
114 | # DocProject is a documentation generator add-in
115 | DocProject/buildhelp/
116 | DocProject/Help/*.HxT
117 | DocProject/Help/*.HxC
118 | DocProject/Help/*.hhc
119 | DocProject/Help/*.hhk
120 | DocProject/Help/*.hhp
121 | DocProject/Help/Html2
122 | DocProject/Help/html
123 |
124 | # Click-Once directory
125 | publish/
126 |
127 | # Publish Web Output
128 | *.Publish.xml
129 | *.pubxml
130 | *.publishproj
131 |
132 | # NuGet Packages Directory
133 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
134 | #packages/
135 |
136 | # Windows Azure Build Output
137 | csx
138 | *.build.csdef
139 |
140 | # Windows Store app package directory
141 | AppPackages/
142 |
143 | # Others
144 | sql/
145 | *.Cache
146 | ClientBin/
147 | [Ss]tyle[Cc]op.*
148 | ~$*
149 | *~
150 | *.dbmdl
151 | *.[Pp]ublish.xml
152 | *.pfx
153 | *.publishsettings
154 |
155 | # RIA/Silverlight projects
156 | Generated_Code/
157 |
158 | # Backup & report files from converting an old project file to a newer
159 | # Visual Studio version. Backup files are not needed, because we have git ;-)
160 | _UpgradeReport_Files/
161 | Backup*/
162 | UpgradeLog*.XML
163 | UpgradeLog*.htm
164 |
165 | # SQL Server files
166 | App_Data/*.mdf
167 | App_Data/*.ldf
168 |
169 | #############
170 | ## Windows detritus
171 | #############
172 |
173 | # Windows image file caches
174 | Thumbs.db
175 | ehthumbs.db
176 |
177 | # Folder config file
178 | Desktop.ini
179 |
180 | # Recycle Bin used on file shares
181 | $RECYCLE.BIN/
182 |
183 | # Mac crap
184 | .DS_Store
185 |
186 |
187 | #############
188 | ## Python
189 | #############
190 |
191 | *.py[cod]
192 |
193 | # Packages
194 | *.egg
195 | *.egg-info
196 | dist/
197 | build/
198 | eggs/
199 | parts/
200 | var/
201 | sdist/
202 | develop-eggs/
203 | .installed.cfg
204 |
205 | # Installer logs
206 | pip-log.txt
207 |
208 | # Unit test / coverage reports
209 | .coverage
210 | .tox
211 |
212 | #Translations
213 | *.mo
214 |
215 | #Mr Developer
216 | .mr.developer.cfg
217 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Xgbfi
2 | XGBoost Feature Interactions & Importance
3 |
4 | ### What is Xgbfi?
5 | Xgbfi is a [XGBoost](https://github.com/dmlc/xgboost) model dump parser, which ranks features as well as feature interactions by different metrics.
6 |
7 | ### Siblings
8 | [Xgbfir](https://github.com/limexp/xgbfir) - Python porting
9 |
10 | ### The Metrics
11 | * **Gain**: Total gain of each feature or feature interaction
12 | * **FScore**: Amount of possible splits taken on a feature or feature interaction
13 | * **wFScore**: Amount of possible splits taken on a feature or feature interaction weighted by the probability of the splits to take place
14 | * **Average wFScore**: *wFScore* divided by *FScore*
15 | * **Average Gain**: *Gain* divided by *FScore*
16 | * **Expected Gain**: Total gain of each feature or feature interaction weighted by the probability to gather the gain
17 | * **Average Tree Index**
18 | * **Average Tree Depth**
19 |
20 | ### Additional Features
21 | * **Leaf Statistics**
22 | * **Split Value Histograms**
23 |
24 | **Example:**
25 |
26 | 
27 |
28 | ### Usage
29 | *[mono] XgbFeatureInteractions.exe [-help|options]*
30 |
31 | ### Quick Guide
32 | a) Creating a feature map (fmap)
33 | ```python
34 | def create_feature_map(fmap_filename, features):
35 | """
36 | features: enumerable of feature names
37 | """
38 | outfile = open(fmap_filename, 'w')
39 | for i, feat in enumerate(features):
40 | outfile.write('{0}\t{1}\tq\n'.format(i, feat))
41 | outfile.close()
42 |
43 | create_feature_map('xgb.fmap', features)
44 | ```
45 |
46 | b) Dumping a [XGBoost](https://github.com/dmlc/xgboost) model
47 | ```python
48 | gbdt.dump_model('xgb.dump',fmap='xgb.fmap', with_stats=True)
49 | ```
50 |
51 | c) Editing Parameters in *XgbFeatureInteractions.exe.config*
52 | ```xml
53 |
54 | xgb.dump
55 |
56 | ```
57 |
58 | d) Running *[mono] XgbFeatureInteractions.exe* without cmd line parameters
59 |
--------------------------------------------------------------------------------
/XgbFeatureInteractions.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XgbFeatureInteractions", "XgbFeatureInteractions\XgbFeatureInteractions.csproj", "{09B47150-EEB5-4416-8D9A-7258CB0C717B}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {09B47150-EEB5-4416-8D9A-7258CB0C717B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {09B47150-EEB5-4416-8D9A-7258CB0C717B}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {09B47150-EEB5-4416-8D9A-7258CB0C717B}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {09B47150-EEB5-4416-8D9A-7258CB0C717B}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/XgbFeatureInteractions/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | xgb.model
20 |
21 |
22 | XgbFeatureInteractions.xlsx
23 |
24 |
25 | 100
26 |
27 |
28 | -1
29 |
30 |
31 | Gain
32 |
33 |
34 | -1
35 |
36 |
37 | 2
38 |
39 |
40 | 10
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/XgbFeatureInteractions/FIScoreComparer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace XgbFeatureInteractions
8 | {
9 |
10 | public enum SortingMetric
11 | {
12 | Gain,
13 | FScore,
14 | FScoreWeighted,
15 | AverageFScoreWeighted,
16 | AverageGain,
17 | ExpectedGain
18 | }
19 |
20 | static class FIScoreComparer
21 | {
22 | private static Func _comparer { set; get; }
23 | public static SortingMetric SortBy { private set; get; }
24 |
25 | public static void SetComparer(string sortBy)
26 | {
27 | sortBy = sortBy.ToLower().Replace(" ", "");
28 | if(sortBy == "gain")
29 | {
30 | SetComparer(SortingMetric.Gain);
31 | return;
32 | }
33 |
34 | if (sortBy == "fscore")
35 | {
36 | SetComparer(SortingMetric.FScore);
37 | return;
38 | }
39 |
40 | if (sortBy == "wfscore")
41 | {
42 | SetComparer(SortingMetric.FScoreWeighted);
43 | return;
44 | }
45 |
46 | if (sortBy == "avgwfscore")
47 | {
48 | SetComparer(SortingMetric.AverageFScoreWeighted);
49 | return;
50 | }
51 |
52 | if (sortBy == "avggain")
53 | {
54 | SetComparer(SortingMetric.AverageGain);
55 | return;
56 | }
57 |
58 | if (sortBy == "expgain")
59 | {
60 | SetComparer(SortingMetric.ExpectedGain);
61 | return;
62 | }
63 | }
64 |
65 | public static void SetComparer(SortingMetric sortingMetric)
66 | {
67 | switch(sortingMetric)
68 | {
69 |
70 | case SortingMetric.Gain:
71 | default:
72 | SortBy = SortingMetric.Gain;
73 | _comparer = (a, b) =>
74 | {
75 | return -a.Gain.CompareTo(b.Gain);
76 | };
77 | break;
78 | case SortingMetric.FScore:
79 | SortBy = SortingMetric.FScore;
80 | _comparer = (a, b) =>
81 | {
82 | return -a.FScore.CompareTo(b.FScore);
83 | };
84 | break;
85 | case SortingMetric.FScoreWeighted:
86 | SortBy = SortingMetric.FScoreWeighted;
87 | _comparer = (a, b) =>
88 | {
89 | return -a.FScoreWeighted.CompareTo(b.FScoreWeighted);
90 | };
91 | break;
92 | case SortingMetric.AverageFScoreWeighted:
93 | SortBy = SortingMetric.AverageFScoreWeighted;
94 | _comparer = (a, b) =>
95 | {
96 | return -a.AverageFScoreWeighted.CompareTo(b.AverageFScoreWeighted);
97 | };
98 | break;
99 | case SortingMetric.AverageGain:
100 | SortBy = SortingMetric.AverageGain;
101 | _comparer = (a, b) =>
102 | {
103 | return -a.AverageGain.CompareTo(b.AverageGain);
104 | };
105 | break;
106 | case SortingMetric.ExpectedGain:
107 | SortBy = SortingMetric.ExpectedGain;
108 | _comparer = (a, b) =>
109 | {
110 | return -a.ExpectedGain.CompareTo(b.ExpectedGain);
111 | };
112 | break;
113 |
114 | }
115 | }
116 |
117 | static FIScoreComparer()
118 | {
119 | SetComparer(SortingMetric.Gain);
120 | }
121 |
122 | public static int Compare(FeatureInteraction a, FeatureInteraction b)
123 | {
124 | return _comparer(a, b);
125 | }
126 |
127 |
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/XgbFeatureInteractions/FeatureInteraction.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace XgbFeatureInteractions
8 | {
9 | public class FeatureInteraction : IComparable
10 | {
11 | public string Name { get; set; }
12 | public int Depth { get; set; }
13 | public double Gain { get; set; }
14 | public double Cover { get; set; }
15 | public double FScore { get; set; }
16 | public double FScoreWeighted { get; set; }
17 | public double AverageFScoreWeighted { get; set; }
18 | public double AverageGain { get; set; }
19 | public double ExpectedGain { get; set; }
20 | public double TreeIndex { get; set; }
21 | public double AverageTreeIndex { get; set; }
22 | public double TreeDepth { get; set; }
23 | public double AverageTreeDepth { get; set; }
24 | public SplitValueHistogram SplitValueHistogram { get; set; }
25 |
26 | public bool HasLeafStatistics { get; set; }
27 | public double SumLeafValuesLeft { get; set; }
28 | public double SumLeafCoversLeft { get; set; }
29 | public double SumLeafValuesRight { get; set; }
30 | public double SumLeafCoversRight { get; set; }
31 |
32 | public FeatureInteraction(HashSet interaction, double gain, double cover, double pathProbability, double depth, double treeIndex, double fScore = 1)
33 | {
34 | SplitValueHistogram = new SplitValueHistogram();
35 | List features = interaction.OrderBy(x => x.Feature).Select(y => y.Feature).ToList();
36 |
37 | Name = string.Join("|", features);
38 | Depth = interaction.Count - 1;
39 | Gain = gain;
40 | Cover = cover;
41 | FScore = fScore;
42 | FScoreWeighted = pathProbability;
43 | AverageFScoreWeighted = FScoreWeighted / FScore;
44 | AverageGain = Gain / FScore;
45 | ExpectedGain = Gain * pathProbability;
46 | TreeIndex = treeIndex;
47 | TreeDepth = depth;
48 | AverageTreeIndex = TreeIndex / FScore;
49 | AverageTreeDepth = TreeDepth / FScore;
50 | HasLeafStatistics = false;
51 |
52 | if (Depth == 0)
53 | {
54 | SplitValueHistogram.AddValue(interaction.First().SplitValue);
55 | }
56 | }
57 |
58 | public int CompareTo(object obj)
59 | {
60 | var featInteraction = obj as FeatureInteraction;
61 | return FIScoreComparer.Compare(this, featInteraction);
62 | }
63 |
64 | public override string ToString()
65 | {
66 | return String.Format("{0}:{1}", Name, Gain);
67 | }
68 |
69 | public override bool Equals(object obj)
70 | {
71 | var featInteraction = obj as FeatureInteraction;
72 | return this.Name.Equals(featInteraction.Name);
73 | }
74 |
75 | public override int GetHashCode()
76 | {
77 | return Name.GetHashCode();
78 | }
79 |
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/XgbFeatureInteractions/FeatureInteractions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using OfficeOpenXml;
8 | using XgbFeatureInteractions.Properties;
9 |
10 | namespace XgbFeatureInteractions
11 | {
12 | public class FeatureInteractions : Dictionary
13 | {
14 | public int MaxDepth
15 | {
16 | get
17 | {
18 | return this.Max(x => x.Value.Depth);
19 | }
20 | }
21 |
22 | public double TotalGain
23 | {
24 | get
25 | {
26 | return this.Sum(x => x.Value.Gain);
27 | }
28 | }
29 |
30 | public double TotalCover
31 | {
32 | get
33 | {
34 | return this.Sum(x => x.Value.Cover);
35 | }
36 | }
37 |
38 | public double TotalFScore
39 | {
40 | get
41 | {
42 | return this.Sum(x => x.Value.FScore);
43 | }
44 | }
45 |
46 | public FeatureInteractions() : base()
47 | {
48 |
49 | }
50 |
51 | public void Merge(FeatureInteractions interactions)
52 | {
53 | foreach(KeyValuePair fi in interactions)
54 | {
55 | if (!ContainsKey(fi.Key))
56 | {
57 | Add(fi.Key, fi.Value);
58 | }
59 | else
60 | {
61 | this[fi.Key].Gain += fi.Value.Gain;
62 | this[fi.Key].Cover += fi.Value.Cover;
63 | this[fi.Key].FScore += fi.Value.FScore;
64 | this[fi.Key].FScoreWeighted += fi.Value.FScoreWeighted;
65 | this[fi.Key].AverageFScoreWeighted = this[fi.Key].FScoreWeighted / this[fi.Key].FScore;
66 | this[fi.Key].AverageGain = this[fi.Key].Gain / this[fi.Key].FScore;
67 | this[fi.Key].ExpectedGain += fi.Value.ExpectedGain;
68 | this[fi.Key].SumLeafCoversLeft += fi.Value.SumLeafCoversLeft;
69 | this[fi.Key].SumLeafCoversRight += fi.Value.SumLeafCoversRight;
70 | this[fi.Key].SumLeafValuesLeft += fi.Value.SumLeafValuesLeft;
71 | this[fi.Key].SumLeafValuesRight += fi.Value.SumLeafValuesRight;
72 | this[fi.Key].TreeIndex += fi.Value.TreeIndex;
73 | this[fi.Key].AverageTreeIndex = this[fi.Key].TreeIndex / this[fi.Key].FScore;
74 | this[fi.Key].TreeDepth += fi.Value.TreeDepth;
75 | this[fi.Key].AverageTreeDepth = this[fi.Key].TreeDepth / this[fi.Key].FScore;
76 |
77 | //if (fi.Value.Depth == 0)
78 | //{
79 | // this[fi.Key].SplitValueHistogram.Merge(fi.Value.SplitValueHistogram);
80 |
81 | //}
82 | this[fi.Key].SplitValueHistogram.Merge(fi.Value.SplitValueHistogram);
83 | }
84 | }
85 | }
86 | public FeatureInteractions(IEnumerable> featureInteractions) : base()
87 | {
88 | foreach (var fi in featureInteractions)
89 | {
90 | Add(fi.Key, fi.Value);
91 | }
92 | }
93 |
94 | public FeatureInteractions GetFeatureInteractionsOfDepth(int depth)
95 | {
96 | return new FeatureInteractions(new FeatureInteractions(this.Where(x => x.Value.Depth == depth)));
97 | }
98 |
99 | public FeatureInteractions GetFeatureInteractionsWithLeafStatistics()
100 | {
101 | return new FeatureInteractions(new FeatureInteractions(this.Where(x => x.Value.HasLeafStatistics == true)));
102 | }
103 |
104 | public bool WriteToXlsx(string fileName, int topK)
105 | {
106 | try
107 | {
108 | if (File.Exists(fileName))
109 | {
110 | File.Delete(fileName);
111 | }
112 |
113 | FileInfo newFile = new FileInfo(fileName);
114 | ExcelPackage pck = new ExcelPackage(newFile);
115 |
116 | Console.ResetColor();
117 | Console.WriteLine("Writing {0}", fileName);
118 |
119 | List interactions = null;
120 |
121 | for (int depth=0; depth <= MaxDepth; depth++)
122 | {
123 | Console.ForegroundColor = ConsoleColor.DarkGreen;
124 | Console.WriteLine(String.Format("Writing feature interactions with depth {0} ", depth));
125 | Console.ResetColor();
126 |
127 | interactions = GetFeatureInteractionsOfDepth(depth).Values.ToList();
128 | interactions.Sort();
129 |
130 | double KTotalGain = interactions.Sum(x => x.Gain);
131 | double TotalCover = interactions.Sum(x => x.Cover);
132 | double TotalFScore = interactions.Sum(x => x.FScore);
133 | double TotalFScoreWeighted = interactions.Sum(x => x.FScoreWeighted);
134 | double TotalFScoreWeightedAverage = interactions.Sum(x => x.AverageFScoreWeighted);
135 |
136 | if (topK > 0)
137 | {
138 | interactions = interactions.Take(topK).ToList();
139 | }
140 |
141 |
142 | if (interactions.Count == 0)
143 | {
144 | break;
145 | }
146 |
147 | var ws = pck.Workbook.Worksheets.Add(String.Format("Interaction Depth {0}",depth));
148 |
149 | ws.Row(1).Height = 20;
150 | ws.Row(1).Style.Font.Bold = true;
151 | ws.Row(1).Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
152 | ws.Row(1).Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
153 | ws.Column(1).Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center;
154 | ws.Column(1).Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center;
155 | ws.Column(1).Width = interactions.Max(x => x.Name.Length) + 10;
156 | ws.Column(2).Width = 17;
157 | ws.Column(3).Width = 17;
158 | ws.Column(4).Width = 17;
159 | ws.Column(5).Width = 17;
160 | ws.Column(6).Width = 17;
161 | ws.Column(7).Width = 17;
162 | ws.Column(8).Width = 17;
163 | ws.Column(9).Width = 17;
164 | ws.Column(10).Width = 17;
165 | ws.Column(11).Width = 18;
166 | ws.Column(12).Width = 18;
167 | ws.Column(13).Width = 19;
168 | ws.Column(14).Width = 17;
169 | ws.Column(15).Width = 19;
170 | ws.Column(16).Width = 19;
171 |
172 | ws.Cells[1, 1].Value = "Interaction";
173 | ws.Cells[1, 2].Value = "Gain";
174 | ws.Cells[1, 3].Value = "FScore";
175 | ws.Cells[1, 4].Value = "wFScore";
176 | ws.Cells[1, 5].Value = "Average wFScore";
177 | ws.Cells[1, 6].Value = "Average Gain";
178 | ws.Cells[1, 7].Value = "Expected Gain";
179 | ws.Cells[1, 8].Value = "Gain Rank";
180 | ws.Cells[1, 9].Value = "FScore Rank";
181 | ws.Cells[1, 10].Value = "wFScore Rank";
182 | ws.Cells[1, 11].Value = "Avg wFScore Rank";
183 | ws.Cells[1, 12].Value = "Avg Gain Rank";
184 | ws.Cells[1, 13].Value = "Expected Gain Rank";
185 | ws.Cells[1, 14].Value = "Average Rank";
186 | ws.Cells[1, 15].Value = "Average Tree Index";
187 | ws.Cells[1, 16].Value = "Average Tree Depth";
188 |
189 | var gainSorted = interactions.OrderBy(x => -x.Gain).ToList();
190 | var fScoreSorted = interactions.OrderBy(x => -x.FScore).ToList();
191 | var fScoreWeightedSorted = interactions.OrderBy(x => -x.FScoreWeighted).ToList();
192 | var averagefScoreWeightedSorted = interactions.OrderBy(x => -x.AverageFScoreWeighted).ToList();
193 | var averageGainSorted = interactions.OrderBy(x => -x.AverageGain).ToList();
194 | var expectedGainSorted = interactions.OrderBy(x => -x.ExpectedGain).ToList();
195 |
196 | List