473,396 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Disease Prediction using Decisional Trees

I have made cancer prediction based on symptoms using decision trees but i am not able to run my code

Please Help ME!! Thanks in Advance!!!

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<iostream>
  3. using namespace std;
  4. #include<conio.h>
  5. #include<string.h>
  6.  
  7. struct dectree
  8. {
  9.     char symptom[50];
  10.  
  11.     struct disease
  12.     {
  13.         char disea[50];
  14.     }dis[20];
  15. }arr[40];
  16.  
  17. void datainsert()
  18. {
  19. strcpy(arr[0].symptom,"Uneasiness");
  20. strcpy(arr[0].dis[0].disea,"Pancreas");
  21. strcpy(arr[0].dis[1].disea,"Stomach");
  22. strcpy(arr[0].dis[2].disea,"Esophagus");
  23. strcpy(arr[0].dis[3].disea,"Kidney");
  24. strcpy(arr[0].dis[4].disea,"Lung");
  25. strcpy(arr[0].dis[5].disea,"Bone");
  26. strcpy(arr[0].dis[6].disea,"Brain");
  27. strcpy(arr[0].dis[7].disea,"Leukmia");
  28. strcpy(arr[0].dis[8].disea,"Colon");
  29.  
  30. strcpy(arr[1].symptom,"Unexplained Weight Loss");
  31. strcpy(arr[1].dis[0].disea,"Pancreas");
  32. strcpy(arr[1].dis[1].disea,"Stomach");
  33. strcpy(arr[1].dis[2].disea,"Esophagus");
  34. strcpy(arr[1].dis[3].disea,"Kidney");
  35. strcpy(arr[1].dis[4].disea,"Lung");
  36.  
  37. strcpy(arr[2].symptom,"Fatigue");
  38. strcpy(arr[2].dis[0].disea,"Bone");
  39. strcpy(arr[2].dis[1].disea,"Brain");
  40. strcpy(arr[2].dis[2].disea,"Leukmia");
  41. strcpy(arr[2].dis[3].disea,"Colon");
  42.  
  43. strcpy(arr[3].symptom,"Stomach Ache");
  44. strcpy(arr[3].dis[0].disea,"Pancreas");
  45. strcpy(arr[3].dis[1].disea,"Stomach");
  46. strcpy(arr[3].dis[2].disea,"Esophagus");
  47. strcpy(arr[3].dis[3].disea,"Kidney");
  48.  
  49. strcpy(arr[4].symptom,"Chronic Cough");
  50. strcpy(arr[4].dis[0].disea,"Lung");
  51.  
  52. strcpy(arr[5].symptom,"Changing Bowel Habits");
  53. strcpy(arr[5].dis[0].disea,"Colon");
  54.  
  55. strcpy(arr[6].symptom,"Pain");
  56. strcpy(arr[6].dis[0].disea,"Bone");
  57. strcpy(arr[6].dis[1].disea,"Leukmia");
  58. strcpy(arr[6].dis[2].disea,"Brain");
  59.  
  60. strcpy(arr[7].symptom,"Hypertension");
  61. strcpy(arr[7].dis[0].disea,"Pancreas");
  62. strcpy(arr[7].dis[1].disea,"Kidney");
  63.  
  64. strcpy(arr[8].symptom,"Swallowing Difficulty");
  65. strcpy(arr[8].dis[0].disea,"Stomach");
  66. strcpy(arr[8].dis[1].disea,"Esophagus");
  67.  
  68. strcpy(arr[13].symptom,"Head Ache");
  69. strcpy(arr[13].dis[0].disea,"Brain");
  70.  
  71. strcpy(arr[14].symptom,"Body Ache");
  72. strcpy(arr[14].dis[0].disea,"Bone");
  73. strcpy(arr[14].dis[1].disea,"Leukmia");
  74.  
  75. strcpy(arr[15].symptom,"Change in urine");
  76. strcpy(arr[15].dis[0].disea,"Kidney");
  77.  
  78. strcpy(arr[17].symptom,"Heartburn");
  79. strcpy(arr[17].dis[0].disea,"Esophagus");
  80.  
  81. strcpy(arr[29].symptom,"Physical Intolerance");
  82. strcpy(arr[29].dis[0].disea,"Leukmia");
  83.  
  84. strcpy(arr[30].symptom,"Bone swelling");
  85. strcpy(arr[30].dis[0].disea,"Bone");
  86.  
  87. }
  88. void result(int n)
  89. {
  90.     cout<<"Based on the following symptom you have chances of following CANCERS : \n";
  91.  
  92.     for(int i=0;i<9;i++)
  93.     {
  94.         cout<<arr[n].dis[i].disea<<"\t";
  95.     }
  96.     cout<<endl;
  97. }
  98. void search()
  99. {
  100. int    i=0;
  101. int count=1;
  102. int root=i;    
  103. int lchild;
  104. int rchild;
  105. char syn[40];
  106. int queue[20];
  107. int k=1;
  108.  
  109. lchild=2*root+1;
  110. rchild=2*root+2;
  111.  
  112.  
  113. while(arr[lchild].symptom!= NULL && arr[rchild].symptom!= NULL)
  114. {
  115.  
  116. cout<<"Enter the symptom "<<"\t";
  117. cin.getline(syn,40);
  118.  
  119. queue[count]=lchild;
  120. count++;
  121. queue[count]=rchild;
  122. count++;
  123.  
  124.  
  125. if(strcmp(arr[root].symptom,syn)==0)
  126. {
  127.  root=queue[k];
  128.  lchild=2*root+1;
  129.  rchild=2*root+2;
  130.  k++; 
  131.  
  132. }
  133. else if( queue[k]!=NULL)
  134. {
  135.     root=queue[k];
  136.      k++;    
  137.     if(strcmp(arr[root].symptom,syn)==0)
  138. {
  139.  root=queue[k];
  140.  lchild=2*root+1;
  141.  rchild=2*root+2;
  142.  k++; 
  143.  
  144. }
  145. }
  146. else
  147. {
  148.     break;
  149. }
  150. }
  151.  
  152. result(root);
  153.  
  154. }
  155. main()
  156. {
  157. datainsert();
  158. search();
  159. getch();    
  160. }
  161.  
Oct 19 '14 #1
11 1826
weaknessforcats
9,208 Expert Mod 8TB
Is there a reason you are using C++ but are attempting to code in C ?

You should be using be using C++ string objects, classes and a map container. That avoids all of the tree code.

If you are writing in C then use the C #includes and the scanf/printf functions.

If you continue your way, then use your debugger to step through the code.

C++ might kind of look like:
Expand|Select|Wrap|Line Numbers
  1. class Disease
  2. {
  3.    private:
  4.      string diseaseName;
  5. };
  6.  
  7. class Symptom
  8. {
  9.     private:
  10.        vector<Disease> dis;
  11. };
  12.  
Your database is:

Expand|Select|Wrap|Line Numbers
  1. map<string, Symptom> > database;
  2.  
  3.  
This data model assumes a key symptom which is looked up in the map container. The Symptom object has an embedded array of Disease objects which are the diseases associated with the symptom. All of the lookup tree code is done in the map container which is a C++ Standard Library object.
Oct 19 '14 #2
Thank You!

What i am doing is to incorporate both of them for the simplicity of the program.

I have found that my loop is not ending properly.. If you could please see that and give your input/rectification about the traversal or the search part.

If you have time..Please try running my code then you can see the error i am facing

Thank You!!
Oct 19 '14 #3
donbock
2,426 Expert 2GB
You mention run-time problems. Are you getting any compiler warnings?

Line 113 checks if the symptom field is NULL, but symptom is a char array not a char pointer. I'm surprised you didn't get a compiler warning for this. Likewise for other NULL test on line 133.

Can you describe in words the intent behind your search() function? Variable names lchild and rchild suggest a binary tree; but the arr array does not look a tree.
Oct 19 '14 #4
Thank You!!!

The compiler is not showing any warning but the loop is running infinitely.

The purpose behind this is the prediction of the disease based on symptom and yes its a binary tree made up using arrays. If you observe the array positions are such that it will form a tree.
Oct 19 '14 #5
weaknessforcats
9,208 Expert Mod 8TB
If you observe the array positions are such that it will form a tree.

Array positions are not usually used for trees.

Trees are made up of nodes where the node contains a pointer to keys larger than the search key and a pointer to the keys smaller then the search key and a pointer to the data value if the search key is equal. In the case of 1-2-3 trees there may be even more pointers.

Have you implemented a tree structure out of a book? If so, you can use the book example to debug your code. If not, you may want to find a tree structure you are comfortable with and implement that.

I would advise against placing values in known positions. You will be better off using addresses so you can place data indirectly thereby removing the requirement for a data structure. Instead your structure is defined by following an address to a node.
Oct 19 '14 #6
Thank you !

I haven't gone through the book structure

I want to implement the tree structure without nodes just using the array positions

In case if you have run the code you would have found that the loop runs infinitely and everytime it asks for symptoms

The thing that I want to end the loop conditionally an I am not able to run that
Oct 20 '14 #7
donbock
2,426 Expert 2GB
Each dectree structure associates one symptom with up to 20 diseases; arr is an array of 40 of these structures. Please explain the intended logic of the search function.
  • Do you intend to merely search the array for the first matching symptom and then you're done?
  • Do you intend to dance through the array in some disease-specific order?
You say the array is organized as a tree, but I don't understand what that means. A key attribute of a tree is the notion of a link to the next item (next right; next left). For example, what is the next item on the right of arr[7] (hypertension)? Which array entry is the root of the tree?
Oct 20 '14 #8
donbock
2,426 Expert 2GB
Traditionally, a decision tree is a structure where you start with a question; and each possible answer to that question either leads to another decision tree (another question) or to a final decision. How you answer the questions determines your path through the structure. The path is typically different each time.

What mechanism do you use to vary your path through your decision tree?
Oct 20 '14 #9
Thank You!!!

Ok ...so if you want to make a tree out of the array positions I have given then do 2i+1 and 2i+2

For example lets take the hypertension its at array 7 position so now to find out its root you will do (I-1)/2 ie 7-1=6 -> 6/2 = 3 now see array 3 ,...you will find stomach ache ... And see if you don't find the correspondent number like you are searching for that means its not there in the list(ie the node doesn't have Xchild)

See what I want to do is that first if a person has uneasiness then I will ask further symptom and each symptom is associated with some amount of cancer ...finally I come to a specific point where a person stops...you can make the tree with the above formulas

Thanks !!!
Oct 20 '14 #10
donbock
2,426 Expert 2GB
Your loop terminates because either
  • The loop condition on line 113 is satisfied.
  • You reach the break instruction on line 148: root symptom is not the entered symptom (line 125) and queue[k]==NULL (line 133).
As I pointed out in my first reply, none of your comparisons to NULL will do what you expect. This is likely why your loop doesn't terminate.

By the way, the lchild and rchild values of "Physical intolerance" and "Bone swelling" will be larger than the size of your array. You should trap these out-of-range values before using them to access the array. Accessing past the end of an array is Undefined Behavior.
Oct 20 '14 #11
Thank You!!!

The problem with the code was that lchild and rchild were such that it wasn't getting to null

and about out of range it won't give error as the values are not there that means its null

I would like to share that I have successfully run the code after rectifying the traversal mistake

BIG THANK YOU TO ALL WHO HELPED !!

Mission accomplished !!!
Oct 21 '14 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: MBS | last post by:
I am trying to pass a string from one page to another. The input string comes from a database and many times has the superscript TM trademark symbol. The querystring handles this properly because...
6
by: C++ Shark | last post by:
Hi, which stl class is good for creating search trees? I am looking for something flexible, that allows me to search for a required state (of matrices, graphs, etc.) quickly. thanks in...
2
by: barnesc | last post by:
>barnesc at engr.orst.edu wrote: > > So my question is: are there any other *practical* applications of a > > B-tree based list/set/dict ? In other words, is this module totally > > worth coding,...
4
by: news.microsoft.com | last post by:
In my engineering class we're discussing microprocessor branch predictors. Is it possible to write a Windows application (anything whatsoever) that would allow me see how branch prediction is done...
3
by: ptrSriram | last post by:
Can someone help me with an algorithm to merge two binary search trees. One method I thought of was to flatten both the trees into sorted lists(inorder traversal),merge those two sorted lists,...
0
by: dr3amxstar | last post by:
Hi this might not be totally related but im just trying my luck here. I am doing a project - protein secondary structure prediction using Artificial Neural Network. I have written out the full code,...
9
by: aeismail | last post by:
Hi, everybody: A quick question regarding how to write if/then blocks. Do C++ compilers care in terms of execution (i.e., efficiency) which block in an if/then/else loop is executed? That is,...
17
Ganon11
by: Ganon11 | last post by:
Hey guys, OK, taking care of this beforehand; I AM a student in a university. This IS part of my homework, and (as a moderator), I'm doing my best to follow the posting guidelines I work so hard...
6
by: rsprawls | last post by:
I found a disk for a b-tree algorithm that I purchased back in 93 or so. I'd hoped to find this, but now I'd like to know how worthwhile are b-trees in today's advancements? This is old C code...
7
by: sani kolik | last post by:
I have three tables. I have the following database table with information about symptoms, diseases, and diseaseSymptoms: DISEASE_T SYMPTOMS diseaseSymptoms ========== ========== ========...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.