Last active
February 6, 2018 14:55
-
-
Save lievcin/bfc6debd8fdfc61ab5c444a23bb2a10f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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