\begin{figure}
\begin{alltt}
function Training(data)
  training = data

function Testing(data)
  for(row in data)
    knn = k nearest neighbors from training to row
    knn = ApplyWeighting(knn, row)
    results += Classify(knn, row)
  return results
     
function ApplyWeighting(data, testRow)
  for(row in data)
    row.weight = row.distanceFrom(testRow) / maxDistanceFromTest
    
function Classify(training, testingRow)
  counts = array()
  classes = array()
  
  for(row in training)
    for(column in row)
      counts[column.index][column.value][row.class]++
      classes[row.class]++
      
  for(class in classes)
    score = classes[class] / training.length
    
    for(column in testingRow)
      score *= counts[column.index][testingRow[column.index]][testingRow.class] / 
               classes[class]

  return classWithMaxScore == testingRow.class
\end{alltt}
\caption{Pseudo code of Locally Weighted Naive Bayes}\label{fig:pseudoCode-lwl}
\end{figure}
