Beispiel #1
0
        public bool CheckError()
        {
            var _inputs  = _codebook.GetArray(_treeInfo.Inputs);
            var _outputs = _codebook.GetArray(_treeInfo.Output);

            if (_inputs == null || _outputs == null)
            {
                return(false);
            }

            var result = true;

            for (var i = 0; i < _inputs.Length; ++i)
            {
                var res = _tree.Compute(_inputs[i]);
                result = result && res == _outputs[i];

                if (result)
                {
                    continue;
                }

                var vector = string.Join(", ", _inputs[i].Select(x => x.ToString()));
                _logger.Info($"Crash for: {vector}");
            }

            return(result);
        }
Beispiel #2
0
        public DecisionTreeService(
            DataTable data,
            IDictionary <string, string[]> metaInfo,
            ILogger logger)
        {
            _logger   = logger;
            _codebook = new Codebook(data, metaInfo);

            var vars       = ParseMetaInfo(metaInfo);
            var inputInfo  = vars.Take(vars.Length - 1).ToArray();
            var outputInfo = vars.Last();

            _treeInfo = new TreeInfo()
            {
                Inputs = inputInfo.Select(x => x.Name).ToArray(),
                Output = outputInfo.Name
            };

            var inputs  = _codebook.GetArray(_treeInfo.Inputs);
            var outputs = _codebook.GetArray(_treeInfo.Output);

            _treeBuilder = new Id3Algorithm(inputInfo, outputInfo);
            _tree        = _treeBuilder.Learn(inputs, outputs);
        }