/* /--------------------------------------------------------------------\ | File : Tester.C | |--------------------------------------------------------------------| | Written by : Umit CATALYUREK | | Date : 1.6.1993 | |--------------------------------------------------------------------| | Description : Test program for Decison List produced by CN2 | | program | | Machine Learning Course. | | Main File | |--------------------------------------------------------------------| | Last Modification Date : | | By : | | Description : | \____________________________________________________________________/ */ #include #include #include #include #include #include "prepare.h" #include "complex.h" extern Description Dscr; extern DataList Data; extern PComplexList selectors; #define MAXSTAR 5 RuleList rulelist; PComplexList star; main(argc, argv) int argc; char *argv[]; { char fname[100]; FILE *namesf, *dataf; int inf, suc, fail; PInstance I; if (argc!=2) { printf("\n Usage : tester \n\n"); exit(0); } printf("\n Tester for CN2 Ver 1.0"); printf("\n Implemented by : Umit CATALYUREK\n"); printf("\n Implementation for Machine Learning Course.\n Date : Spring 1992/93\n"); strcpy(fname, "Data/"); strcat(fname, argv[1]); strcat(fname, ".names"); namesf = fopen(fname, "r"); if (namesf == NULL) { printf("\n I could not open description file : %s\n\n", fname); exit(0); } strcpy(fname, "Data/"); strcat(fname, argv[1]); strcat(fname, ".test"); dataf = fopen(fname, "r"); if (dataf == NULL) { printf("\n I could not open test file : %s\n\n", fname); exit(0); } strcpy(fname, "Data/"); strcat(fname, argv[1]); strcat(fname, ".cn2"); inf = open(fname, O_RDONLY); Initialize(); rulelist.head = rulelist.tail = NULL; ReadDescrFile(namesf); /* printdescription(); */ ReadDataFile(dataf); /* printdata(); */ ReadOccurences(inf); InitSelectors(); ReadRuleList(inf); /* printrulelist(); getchar(); */ EliminateUnknownData(); printf("\n Description File : %s.names", argv[1]); printf("\n Test File : %s.data", argv[1]); printf("\n #Attributes : %5d # Test Instances : %5d\n", Dscr.numofattributes, Data.numofinstances); suc = fail = 0; for (I=Data.head; I!=NULL; I=I->next) if (RuleListMatch(I)) suc++; else fail++; printf("\n # Success : %d", suc); printf("\n # Fail : %d", fail); printf("\n Success rate : %8.3f\n\n", (float) suc / (float) Data.numofinstances); fclose(namesf); fclose(dataf); close(inf); Deallocate(); DeallocateRuleList(); DeallocateSelectors(); }