You are on page 1of 24

StringTokenizer tokenizer = new StringTokenizer(input);

numAttributes = tokenizer.countTokens();

if (numAttributes <= 1) {

System.err.println( "Read line: " + input);

System.err.println( "Could not obtain the names of attributes in the

line");

System.err.println( "Expecting at least one input attribute and one

output attribute");

return 0;

}domains = new Vector[numAttributes];

for (int i=0; i < numAttributes; i++) domainsIdea [I] = new Vector();

attributeNames = new String[numAttributes];

for (int i=0; i < numAttributes; i++) {

attributeNamesIdea [I] = tokenizer.nextToken();

}while(true) {

input = bin.readLine();

if (input == null) break;

if (input.startsWith("//")) continue;

if (input.equals("")) continue;

tokenizer = new StringTokenizer(input);

int numtokens = tokenizer.countTokens();

if (numtokens != numAttributes) {

System.err.println( "Read " + root.data.size() + " data");


System.err.println( "Last line read: " + input);

System.err.println( "Expecting " + numAttributes + " attributes");

return 0;
}DataPoint point = new DataPoint(numAttributes);

for (int i=0; i < numAttributes; i++) {

point.attributesIdea [I] = getSymbolValue(i, tokenizer.nextToken()

);

}root.data.addElement(point);
}bin.close();
return 1;
}public void printTree(TreeNode node, String tab) {

int outputattr = numAttributes-1;

if (node.children == null) {

int []values = getAllValues(node.data, outputattr );

if (values.length == 1) {

System.out.println(tab + "\t" + attributeNames[outputattr] + " = \"" +

domains[outputattr].elementAt(values[0]) + "\";");

return;

}System.out.print(tab + "\t" + attributeNames[outputattr] + " = {");

for (int i=0; i < values.length; i++) {

System.out.print("\"" + domains[outputattr].elementAt(valuesIdea [I]) + "\"

");

if ( i != values.length-1 ) System.out.print( " , " );

}System.out.println( " };");

return;
}int numvalues = node.children.length;

for (int i=0; i < numvalues; i++) {

System.out.println(tab + "if( " +


attributeNames[node.decompositionAttribute] + " == \"" +

domains[node.decompositionAttribute].elementAt(i)

+ "\") {" );

printTree(node.childrenIdea [I], tab + "\t");

if (i != numvalues-1) System.out.print(tab + "} else ");

else System.out.println(tab + "}");

}}public void createDecisionTree() {

decomposeNode(root); printTree(root, ""); }/* main function */


public static void main(String[] args) throws Exception {

ID3 me = new ID3();

int status = me.readData("c:\\in.txt");

if (status <= 0) return;

me.createDecisionTree();

}}

Decision Tree Algorithm


Download this Document for FreePrintMobileCollectionsReport Document
ba9277306bed2a

doc

Report

This is a private document.


Info and Rating

4.7 5 false false 0

java
decision
tree
algorithm
Technology-Computer-Science
code c
decisions tree
tree classification
(more tags)
Pageman
Ads by Google

Sign Up for an Ad-Free Scribd

 Remove all ads.


Never see ads on Scribd again.

No Thanks

Share & Embed

Related Documents

PreviousNext

1.

2 p.
83 p.

21 p.

2.

41 p.

2 p.

146 p.

3.
2 p.

430 p.

5 p.

4.

42 p.

21 p.

68 p.

5.
212 p.

2 p.

16 p.

6.

29 p.

2 p.
2 p.

7.

109 p.

1 p.

1 p.

8.

1 p.
20 p.

1 p.

9.

1 p.

3 p.

1 p.

10.
76 p.

21 p.

13 p.

11.

2 p.

37 p.
251 p.

12.

9 p.

7 p.

14 p.

13.

97 p.
21 p.

1 p.

14.

1 p.

127 p.

1 p.

15.
1 p.

1 p.

15 p.

16.

9 p.

1 p.
5 p.

17.

20 p.

144 p.

1 p.

18.

44 p.
1 p.

19 p.

19.

1 p.

1 p.

15 p.

20.
2 p.

11 p.

4 p.

21.

16 p.

More from this user

PreviousNext

1.

1 p.
2 p.

1 p.

2.

2 p.

5 p.

4 p.
3.

4 p.

2 p.

4 p.

4.

2 p.

4 p.
3 p.

5.

21 p.

2 p.

2 p.

6.

5 p.
2 p.

3 p.

7.

3 p.

2 p.

4 p.
8.

48 p.

3 p.

3 p.

9.

2 p.

Recent Readcasters

Add a Comment
ba9277306bed2a

Submit

document_comme

4gen

mohammedirfan13 left a comment

plzzzzzzzzzz andy body tell me what is the format for in.txt file.. plzzzzzzz... and what is the
best IDE to implement this algorithm.. plzzzzz reply any body...
03 / 19 / 2010
Reply
Report

merkurisa left a comment

thank you for your uploding,but please add the" in.txt" file.please please please...
03 / 07 / 2010
Reply
Report

emadof left a comment

thanks, but, in which way the data in the input file is defined?
02 / 02 / 2010
Reply
Report

umayanganie left a comment


thanks.
01 / 06 / 2010
Reply
Report

zarsiwala left a comment

Is the .txt file attached some other place? Or is the format specified somewhere? Thanks!
11 / 16 / 2009
Reply
Report

ba9277306bed2a

Enter a name for your new colle

public - locked

Save collection

ba9277306bed2a
public - locked

Save collection

You might also like