示例#1
0
		/// <summary> Generates the classifier.
		/// 
		/// </summary>
		/// <exception cref="Exception">if classifier can't be built successfully
		/// </exception>
		public override void  buildClassifier(Instances instances)
		{
			
			ModelSelection modSelection;
			
			if (m_binarySplits)
				modSelection = new BinC45ModelSelection(m_minNumObj, instances);
			else
				modSelection = new C45ModelSelection(m_minNumObj, instances);
			if (!m_reducedErrorPruning)
				m_root = new C45PruneableClassifierTree(modSelection, !m_unpruned, m_CF, m_subtreeRaising, !m_noCleanup);
			else
				m_root = new PruneableClassifierTree(modSelection, !m_unpruned, m_numFolds, !m_noCleanup, m_Seed);
			m_root.buildClassifier(instances);
			if (m_binarySplits)
			{
				((BinC45ModelSelection) modSelection).cleanup();
			}
			else
			{
				((C45ModelSelection) modSelection).cleanup();
			}
		}
示例#2
0
		/// <summary> Returns a newly created tree.
		/// 
		/// </summary>
		/// <param name="data">the training data
		/// </param>
		/// <exception cref="Exception">if something goes wrong
		/// </exception>
		protected internal virtual ClassifierTree getNewTree(Instances data)
		{
			
			ClassifierTree newTree = new ClassifierTree(m_toSelectModel);
			newTree.buildTree(data, false);
			
			return newTree;
		}
示例#3
0
		/// <summary> Returns a newly created tree.
		/// 
		/// </summary>
		/// <param name="data">the training data
		/// </param>
		/// <param name="test">the pruning data.
		/// </param>
		/// <exception cref="Exception">if something goes wrong
		/// </exception>
		protected internal virtual ClassifierTree getNewTree(Instances train, Instances test)
		{
			
			ClassifierTree newTree = new ClassifierTree(m_toSelectModel);
			newTree.buildTree(train, test, false);
			
			return newTree;
		}
示例#4
0
        public override void buildClassifier(string fileName, Instances instances)
        {

            XmlDocument dom = new XmlDocument();
            dom.Load(fileName);
            XmlNode xNode = dom.DocumentElement;

            if ((xNode.Name == Constants.DECISION_TREE_ELEMENT) && (xNode.HasChildNodes))
            {

                foreach (XmlAttribute xAttribute in xNode.Attributes)
                {
                    if (xAttribute.Name == Constants.PRUNED_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_unpruned = true;
                        else
                            this.m_unpruned = false;
                    }
                    else if (xAttribute.Name == Constants.CONFIDENCE_ATTRIBUTE)                    
                        this.m_CF = (float) Convert.ToDouble(xAttribute.Value);
                    else if (xAttribute.Name == Constants.MIN_NUM_OBJECTS_ATTRIBUTE)
                        this.m_minNumObj = Convert.ToInt32(xAttribute.Value);
                    else if (xAttribute.Name == Constants.USE_LAPLACE_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_useLaplace = true;
                        else
                            this.m_useLaplace = false;     
                    }
                    else if (xAttribute.Name == Constants.REDUCED_ERROR_PRUNING_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_reducedErrorPruning = true;
                        else
                            this.m_reducedErrorPruning = false;        
                    }
                    else if (xAttribute.Name == Constants.NUM_FOLDS_ATTRIBUTE)
                        this.m_numFolds = Convert.ToInt32(xAttribute.Value);
                    else if (xAttribute.Name == Constants.BINARY_SPLITS_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_binarySplits = true;
                        else
                            this.m_binarySplits = false;  
                    }
                    else if (xAttribute.Name == Constants.SUBTREE_RAISING_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_subtreeRaising = true;
                        else
                            this.m_subtreeRaising = false;
                    }
                    else if (xAttribute.Name == Constants.NO_CLEANUP_ATTRIBUTE)
                    {
                        if (xAttribute.Value == "True")
                            this.m_noCleanup = true;
                        else
                            this.m_noCleanup = false;
                    }
                    else if (xAttribute.Name == Constants.SEED_ATTRIBUTE)
                        this.m_Seed = Convert.ToInt32(xAttribute.Value);                    
                }

                //Going through the subtrees
                foreach (XmlNode iNode in xNode.ChildNodes)
                {
                    if (iNode.Name == Constants.C45_PRUNEABLE_ELEMENT)
                    {
                        this.m_root = new C45PruneableClassifierTree(iNode, instances);
                    }
                }
            }
        }