473,396 Members | 1,966 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.

How do I design a decision tree?

Seth Schrock
2,965 Expert 2GB
This is a very broad question so all I'm looking for is a few hints of where to start. I need to make a decision tree, but I can't find anything online about how to do that in Access.

I'm trying to make it so that a police officer can determine the exact crime committed by answering some yes/no questions. For example, the crime Driving While Suspended would be the top of the decision tree. The next step would be Has the driver had prior convictions for this crime. Based on the answer to this question, the crime can be either a Class A Misdemeanor or a Class A Felony. This particular decision tree only has one set of questions, but my understanding is that there are other crimes that have more questions depending on the answer given to the first question. I have no idea how to start. I would like to have it so that there is no limit to the number of questions asked as I have no idea what the maximum number would be. Would a tree view control be the thing for this? I know TheSmileyCoder has done a very nice tutorial on this which I could use to help me, but I don't know if this is the way to go.
Dec 23 '12 #1

✓ answered by ADezii

In my opinion, the TreeView Control would be a perfect candidate for this scenario, and it would graphically display all the possible outcomes based on the prior Path(s) taken. Nodes would be expanded/collapsed as the need arises along with a large number of Sub-Levels.

8 8787
zmbd
5,501 Expert Mod 4TB
Seth,

What you are asking for is nothing more than a logic flow chart.

You can implement these in a thousand different ways depending on the complexity of the situation.

What I have is a table... and then I steal from the biologist!
Tbl_kingdom
Tbl_phylum
Tbl_class
Tbl_family]

down to:
tbl_Species
[Species_pk] autonumber
[Species_question] text(250)
[Species_fk_genus] long
[Species_fk_actiontotake] as long

Each of the fields "Species_fk...." is a foreign key to a table of the that name, where in the the FK cascades thru (for example):
tbl_kingdom
[kingdom_pk] autonumber
[kingom_question] text(250)

tbl_phylum
[phylum_pk] autnumber
[phylum_question] text(250)
[phylum_fk_kingdom] long

tbl_class
[class_pk] autonumber
[class_question] text(250)
[class_fk_phylum] long

I only use as many tables a needed...
For a simple logic... maybe just family, genus, species
Always start with genus and species.
One can always add an upper level.

I've yet to find in 20-questions (is it animal, vegetable, or mineral) type logic trees a need for more than the entire thing
(Kingdom: Civil, Criminal)
(Phylum: next classes...)

In the form I've done this a few ways...
Cascading combo boxes (there's an insight article about this).
I have had an occasion where the user didn't like all of the combo boxes and wanted a parent/child type setup...
In that case I used "TABS" with late recordset binding. The first tab is bound to the top level table. When the user double clicks a record in the tab, the tab is "locked" to that choice, the next tab is made visible and it's record set is bound and filtered based on the prior tab, and so forth.
Once the final species tab is set, then I open a form or report based on the action specified.

Then there was the "rolling record set" nightmare... sigh.
The parent form with child.
Initial record sets were the top level table for the parent and the next level for the child.
Make the selection in the parent, then the child, then the child's record set was sent "up" to the parent from, and then the next level down is adopted to be the new child form's record set... the VBA behind this was brutal for me to implement... and when the gentlemen left... I moved this to the late-binding tab form.

How you get the records and subrecords and so forth... in Chemistry, there's usually a method or classification system in place and I follow that. I would hope that there is something similar for your project. Otherwise, time to list all of your final (species) questions that lead to an action and then sort those by type (genus), see if those have a relationship (family) and so forth.
Dec 23 '12 #2
NeoPa
32,556 Expert Mod 16PB
I cannot comment on the TreeView control approach, as I know little about that (them).

However, what I would do is build a table of offenses and a table of questions, then treat the two as joined in a many-to-many (M:N) link by building a JOIN table between the two which includes a reference to the offense, a reference to the question, and some information as to what type of answer indicates the offense should be thus identified. One question should have links to all the offenses. This will always be the first question asked.

For instance, a Yes/No question would simply be identified as a simple Yes or No, whereas a count of existing offenses may require a particular value above which this offense is triggered. A multiple choice string value would require one of the valid choices, which could be of any data format. The value stored must match the type of question it's associated with.

The first question asked should be one that all offenses have a value for. From the answer to the first question you go through the loop until only one offense is left :
  1. Find the question that is required for the most number of offenses that are still possible and that hasn't already been asked. The first time through the loop should always find the same question which is common to all offenses.
  2. Filter the offenses by the result of that question.
  3. If the number of offenses left is still multiple then loop back to step #1.
  4. Unless the data has been entered incorrectly you should have a single valid offense remaining. Bingo.

This approach gives almost unlimited flexibility as well as the ability to upgrade and change at will. It does, however, rely a fair bit on code logic rather than simple SQL and data structure.
Dec 23 '12 #3
ADezii
8,834 Expert 8TB
In my opinion, the TreeView Control would be a perfect candidate for this scenario, and it would graphically display all the possible outcomes based on the prior Path(s) taken. Nodes would be expanded/collapsed as the need arises along with a large number of Sub-Levels.
Dec 23 '12 #4
Seth Schrock
2,965 Expert 2GB
Thankfully, I don't have to have the database count if there are prior records. The officer has to look it up on their system and they will just answer yes or no if there were past offenses. Also, if I'm understanding Z's and NeoPa's responses, the questions would need to be similar for the all of the crimes (ie first question is the species animal, vegetable or mineral), but I won't have that. Each crime will have its own particular set of questions. If some of the questions are the same, it is a coincidence. Similar to a file path on the computer. Each main crime would be a different drive letter and you would need to drill down through the folders (questions) until you find the file (the specific crime). Also similar to a file path, some folders might have the same name, but it is just a coincidence. That is why I thought of the tree view.
Dec 23 '12 #5
zmbd
5,501 Expert Mod 4TB
You have to have a way to classify the questions.

Take a look at the following where in each subsection lead to to the next... let's take stalking:
Kingdom: http://www.law.cornell.edu/uscode/text/18
Phylum: http://www.law.cornell.edu/uscode/text/18/part-I
Class: http://www.law.cornell.edu/uscode/te...I/chapter-110A
Family: http://www.law.cornell.edu/uscode/text/18/2261A
Genus: ... well there wasn't one for this site; however, insert next level
Species: ... once again you get more specific.

Take a look at a biological or chemical nomenclature chart... it flows much like the tree-view control with the branching.
IN that the same question might apply to more than one type of case would mean a simple modification to my system wherein the grandparent-fk, the parent-fk, are referenced and I use a question table against the child

tbl_species
[species_pk]
[species_fk_family] (grandparent table 1:m)
[species_fk_genus] (parent table 1:m)
[species_fk_standard_questions]

Tbl_standard_questions
[standard_questions_pk]
[standard_question_text]

I've only had to do this once! Conceivably, one could add the great-grandparent and so forth; however, that adds to the complexity.
I corrected the issue by adding the next higher grouping table after having gone thru all of the questions in each group several times.

In any case, you have to have a means of classification. Now I pulled on the USC code because I'm very familiar with it... note that I could have gotten away with one fewer table to get to the stalking; however, the extra tables allow you add criteria etc... You should have a codification of criminal code upon which to base the logic tree
Dec 23 '12 #6
NeoPa
32,556 Expert Mod 16PB
Seth:
Also, if I'm understanding Z's and NeoPa's responses, the questions would need to be similar for the all of the crimes
Not at all Seth. The flexibility is there to have commonality of questions across all the crimes, just as well as to have a separate set for each type of crime, or anything in between. Nothing about the design restricts it to either end of the spectrum. Your data alone specifies what links to what. That is the beauty of a data-driven approach (such as this).
Dec 23 '12 #7
Seth Schrock
2,965 Expert 2GB
Okay. I think that I will stick with the tree view as it doesn't require a lot of code and doesn't require a bunch of tables either. I also have a tutorial to help me out which helps greatly. Here is the link if anyone wants to watch: Treeview in Access Part 1
Dec 23 '12 #8
NeoPa
32,556 Expert Mod 16PB
I'm not going to argue with that choice Seth :-) If the TreeView controls do the business for you in a straightforward way, and that was your original thinking anyway, it seems an ideal choice.
Dec 23 '12 #9

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

Similar topics

0
by: | last post by:
Hi everyone, Just wanted your expert opinion on the following: I'm implementing an authorization system with user/group permissions stored in a database. I have a Users table and a Group...
0
by: Riki A | last post by:
hi there anyone has any idea of the decision tree algorith implemented in C++, besides the C45. i would appreciate any help i could get from u guys. thanks in advance
1
by: Jim Adams | last post by:
I'm just starting an ASP.Net question and answer driven decision tree / wizard. e.g. Is it A or B? If A -> Is it 1 or 2? If 1 -> Is it 3 or 4? ... If 2 -> Is it 5 or 6? ...
5
by: Daniel | last post by:
I am trying to find all possible routes between two points on a tree using a top to bottom search only. The tree looks like this: ' 1 ' / \ ...
10
by: Will Honea | last post by:
I have a data set which I need to analyze but I am having a problem figuring out a structure for the database - or whether there are better ways of attacking the problem. The base data set is a...
5
by: __PPS__ | last post by:
Hello all, I was working on someone else's code to implement some classes. The task seemed to be simple and I was confident that I won't spent alot of time on that task... But! I've already spent...
6
by: Smithers | last post by:
In consideration of a "Utilities" class that contains methods intended to be used amongst multiple projects... Is there any general consensus on whether such a class should be static? I have...
1
by: almurph | last post by:
Hi, I'm looking for a C# implementation of the C4.5 algorithm or failing that, a pseudocode implementation easy enough that I could implement in C# (I'm pretty new to decision trees, so it would...
5
by: nehap | last post by:
I am doing project in DataMining.Can I get the source code for Binary Decision Tree algorithm in JAVA using some Dataset?
18
by: kaushik1221 | last post by:
I want to know how can we parse a string with braces of the form((Question)(Left_Node)(right_node)). The "question" for example will be of the form if segment size < 1.5,then choose left node,else...
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: 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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.