\begin{figure}
\begin{alltt}
function Training(data)
  counts = array()
  classes = array()
  
  for(row in data)
    for(column in row)
      counts[column.index][column.value][row.class]++
      classes[row.class]++
  return \{classes, counts\}  
    
function Testing(data, model)
  classes = model.classes
  counts = model.counts

  for(row in data)
    scores = array()
    for(class in classes)
      score = classes[class] / training.length
    
      for(column in row)
        score *= counts[column.index][row[column.index]][row.class] / classes[class]
      scores[class] = score
    
    classWithMaxScore = maximum(scores)
    results += (classWithMaxScore == row.class)

  return results
  
function NaiveBayes(data)
  model = Training(data)
  return Testing(data, model)
\end{alltt}
\caption{Pseudo code of Naive Bayes}\label{fig:pseudoCode-naivebayes}
\end{figure}
