In this section, we will implement a program calculating the probability of a data item belonging to a certain class by using Bayes' theorem:
# source_code/2/naive_bayes.py # A program that reads the CSV file with the data and returns # the Bayesian probability for the unknown value denoted by ? to # belong to a certain class. # An input CSV file should be of the following format: # 1. items in a row should be separated by a comma ',' # 2. the first row should be a heading - should contain a name for each # column of the data. # 3. the remaining rows should contain the data itself - rows with # complete and rows with the incomplete data. # A row with complete data is the row that has a non-empty and # non-question mark value for each column. A row with incomplete data is # the row that has the last column with the value...