Skip to content

Instantly share code, notes, and snippets.

@lievcin
Last active February 6, 2018 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lievcin/bfc6debd8fdfc61ab5c444a23bb2a10f to your computer and use it in GitHub Desktop.
Save lievcin/bfc6debd8fdfc61ab5c444a23bb2a10f to your computer and use it in GitHub Desktop.
featureDict = {} # A global dictionary of features
def toFeatureVector(tokens, rating, verified):
# Should return a dictionary containing features as keys, and weights as values
v = {}
for t in tokens:
try:
featureDict[t] += 1
except KeyError:
featureDict[t] = 1
try:
v[t] += (1.0/len(tokens))
except KeyError:
v[t] = (1.0/len(tokens))
v['Rating'] = rating
v['Verified'] = verified
return v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment