[Tutor] Medical Decision-Making Question
Steven D'Aprano
steve at pearwood.info
Mon Jun 13 17:52:47 CEST 2011
Fred G wrote:
> Hello--
>
> I'm a pre-med student interested in decision-making as applied to medical
> decisions. I am trying to build a medical decision-making algorithm and am
> pretty stuck on a few things.
Essentially what you want is to build an expert system. I don't want to
discourage you, but expert systems are big, complicated pieces of
software! They're a form of artificial intelligence. You probably want
to think hard about how to narrow the problem you're trying to solve.
You could google on "python expert system ai" are similar terms, see
what comes up. Other search terms might include "inference engine": you
want the software to *infer* a disease from a set of symptoms.
Another possibility is to look at "logic programming". Traditionally
people do that in Prolog, but there are some tools for doing this in
Python. Google on "prolog python", or look at Pyke:
http://pyke.sourceforge.net/
More comments below.
> I've built a file that contains a list of many diseases and their associated
> symptoms. For example, here are the column headers and two sample rows (the
> "|" = "or"):
> Disease Symptoms
> Cold
> sore_throat|runny_nose|congestion|cough|aches|slight_fever
> Flu
> sore_throat|fever|headache|muscle_aches|soreness|congestion|cough|returning_fever
>
> My questions are the following:
> a) How's the best way to make it so I can have a user type in a list of
> symptoms and then have the computer tell the user the possible diseases that
> share those symptoms? In other words, on a high-level I have a pretty good
> idea of what I want my algorithm to do-- but I need help implementing the
> basic version first. I'd like to do the following:
>>>> Please enter a list of symptoms
>>>> [user_input]
>>>> Possible diseases include: x, y, z
First you need to decide, how would *you* decide which diseases are
possible?
My *guess* is that you would do something like this:
for each symptom given:
for each disease:
if the symptom appears in the disease,
then add disease to the list of possible diseases
But should some symptoms count as stronger than others? I don't know.
Here is a toy example, presented without explanation because it's 1:50am
here in Australia and I'm getting tired. I don't know whether you are a
beginner at Python or you've been programming for years, so don't
hesitate to ask if you don't understand any of it!
# Untested!
class Disease:
def __init__(self, name, symptoms):
self.name = name
self.symptoms = symptoms
known_diseases = [
Disease('cold', set(
"sore throat|runny nose|congestion|cough|aches".split("|"))
),
Disease('flu', set(
"fever|headache|muscle aches|returning fever".split("|"))
),
Disease('ebola', set(
"tiredness|death|bruising over 90% of body|black blood".split("|"))
),
]
# note: for Python 2, use "raw_input" instead of input
symptoms = input("Please enter symptoms separated by commas: ")
symptoms = symptoms.lower()
symptoms = symptoms.split(",")
possible = []
for symptom in symptoms:
for disease in known_diseases:
if symptom in disease.symptoms:
possible.append(disease.name)
if possible:
print("You may have these diseases:")
print(*possible)
else:
print("Good news! You're going to have a disease named after you!")
Obviously in a real project, you would read the diseases from a file, or
store them in a database.
> b)Once I get that working, could anyone point me to good code already
> written in Python such that I could have a model (for syntax and overall
> structure) for figuring out how to make the computer evaluate more factors
> such as: patient age, patient history, and even downloading archival data
> for patients in the same demographic group?
Well, I must say you're certainly ambitious! This is a *hard problem*,
which is why expert systems usually cost a lot of money.
Start by writing down how a human doctor would combine these pieces of
information. Think about whether there are "anti-indicators", e.g. "if
the patient doesn't have spots, it can't be measles!" (or maybe it can,
I'm not a doctor...).
Age, history, demographics, etc. can be treated just like symptoms. "If
the patient is male, he can't be pregnant." (Although there are such
things as false pregnancies, and even men can get that!)
My guess is that doctors will first try to think of all the diseases it
could be, and then eliminate those it can't be, and then take a
probabilistic estimate (i.e. a guess) from those left over. E.g.:
If the patient has the symptoms of ebola, and has been to Africa in the
last month, or works with monkeys or in germ warfare, then the chances
of ebola are 95%; otherwise the chances of ebola are 1%.
Google on Bayesian probability and Bayes Theorem.
Also look at fuzzy logic. That's another good approach for expert system
problem solving.
The problem you are likely to face is not that there's no good way to
decide which diseases are likely, but that there are too many competing
ways.
Good luck!
--
Steven
More information about the Tutor
mailing list