Decision Table Discretization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
var data = Data.Benchmark.Factory.Vehicle();
DecisionTable train, test;
var splitter = new DataSplitterRatio(data, 0.8);
splitter.Split(out train, out test);
var tableDiscretizer = new TableDiscretizer(
new IDiscretizer[]
{
//try to discretize using Fayyad MDL Criterion
new DiscretizeFayyad(),
//in case Fayyad MDL is to strict
//use standard entropy and 5 buckets
new DiscretizeEntropy(5)
});
tableDiscretizer.FieldsToDiscretize = train
.SelectAttributeIds(a => a.IsStandard && a.CanDiscretize());
var filter = new DiscretizeFilter();
filter.TableDiscretizer = tableDiscretizer;
filter.Compute(train);
foreach(int attributeId in tableDiscretizer.FieldsToDiscretize)
{
var fieldDiscretizer = filter
.GetAttributeDiscretizer(attributeId);
Console.WriteLine("Attribute {0} was discretized with {1}",
attributeId, fieldDiscretizer.GetType().Name);
Console.WriteLine("Computed Cuts: {0}",
fieldDiscretizer.Cuts.ToStr());
}
var trainDisc = filter.Apply(train);
var testDisc = filter.Apply(test);
Written on June 28, 2017