.net - How to implement decision tree with c# (visual studio 2008) - Help -


i have decision tree need turn code in c#

the simple way of doing using if-else statements in solution need create 4-5 nested conditions.

i looking better way , far read little bit rule engines.

do have else suggest efficient way develop decision tree 4-5 nested conditions?

i implemented simple decision tree sample in book. code available online here, perhaps use inspiration. decision represented class has references true branch , false branch , contains function test:

class decisionquery : decision {   public decision positive { get; set; }   public decision negative { get; set; }   // primitive operation provided user   public func<client, bool> test { get; set; }    public override bool evaluate(client client) {     // test client using primitive operation     bool res = test(client);     // select branch follow     return res ? positive.evaluate(client) : negative.evaluate(client);   } } 

here, decision base class contains evaluate method , source contains 1 additional derived type contains final decision of tree (yes/no). type client sample input data you're analysing using tree.

to create decision tree, can write like:

var tree = new decisionquery {     test = (client) => client.income > 40000,     positive = othertree,     negative = someothertree   }; 

if want write 5 nested static if clauses maybe writing if fine. benefit of using type 1 can compose trees - e.g. reuse part of tree or modularize construction.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -