Select your font size 
 
about us products & services consulting & support news & events contact us
Paul Meagher shows how to use a database query to calculate conditional probability.

Conditional Probability and SQL - Ontario

print this article 
 

P(A | B) can be mapped onto database-query operations. For example, the probability of cancer given a positive test result, P(+cancer | +test), can be obtained by issuing this SQL query then doing some tallies on the result set like this:

SELECT cancer_status FROM Data WHERE test_status='+test'

If I gather information about how several boolean-valued tests co-vary with a boolean-valued diagnosis (like that of cancer or not cancer), then I can perform slightly more complex queries to study how diagnostically useful other factors are in determining whether a patient has cancer, such as in the following:

SELECT cancer_status FROM Data WHERE genetic_status='+' AND age_status='+' AND biopsy_status='+'

In the case of detecting e-mail spam, I might be interested in computing P(+spam | title_word='viagra' AND title_word='free'), which could be viewed as a directive to issue the following SQL query:

SELECT spam_status FROM Emails WHERE email_title LIKE 'viagra' AND email_title LIKE 'free' 

After enumerating the number of e-mails that are spam and have "viagra" and "free" in the title (like so):

count_emails(spam_status='+spam' AND email_title LIKE 'viagra' AND email_title LIKE 'free')

and dividing by the overall number of e-mails with the words "viagra" and "free" in the title:

count_emails(email_title LIKE 'viagra' AND email_title LIKE 'free')

I might arrive at the conclusion that the appearence of these words in the title strongly and specifically co-varies with the message being spam (after all, 18/18 = 100 percent) and this rule might be used to automatically filter such messages.

In Bayes spam filtering, you need to initially train the software in which e-mails are spam and which are not. One can imagine storing spam_status information with each e-mail record (for example, email_id, spam_status, email_title, or email_message) and doing the previous queries and counts on this data to decide whether to forward a new e-mail into your inbox.



Page:   1  2  3  4  5  6  7  8  9  10  11 Next Page: Frequency versus probability format

The content shown in this page was first published by IBM developerWorks and is reprinted with permission from Paul Meagher (www.datavore.com)


Most Recent Website and Regional Updates

 Transparen Corporation Canada Day Celebrations July 1, 2006
Transparen Corp. is proud of its Canadian heritage, and gladly celebrates Canada Day every year. Look back at previous Canada Days to learn about Transparen's history.

 
 Timing Upgrades - Factors Affecting Time Between Purchases for Tech Toys
It is possible to understand client purchase decisions by performing a regression analysis. By forming strategies based on the results, companies can optimize strategic programs to maximize profits.

 
 Federal Candidates Weigh In On Fairness
McGuinty government posts responses to Ontario?s call for fairness.

 
 Ontario Pays Tribute To Fallen Firefighters
McGuinty government honours families at Queen?s Park, fire fighter memorial.

 
 Ontario Celebrates Its Olympic Athletes
Premier McGuinty Passes The Torch With Pan Am Bid

 
 Ontario Supports Craft Brewers
The Government of Ontario is making an $8-million commitment to help ensure the prosperity of small brewers for many years to come.

 
 New Honda Engine Plant Drives Green Jobs
McGuinty Government Calls Plant A Vote Of Confidence In Ontario?s Skilled Workers

 
 Turning Innovation Into Ontario Jobs
Today, the government intends to introduce Ideas for the Future Act, 2008, that, if passed, would provide a 10-year corporate income tax exemption for new companies that turn home-grown ideas into Ontario jobs and products.

 
 Speaking Up For Ontario
Premier urges Ontarians to sign petition and stand up for fairness.

 
 Improving Care for Ontario?s Youngest Patients
McGuinty Government Improving Access To Care And Reducing Wait Times For Kids

 
 Moving Ontario Forward, Together
McGuinty Government?s Latest Progress Report Tells Stories Of Real People

 
 Making Ontario More Competitive At Home And Abroad
Cabinet Shuffle Focuses On Strengthening Economy

 

Google
 
Web transparen.com

Contact Information

Related Information

 
  TORONTO ON
LONDON ON
OTTAWA ON
HAMILTON ON
 
 
E C M | © 2003-2007 Transparen Corp.      

Standardized Services: Data Recovery Service / Creative Services / Premium Web Hosting Services / System Administration Tech Support Services
Recent Projects: Full-Service Mortgage and Financing Company / System to manage flights from Vancouver to Tofino / Photo exchange verification service
Our Vancouver BC Server Proudly Hosts: automated parking and revenue control systems, leafside lane at southlands, cost effective alternative power sources, the photo genie, pacific forage bag supply, sunburst medical, neosonic design, roger mahler photography - passionate, intriguing, desirable, the connection between east and west, affordable flights to victoria and tofino, low interest mortgage brokers in vancouver, richmond, surrey, toronto, mortgage brokers in calgary
Toronto, Ottawa, Kanata, Hamilton, London - view entire list