Programmers need to
debug, which sometimes requires identification of points in your program
where a programmer would like to insert code that would help him/her to
debug his/her code efficiently. A simple example might be inserting a
Console.Writeline() call that prints out values or indicates completion
(successful or unsuccessful) of the executed part. However, these lines
can clutter up the code structure and also needs removal of the
debugging code for the release of the entire software.
This overhead is taken care of by specialized methods in C# that
help the programmer debug the code without the need to clean up his/her
debugging code for the release phase. These methods which are used for
debugging are called Conditional methods.
The compiler identifies these marked methods and never includes them in
the release build.
Well, that’s good enough. But, how do I make a method
conditional? .NET provides an attribute System.Diagnostics.ConditionalAttribute
(alias Conditional) to achieve this. Let’s
look at some code now.
Defining the conditional
method
publicclassMyTracer {[Conditional(“DEBUG”)]publicstatic void LogThisMessage(string myMessage, int
severity){//Write message to screen
or a file or …Console.WriteLine(” DEBUG MESSAGE : “ + myMessage +” SEVERITY LEVEL : “+severity);}}
The Conditional attribute has been applied to the LogThisMessage() method with the DEBUG conditional compilation symbol. This signals the
compiler that the method should be ignored if the conditional symbol DEBUG is not specified.
Using the conditional method
With the Solution
Configurations set to Debug mode if you execute the following
code, you would happily see the output window shown below.
publicstaticvoid Main(string[]
args){//Some error occured in my
code//Log the messageMyTracer.LogThisMessage(“The error 1221 has occured.”,
5);}
Now lets see what happens
to our conditional code in the Release mode. To enable Debug or Release
mode you have to look for the Solution Configurations selector in your
Visual Studio IDE which is shown below.
Change the mode to “Release” and you would see that the conditional code
now has disappeared.
We used the predefined DEBUG compilation symbol in our code. You can have
your own defined symbols and use them for conditional compilation. You
can define custom compilation symbols in Project Properties -> Build
tab -> General. Checkboxes have been provided to enable or disable
the DEBUG and TRACE
symbols.
.NET also provides two
classes that provide similar functionality:
System.Diagnostics.Debug
System.Diagnostics.Trace
These classes
contain methods that can also be used for debugging if you do not need
more specific custom methods.
對於在Step2所建立的Child node,有一些可能會是空的。 =>the node is declared a leaf node with the same class label as the majority class of training records associated with its parent node. (這個node會被宣告成leaf node,而class label會標成與父節點底下的training records的主要class。)
在Step2中,若Dt中的全部records皆擁有相同的屬性值,則無法在進一步做分離這些records。 =>the node is declared a leaf node with the same class label as the majority class of training records associated with this node. (這個node會被宣告成leaf node,而class label會標成與這個node相連結的training records的主要class一樣。)
Design Issue of Decision Tree Induction 決策樹的設計問題介紹
歸納決策樹的演算法必須注意兩個問題:
How should the training records be split? 建立樹的process的每一個recursive step必須挑選一個attribute test condition 去把records分成小的集合。為了實作此步驟,演算法必須提供一個方法,對於不同屬性形態可以去詳細指明測試條件。
How should the splitting procedure stop? 終止一個建立樹的process是需要一個停止條件的。可能的方法就是一直展開節點直到所有record都屬於同一個類別或者是所有records都有相同的屬性值。雖然這兩種條件都可以有效率的讓建立樹的process暫停,但也有可能有其他的標準可以讓這個prcoess更早暫停。在後面4-4-5將會談到。
呼!好累!看原文書還要瞭解,然後在寫成我自己的筆記,挺累的!
4-3-3 Methods for Expressing Attribute Test Conditions 表達屬性測試條件的方法
如下圖,如果有兩個方法可以把資料分成較小的集合,若屬性A先選的話,Gini(N1)=0.4898,G(N2)=0.480,對於descendent nodes來說,weighted average of the Gini index=(7/12)x0.4898+(5/12)x0.480=0.486。相同的,若先選B的話,weighted average of the Gini index=0.375,因為B有比較小的Gini index,所以會先選擇屬性B。
Splitting of Nominal Attributes
binary split的算法跟binary attribute一樣,所以左邊的Gini index=0.468,而右邊Gini index=0.167,所以會選擇右邊的分割方法。另一個Multiway split的算法也是差不多,Gini index=4/20 x 0.375+8/20 x 0 + 8/20 x 0.219=0.163,比起binary split的方法,multiway split的gini index更小。