title: Creating a feature dictionary for Python machine learning (naive bayes) algorithm
body: <p>I would like predict, for example, Chinese vs. non-Chinese ethnicities using last names. Particularly I want to extract three-letter substrings from the last names. So for example, the last name "gao" will give one feature as "gao" while "chan" will give two features as "cha" and "han".</p>
  
  <p>The splitting is successfully done in the three_split function below. But as far as I understand, to incorporate this as a feature set I need to return the output as dictionary. Any hints of how to do that? For the dictionary of "Chan", the dictionary should return "cha" and "han" as TRUE.</p>
  
  <pre><code>from nltk.classify import PositiveNaiveBayesClassifier
  import re
  
  chinese_names = ['gao', 'chan', 'chen', 'Tsai', 'liu', 'Lee']
  
  nonchinese_names = ['silva', 'anderson', 'kidd', 'bryant', 'Jones', 'harris', 'davis']
  
  def three_split(word):
      word = word.lower()
      word = word.replace(" ", "_")
      split = 3
      return [word[start:start+split] for start in range(0, len(word)-2)]
  
  positive_featuresets = list(map(three_split, chinese_names))
  unlabeled_featuresets = list(map(three_split, nonchinese_names))
  classifier = PositiveNaiveBayesClassifier.train(positive_featuresets, 
      unlabeled_featuresets)
  
  print three_split("Jim Silva")
  print classifier.classify(three_split("Jim Silva"))
  </code></pre>