コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="maximumTreeDepth">The maximal tree depth before a leaf is generated</param>
        /// <param name="featuresPrSplit">The number of features to be selected between at each split.
        /// 0 means use all availible features</param>
        /// <param name="minimumInformationGain">The minimum improvement in information gain before a split is made</param>
        /// <param name="seed">Seed for feature selection if number of features pr split is not equal
        /// to the total amount of features in observations. The features will be selected at random for each split</param>
        /// <param name="splitSearcher">The type of searcher used for finding the best features splits when learning the tree</param>
        /// <param name="impurityCalculator">Impurity calculator used to decide which split is optimal</param>
        public DepthFirstTreeBuilder(int maximumTreeDepth, int featuresPrSplit, double minimumInformationGain, int seed,
                                     ISplitSearcher splitSearcher, IImpurityCalculator impurityCalculator)
        {
            if (splitSearcher == null)
            {
                throw new ArgumentException("splitSearcher");
            }
            if (maximumTreeDepth <= 0)
            {
                throw new ArgumentException("maximum tree depth must be larger than 0");
            }
            if (minimumInformationGain <= 0)
            {
                throw new ArgumentException("minimum information gain must be larger than 0");
            }
            if (featuresPrSplit < 0)
            {
                throw new ArgumentException("features pr split must be at least 0");
            }
            if (impurityCalculator == null)
            {
                throw new ArgumentException("impurityCalculator");
            }

            m_maximumTreeDepth       = maximumTreeDepth;
            m_featuresPrSplit        = featuresPrSplit;
            m_splitSearcher          = splitSearcher;
            m_impurityCalculator     = impurityCalculator;
            m_minimumInformationGain = minimumInformationGain;

            m_random = new Random(seed);
        }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="maximumTreeDepth">The maximal tree depth before a leaf is generated</param>
        /// <param name="maximumLeafCount">The maximal allowed leaf nodes in the tree</param>
        /// <param name="featuresPrSplit">The number of features to be selected between at each split.
        /// 0 means use all available features</param>
        /// <param name="minimumInformationGain">The minimum improvement in information gain before a split is made</param>
        /// <param name="seed">Seed for feature selection if number of features pr split is not equal
        /// to the total amount of features in observations. The features will be selected at random for each split</param>
        /// <param name="splitSearcher">The type of searcher used for finding the best features splits when learning the tree</param>
        /// <param name="impurityCalculator">Impurity calculator used to decide which split is optimal</param>
        public BestFirstTreeBuilder(int maximumTreeDepth,
                                    int maximumLeafCount,
                                    int featuresPrSplit,
                                    double minimumInformationGain,
                                    int seed,
                                    ISplitSearcher splitSearcher,
                                    IImpurityCalculator impurityCalculator)
        {
            if (maximumTreeDepth <= 0)
            {
                throw new ArgumentException("maximum tree depth must be larger than 0");
            }
            if (maximumLeafCount <= 1)
            {
                throw new ArgumentException("maximum leaf count must be larger than 1");
            }
            if (minimumInformationGain <= 0)
            {
                throw new ArgumentException("minimum information gain must be larger than 0");
            }
            if (featuresPrSplit < 0)
            {
                throw new ArgumentException("features pr split must be at least 0");
            }
            m_splitSearcher      = splitSearcher ?? throw new ArgumentException(nameof(splitSearcher));
            m_impurityCalculator = impurityCalculator ?? throw new ArgumentException(nameof(impurityCalculator));

            m_maximumTreeDepth       = maximumTreeDepth;
            m_maximumLeafCount       = maximumLeafCount;
            m_featuresPrSplit        = featuresPrSplit;
            m_minimumInformationGain = minimumInformationGain;

            m_random = new Random(seed);
        }