Commits

Timo Sulg  committed d501bbf

Added some datamining examples, which are taken from book "Programming Collective Intelligence in Python."

  • Participants
  • Parent commits 7e75886

Comments (0)

Files changed (12)

File Chapter7/addresslist.txt

+6 Washington
+21 Manassas
+280 Pearl
+55 Ellery
+50 Follen
+51 Granite
+992 Memorial
+83 Trowbridge
+1 Dana
+45 Regent
+90 Alpine
+21 Francis
+112 Avon Hill
+9 Bellevue
+4 Blanchard Rd
+34 Shea
+5 Fountain
+14 Marcella
+39 Saint Saveur
+35 Pemberton
+46 Shepard
+31 Market
+99 Howard
+88 Pearl
+208 Western
+285 Windsor
+26 Cambridgepark
+211 Erie
+129 Franklin
+27 Gurney
+149 Prospect
+27 Linnaean
+20 Dudley
+60 Otis St
+130 Mount Auburn St
+2 Michael Way
+263 Columbia St
+6 Hurlbut St
+199 Harvard St
+168 River St
+400 Washington St
+12 Traill St
+74 Field St
+21 Walden Square Rd
+7 Wendell St
+15 Normandy Ave
+6 Gibson Ter
+94 Pine St
+23 Magee St
+175 Richdale Ave
+168 River St
+246 Brattle St

File Chapter7/advancedclassify.py

+class matchrow:
+  def __init__(self,row,allnum=False):
+    if allnum:
+      self.data=[float(row[i]) for i in range(len(row)-1)]
+    else:
+      self.data=row[0:len(row)-1]
+    self.match=int(row[len(row)-1])
+
+def loadmatch(f,allnum=False):
+  rows=[]
+  for line in file(f):
+    rows.append(matchrow(line.split(','),allnum))
+  return rows
+ 
+from pylab import *
+def plotagematches(rows):
+  xdm,ydm=[r.data[0] for r in rows if r.match==1],\
+          [r.data[1] for r in rows if r.match==1]
+  xdn,ydn=[r.data[0] for r in rows if r.match==0],\
+          [r.data[1] for r in rows if r.match==0] 
+  
+  plot(xdm,ydm,'bo')
+  plot(xdn,ydn,'b+')
+  
+  show()
+
+def lineartrain(rows):
+  averages={}
+  counts={}
+  
+  for row in rows:
+    # Get the class of this point
+    cl=row.match
+    
+    averages.setdefault(cl,[0.0]*(len(row.data)))
+    counts.setdefault(cl,0)
+    
+    # Add this point to the averages
+    for i in range(len(row.data)):
+      averages[cl][i]+=float(row.data[i])
+      
+    # Keep track of how many points in each class
+    counts[cl]+=1
+    
+  # Divide sums by counts to get the averages
+  for cl,avg in averages.items():
+    for i in range(len(avg)):
+      avg[i]/=counts[cl]
+  
+  return averages
+
+def dotproduct(v1,v2):
+  return sum([v1[i]*v2[i] for i in range(len(v1))])
+
+def veclength(v):
+  return sum([p**2 for p in v])
+
+def dpclassify(point,avgs):
+  b=(dotproduct(avgs[1],avgs[1])-dotproduct(avgs[0],avgs[0]))/2
+  y=dotproduct(point,avgs[0])-dotproduct(point,avgs[1])+b
+  if y>0: return 0
+  else: return 1
+
+def yesno(v):
+  if v=='yes': return 1
+  elif v=='no': return -1
+  else: return 0
+  
+def matchcount(interest1,interest2):
+  l1=interest1.split(':')
+  l2=interest2.split(':')
+  x=0
+  for v in l1:
+    if v in l2: x+=1
+  return x
+
+yahookey="YOUR API KEY"
+from xml.dom.minidom import parseString
+from urllib import urlopen,quote_plus
+
+loc_cache={}
+def getlocation(address):
+  if address in loc_cache: return loc_cache[address]
+  data=urlopen('http://api.local.yahoo.com/MapsService/V1/'+\
+               'geocode?appid=%s&location=%s' %
+               (yahookey,quote_plus(address))).read()
+  doc=parseString(data)
+  lat=doc.getElementsByTagName('Latitude')[0].firstChild.nodeValue
+  long=doc.getElementsByTagName('Longitude')[0].firstChild.nodeValue  
+  loc_cache[address]=(float(lat),float(long))
+  return loc_cache[address]
+
+def milesdistance(a1,a2):
+  lat1,long1=getlocation(a1)
+  lat2,long2=getlocation(a2)
+  latdif=69.1*(lat2-lat1)
+  longdif=53.0*(long2-long1)
+  return (latdif**2+longdif**2)**.5
+
+def loadnumerical():
+  oldrows=loadmatch('matchmaker.csv')
+  newrows=[]
+  for row in oldrows:
+    d=row.data
+    data=[float(d[0]),yesno(d[1]),yesno(d[2]),
+          float(d[5]),yesno(d[6]),yesno(d[7]),
+          matchcount(d[3],d[8]),
+          milesdistance(d[4],d[9]),
+          row.match]
+    newrows.append(matchrow(data))
+  return newrows
+
+def scaledata(rows):
+  low=[999999999.0]*len(rows[0].data)
+  high=[-999999999.0]*len(rows[0].data)
+  # Find the lowest and highest values
+  for row in rows:
+    d=row.data
+    for i in range(len(d)):
+      if d[i]<low[i]: low[i]=d[i]
+      if d[i]>high[i]: high[i]=d[i]
+  
+  # Create a function that scales data
+  def scaleinput(d):
+     return [(d[i]-low[i])/(high[i]-low[i])
+            for i in range(len(low))]
+  
+  # Scale all the data
+  newrows=[matchrow(scaleinput(row.data)+[row.match])
+           for row in rows]
+  
+  # Return the new data and the function
+  return newrows,scaleinput
+
+
+def rbf(v1,v2,gamma=10):
+  dv=[v1[i]-v2[i] for i in range(len(v1))]
+  l=veclength(dv)
+  return math.e**(-gamma*l)
+
+def nlclassify(point,rows,offset,gamma=10):
+  sum0=0.0
+  sum1=0.0
+  count0=0
+  count1=0
+  
+  for row in rows:
+    if row.match==0:
+      sum0+=rbf(point,row.data,gamma)
+      count0+=1
+    else:
+      sum1+=rbf(point,row.data,gamma)
+      count1+=1
+  y=(1.0/count0)*sum0-(1.0/count1)*sum1+offset
+
+  if y>0: return 0
+  else: return 1
+
+def getoffset(rows,gamma=10):
+  l0=[]
+  l1=[]
+  for row in rows:
+    if row.match==0: l0.append(row.data)
+    else: l1.append(row.data)
+  sum0=sum(sum([rbf(v1,v2,gamma) for v1 in l0]) for v2 in l0)
+  sum1=sum(sum([rbf(v1,v2,gamma) for v1 in l1]) for v2 in l1)
+  
+  return (1.0/(len(l1)**2))*sum1-(1.0/(len(l0)**2))*sum0

File Chapter7/agesonly.csv

+24,30,1
+30,40,1
+22,49,0
+43,39,1
+23,30,1
+23,49,0
+48,46,1
+23,23,1
+29,49,0
+38,38,1
+30,34,1
+40,50,1
+35,32,1
+49,44,1
+38,22,1
+30,27,1
+26,24,1
+39,23,1
+36,43,1
+25,31,1
+27,27,1
+32,22,1
+40,30,1
+26,28,1
+46,32,1
+41,37,1
+39,41,1
+18,28,0
+18,47,0
+39,44,1
+38,21,1
+24,36,0
+32,22,1
+21,20,1
+42,36,1
+46,41,1
+39,38,1
+18,31,0
+31,45,1
+44,24,0
+49,22,0
+26,27,1
+25,34,1
+47,23,0
+27,48,0
+32,49,1
+46,41,1
+24,32,1
+29,26,1
+25,36,1
+27,35,1
+38,19,1
+18,40,0
+34,49,1
+32,35,1
+47,49,1
+47,18,0
+33,24,1
+35,28,1
+35,41,1
+39,43,1
+29,18,1
+18,44,0
+26,26,1
+31,43,1
+20,29,0
+28,18,1
+31,38,1
+34,34,1
+32,33,1
+34,27,1
+19,38,0
+32,21,1
+33,37,1
+33,18,1
+18,46,0
+31,37,1
+36,30,1
+40,40,1
+38,30,1
+49,28,1
+31,47,1
+28,50,0
+49,43,1
+24,31,1
+33,43,1
+28,24,1
+45,29,1
+49,35,1
+36,29,1
+42,32,1
+29,18,1
+49,20,0
+22,27,1
+41,38,1
+47,21,0
+40,32,1
+35,18,1
+35,33,1
+34,28,1
+22,31,0
+46,20,0
+18,49,0
+48,23,0
+39,21,1
+20,34,0
+24,20,1
+38,18,1
+37,47,1
+39,37,1
+38,39,1
+27,42,1
+47,49,1
+27,42,1
+40,28,1
+41,46,1
+39,25,1
+43,36,1
+49,30,1
+24,38,0
+49,42,1
+19,22,0
+43,27,1
+30,37,1
+24,31,1
+24,48,0
+24,29,1
+18,19,1
+29,25,1
+38,33,1
+39,20,1
+24,30,1
+22,39,0
+47,21,0
+30,44,1
+41,38,1
+29,33,1
+42,42,1
+47,27,1
+23,20,1
+39,18,1
+30,26,1
+36,27,1
+40,18,1
+31,18,1
+46,27,1
+41,44,1
+26,34,1
+33,18,1
+48,19,0
+46,27,1
+25,40,0
+50,36,1
+20,21,1
+33,47,1
+40,35,1
+24,27,1
+34,19,1
+26,45,0
+34,36,1
+21,27,0
+48,28,1
+23,25,1
+48,46,1
+30,20,1
+23,40,0
+36,40,1
+21,45,0
+30,40,1
+39,24,1
+42,47,1
+28,37,1
+24,30,1
+37,25,1
+44,34,1
+43,32,1
+46,29,1
+49,22,0
+41,28,1
+23,50,0
+30,43,1
+25,32,1
+27,46,0
+23,21,1
+39,41,1
+33,27,1
+49,21,0
+33,33,1
+18,25,0
+42,35,1
+36,25,1
+26,50,0
+18,37,0
+35,37,1
+39,38,1
+22,30,0
+18,44,0
+46,44,1
+24,27,1
+41,34,1
+40,39,1
+34,49,1
+35,41,1
+46,48,1
+50,23,0
+49,20,0
+22,47,0
+27,26,1
+30,30,1
+37,39,1
+42,44,1
+41,27,1
+24,21,1
+34,28,1
+23,43,0
+43,35,1
+42,40,1
+25,24,1
+36,24,1
+25,23,1
+44,30,1
+39,33,1
+38,33,1
+49,30,1
+40,19,1
+19,46,0
+31,21,1
+48,33,1
+26,24,1
+20,37,0
+29,31,1
+35,28,1
+37,25,1
+42,42,1
+42,48,1
+41,47,1
+44,45,1
+45,46,1
+25,38,1
+19,45,0
+36,26,1
+33,36,1
+27,19,1
+48,24,0
+37,48,1
+23,31,0
+20,29,0
+27,44,0
+47,24,0
+36,18,1
+37,48,1
+32,29,1
+46,48,1
+31,47,1
+23,45,0
+28,30,1
+36,32,1
+25,43,0
+24,44,0
+34,47,1
+46,42,1
+18,31,0
+23,25,1
+44,39,1
+18,29,0
+49,40,1
+24,33,0
+21,44,0
+40,24,1
+46,41,1
+42,33,1
+25,41,0
+29,42,1
+40,18,1
+37,40,1
+46,28,1
+33,20,1
+18,42,0
+22,36,0
+27,46,0
+33,48,1
+21,37,0
+26,50,0
+29,23,1
+23,33,0
+21,38,0
+18,30,0
+29,28,1
+31,22,1
+30,48,1
+41,37,1
+35,31,1
+48,32,1
+29,37,1
+32,33,1
+43,26,1
+21,33,0
+44,28,1
+35,18,1
+35,35,1
+25,20,1
+39,46,1
+26,39,1
+36,29,1
+29,44,1
+28,42,1
+38,21,1
+28,49,0
+33,26,1
+31,28,1
+25,47,0
+23,25,1
+45,49,1
+28,26,1
+36,48,1
+42,48,1
+42,21,1
+29,32,1
+26,28,1
+24,46,0
+39,30,1
+29,46,1
+43,43,1
+20,42,0
+35,41,1
+45,19,0
+38,45,1
+25,38,1
+31,20,1
+38,43,1
+37,30,1
+43,27,1
+43,44,1
+21,30,0
+22,45,0
+44,26,1
+43,42,1
+26,41,0
+47,35,1
+48,30,1
+41,24,1
+19,48,0
+45,24,0
+38,41,1
+42,46,1
+49,45,1
+28,44,1
+22,44,0
+31,48,1
+48,21,0
+31,20,1
+30,39,1
+23,23,1
+21,32,0
+19,19,1
+21,27,0
+24,46,0
+25,28,1
+48,50,1
+25,32,1
+26,29,1
+33,48,1
+35,32,1
+48,25,1
+30,27,1
+34,49,1
+40,45,1
+28,32,1
+47,33,1
+29,33,1
+21,22,1
+21,39,0
+41,45,1
+46,39,1
+22,24,1
+32,22,1
+27,46,0
+26,35,1
+27,29,1
+48,19,0
+35,26,1
+42,29,1
+30,22,1
+20,26,0
+33,25,1
+37,30,1
+37,32,1
+20,22,1
+42,48,1
+29,20,1
+32,46,1
+37,34,1
+29,45,1
+19,44,0
+49,18,0
+28,25,1
+48,31,1
+35,46,1
+34,26,1
+38,26,1
+36,31,1
+31,30,1
+27,19,1
+44,38,1
+19,37,0
+43,49,1
+19,42,0
+32,24,1
+46,43,1
+43,46,1
+33,32,1
+23,35,0
+26,34,1
+48,20,0
+45,38,1
+30,30,1
+28,23,1
+43,36,1
+19,37,0
+39,45,1
+20,30,0
+28,30,1
+19,42,0
+41,21,1
+42,31,1
+47,45,1
+42,48,1
+40,22,1
+28,20,1
+22,31,0
+28,24,1
+18,33,0
+42,47,1
+35,18,1
+32,28,1
+45,39,1
+46,45,1
+41,43,1
+24,37,0
+34,30,1
+40,22,1
+38,20,1
+43,28,1
+21,26,0
+35,27,1
+33,37,1
+48,39,1
+47,40,1
+31,32,1
+18,32,0
+31,20,1
+30,49,1
+22,46,0
+36,39,1
+30,35,1
+49,50,1
+46,39,1
+45,44,1
+34,40,1
+27,28,1
+27,35,1
+46,46,1
+26,42,0
+27,18,1
+23,38,0
+30,30,1
+34,32,1
+48,27,1
+31,23,1
+29,47,0
+47,31,1
+35,19,1
+30,28,1
+33,44,1
+36,37,1
+34,44,1
+42,43,1
+36,29,1
+35,46,1
+22,36,0
+39,47,1
+23,23,1
+47,20,0
+38,22,1
+21,33,0
+37,41,1
+18,18,1
+35,34,1
+49,49,1
+33,32,1
+31,19,1
+31,26,1
+45,31,1
+41,44,1
+27,47,0
+28,26,1
+18,47,0
+37,18,1
+20,42,0
+36,45,1

File Chapter7/ebaypredict.py

+import httplib
+from xml.dom.minidom import parse, parseString, Node
+
+devKey = 'YOUR DEV KEY'
+appKey = 'YOUR APP KEY'
+certKey = 'YOUR CERT KEY'
+serverUrl = 'api.ebay.com'
+userToken = 'YOUR TOKEN'
+
+def getHeaders(apicall,siteID="0",compatabilityLevel = "433"):
+  headers = {"X-EBAY-API-COMPATIBILITY-LEVEL": compatabilityLevel,	
+             "X-EBAY-API-DEV-NAME": devKey,
+             "X-EBAY-API-APP-NAME": appKey,
+             "X-EBAY-API-CERT-NAME": certKey,
+             "X-EBAY-API-CALL-NAME": apicall,
+             "X-EBAY-API-SITEID": siteID,
+             "Content-Type": "text/xml"}
+  return headers
+
+def sendRequest(apicall,xmlparameters):
+  connection = httplib.HTTPSConnection(serverUrl)
+  connection.request("POST", '/ws/api.dll', xmlparameters, getHeaders(apicall))
+  response = connection.getresponse()
+  if response.status != 200:
+    print "Error sending request:" + response.reason
+  else: 
+    data = response.read()
+    connection.close()
+  return data
+
+def getSingleValue(node,tag):
+  nl=node.getElementsByTagName(tag)
+  if len(nl)>0:
+    tagNode=nl[0]
+    if tagNode.hasChildNodes():
+      return tagNode.firstChild.nodeValue
+  return '-1'
+
+
+def doSearch(query,categoryID=None,page=1):
+  xml = "<?xml version='1.0' encoding='utf-8'?>"+\
+        "<GetSearchResultsRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">"+\
+        "<RequesterCredentials><eBayAuthToken>" +\
+        userToken +\
+        "</eBayAuthToken></RequesterCredentials>" + \
+        "<Pagination>"+\
+          "<EntriesPerPage>200</EntriesPerPage>"+\
+          "<PageNumber>"+str(page)+"</PageNumber>"+\
+        "</Pagination>"+\
+        "<Query>" + query + "</Query>"
+  if categoryID!=None:
+    xml+="<CategoryID>"+str(categoryID)+"</CategoryID>"
+  xml+="</GetSearchResultsRequest>"
+  
+  data=sendRequest('GetSearchResults',xml)
+  response = parseString(data)
+  itemNodes = response.getElementsByTagName('Item');
+  results = []
+  for item in itemNodes:
+    itemId=getSingleValue(item,'ItemID')
+    itemTitle=getSingleValue(item,'Title')
+    itemPrice=getSingleValue(item,'CurrentPrice')
+    itemEnds=getSingleValue(item,'EndTime')
+    results.append((itemId,itemTitle,itemPrice,itemEnds))
+  return results
+
+
+def getCategory(query='',parentID=None,siteID='0'):
+  lquery=query.lower()
+  xml = "<?xml version='1.0' encoding='utf-8'?>"+\
+        "<GetCategoriesRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">"+\
+        "<RequesterCredentials><eBayAuthToken>" +\
+        userToken +\
+        "</eBayAuthToken></RequesterCredentials>"+\
+        "<DetailLevel>ReturnAll</DetailLevel>"+\
+        "<ViewAllNodes>true</ViewAllNodes>"+\
+        "<CategorySiteID>"+siteID+"</CategorySiteID>"
+  if parentID==None:
+    xml+="<LevelLimit>1</LevelLimit>"
+  else:
+    xml+="<CategoryParent>"+str(parentID)+"</CategoryParent>"
+  xml += "</GetCategoriesRequest>"
+  data=sendRequest('GetCategories',xml)
+  categoryList=parseString(data)
+  catNodes=categoryList.getElementsByTagName('Category')
+  for node in catNodes:
+    catid=getSingleValue(node,'CategoryID')
+    name=getSingleValue(node,'CategoryName')
+    if name.lower().find(lquery)!=-1:
+      print catid,name
+
+def getItem(itemID):
+  xml = "<?xml version='1.0' encoding='utf-8'?>"+\
+        "<GetItemRequest xmlns=\"urn:ebay:apis:eBLBaseComponents\">"+\
+        "<RequesterCredentials><eBayAuthToken>" +\
+        userToken +\
+        "</eBayAuthToken></RequesterCredentials>" + \
+        "<ItemID>" + str(itemID) + "</ItemID>"+\
+        "<DetailLevel>ItemReturnAttributes</DetailLevel>"+\
+        "</GetItemRequest>"
+  data=sendRequest('GetItem',xml)
+  result={}
+  response=parseString(data)
+  result['title']=getSingleValue(response,'Title')
+  sellingStatusNode = response.getElementsByTagName('SellingStatus')[0];
+  result['price']=getSingleValue(sellingStatusNode,'CurrentPrice')
+  result['bids']=getSingleValue(sellingStatusNode,'BidCount')
+  seller = response.getElementsByTagName('Seller')
+  result['feedback'] = getSingleValue(seller[0],'FeedbackScore')
+
+  attributeSet=response.getElementsByTagName('Attribute');
+  attributes={}
+  for att in attributeSet:
+    attID=att.attributes.getNamedItem('attributeID').nodeValue
+    attValue=getSingleValue(att,'ValueLiteral')
+    attributes[attID]=attValue
+  result['attributes']=attributes
+  return result
+
+
+def makeLaptopDataset():
+  searchResults=doSearch('laptop',categoryID=51148)
+  result=[]
+  for r in searchResults:
+    item=getItem(r[0])
+    att=item['attributes']
+    try:
+      data=(float(att['12']),float(att['26444']),
+            float(att['26446']),float(att['25710']),
+            float(item['feedback'])
+           )
+      entry={'input':data,'result':float(item['price'])}
+      result.append(entry)
+    except:
+      print item['title']+' failed'
+  return result

File Chapter7/facebook.py

+import urllib,md5,webbrowser,time
+from xml.dom.minidom import parseString
+
+apikey="47e953c8ea9ed30db904af453125c759"
+secret="ea703e4721e8c7bf88b92110a46a9b06"
+FacebookURL = "https://api.facebook.com/restserver.php"
+
+def getsinglevalue(node,tag):
+  nl=node.getElementsByTagName(tag)
+  if len(nl)>0:
+    tagNode=nl[0]
+    if tagNode.hasChildNodes():
+      return tagNode.firstChild.nodeValue
+  return ''
+
+def callid(): 
+  return str(int(time.time()*10))
+
+class fbsession:
+  def __init__(self):
+    self.session_secret=None
+    self.session_key=None
+    self.createtoken()
+    webbrowser.open(self.getlogin())
+    print "Press enter after logging in:",
+    raw_input()
+    self.getsession()
+  def sendrequest(self, args):
+    args['api_key'] = apikey
+    args['sig'] = self.makehash(args)
+    post_data = urllib.urlencode(args)
+    url = FacebookURL + "?" + post_data
+    data=urllib.urlopen(url).read()
+    print data
+    return parseString(data)
+  def makehash(self,args):
+    hasher = md5.new(''.join([x + '=' + args[x] for x in sorted(args.keys())]))
+    if self.session_secret: hasher.update(self.session_secret)
+    else: hasher.update(secret)
+    return hasher.hexdigest()
+  def createtoken(self):
+    res = self.sendrequest({'method':"facebook.auth.createToken"})
+    self.token = getsinglevalue(res,'token')
+  def getlogin(self):
+    return "http://api.facebook.com/login.php?api_key="+apikey+\
+           "&auth_token=" + self.token
+  def getsession(self):
+    doc=self.sendrequest({'method':'facebook.auth.getSession',
+                               'auth_token':self.token})
+    self.session_key=getsinglevalue(doc,'session_key')
+    self.session_secret=getsinglevalue(doc,'secret')
+  def getfriends(self):
+    doc=self.sendrequest({'method':'facebook.friends.get',
+                          'session_key':self.session_key,'call_id':callid()})
+    results=[]
+    for n in doc.getElementsByTagName('result_elt'):
+      results.append(n.firstChild.nodeValue)
+    return results
+
+  def getinfo(self,users):
+    ulist=','.join(users)
+    
+    fields='gender,current_location,relationship_status,'+\
+           'affiliations,hometown_location'
+    
+    doc=self.sendrequest({'method':'facebook.users.getInfo',
+    'session_key':self.session_key,'call_id':callid(),
+    'users':ulist,'fields':fields})
+
+    results={}
+    for n,id in zip(doc.getElementsByTagName('result_elt'),users):
+      # Get the location
+      locnode=n.getElementsByTagName('hometown_location')[0]
+      loc=getsinglevalue(locnode,'city')+', '+getsinglevalue(locnode,'state')
+      
+      # Get school
+      college=''
+      gradyear='0'
+      affiliations=n.getElementsByTagName('affiliations_elt')
+      for aff in affiliations:
+        # Type 1 is college
+        if getsinglevalue(aff,'type')=='1': 
+          college=getsinglevalue(aff,'name')
+          gradyear=getsinglevalue(aff,'year')
+      
+      results[id]={'gender':getsinglevalue(n,'gender'),
+                   'status':getsinglevalue(n,'relationship_status'),
+                   'location':loc,'college':college,'year':gradyear}
+    return results
+
+  def arefriends(self,idlist1,idlist2):
+    id1=','.join(idlist1)
+    id2=','.join(idlist2)
+    doc=self.sendrequest({'method':'facebook.friends.areFriends',
+                          'session_key':self.session_key,'call_id':callid(),
+                          'id1':id1,'id2':id2})
+    results=[]
+    for n in doc.getElementsByTagName('result_elt'):
+      results.append(int(n.firstChild.nodeValue))
+    return results
+  
+  
+
+  def makedataset(self):
+    from advancedclassify import milesdistance
+    # Get all the info for all my friends
+    friends=self.getfriends()
+    info=self.getinfo(friends)
+    ids1,ids2=[],[]
+    rows=[]
+
+    # Nested loop to look at every pair of friends
+    for i in range(len(friends)):
+      f1=friends[i]
+      data1=info[f1]
+      
+      # Start at i+1 so we don't double up
+      for j in range(i+1,len(friends)):
+        f2=friends[j]
+        data2=info[f2]
+        ids1.append(f1)
+        ids2.append(f2)
+
+        # Generate some numbers from the data
+        if data1['college']==data2['college']: sameschool=1
+        else: sameschool=0
+        male1=(data1['gender']=='Male') and 1 or 0
+        male2=(data2['gender']=='Male') and 1 or 0        
+        
+        row=[male1,int(data1['year']),male2,int(data2['year']),sameschool]
+        rows.append(row)
+    # Call arefriends in blocks for every pair of people
+    arefriends=[]
+    for i in range(0,len(ids1),30):
+      j=min(i+30,len(ids1))
+      pa=self.arefriends(ids1[i:j],ids2[i:j])
+      arefriends+=pa
+    return arefriends,rows
+  

File Chapter7/hotornot.py

+import urllib2
+import xml.dom.minidom
+
+api_key='YOUR KEY HERE'
+
+def getrandomratings(c):
+  # Construct URL for getRandomProfile
+  url="http://services.hotornot.com/rest/?app_key=%s" % api_key
+  url+="&method=Rate.getRandomProfile&retrieve_num=%d" % c
+  url+="&get_rate_info=true&meet_users_only=true"
+  
+  f1=urllib2.urlopen(url).read()
+
+  doc=xml.dom.minidom.parseString(f1)
+  
+  emids=doc.getElementsByTagName('emid')
+  ratings=doc.getElementsByTagName('rating')
+
+  # Combine the emids and ratings together into a list
+  result=[]
+  for e,r in zip(emids,ratings):
+    if r.firstChild!=None:
+      result.append((e.firstChild.data,r.firstChild.data))
+  return result
+
+stateregions={'New England':['ct','mn','ma','nh','ri','vt'],
+              'Mid Atlantic':['de','md','nj','ny','pa'],
+              'South':['al','ak','fl','ga','ky','la','ms','mo',
+                       'nc','sc','tn','va','wv'],
+              'Midwest':['il','in','ia','ks','mi','ne','nd','oh','sd','wi'],
+              'West':['ak','ca','co','hi','id','mt','nv','or','ut','wa','wy']}
+
+def getpeopledata(ratings):
+  result=[]
+  for emid,rating in ratings:
+    # URL for the MeetMe.getProfile method
+    url="http://services.hotornot.com/rest/?app_key=%s" % api_key
+    url+="&method=MeetMe.getProfile&emid=%s&get_keywords=true" % emid
+
+    # Get all the info about this person
+    try:
+      rating=int(float(rating)+0.5)
+      doc2=xml.dom.minidom.parseString(urllib2.urlopen(url).read())
+      gender=doc2.getElementsByTagName('gender')[0].firstChild.data
+      age=doc2.getElementsByTagName('age')[0].firstChild.data
+      loc=doc2.getElementsByTagName('location')[0].firstChild.data[0:2]
+
+      # Convert state to region
+      for r,s in stateregions.items():
+        if loc in s: region=r
+
+      if region!=None:
+        result.append((gender,int(age),region,rating))
+    except:
+      pass
+  return result
+

File Chapter7/matchmaker.csv

+39,yes,no,skiing:knitting:dancing,220 W 42nd St New York NY,43,no,yes,soccer:reading:scrabble,824 3rd Ave New York NY,0
+23,no,no,football:fashion,102 1st Ave New York NY,30,no,no,snowboarding:knitting:computers:shopping:tv:travel,151 W 34th St New York NY,1
+50,no,no,fashion:opera:tv:travel,686 Avenue of the Americas New York NY,49,yes,yes,soccer:fashion:photography:computers:camping:movies:tv,824 3rd Ave New York NY,0
+46,no,yes,skiing:reading:knitting:writing:shopping,154 7th Ave New York NY,19,no,no,dancing:opera:travel,1560 Broadway New York NY,0
+36,yes,yes,skiing:knitting:camping:writing:cooking,151 W 34th St New York NY,29,no,yes,art:movies:cooking:scrabble,966 3rd Ave New York NY,1
+27,no,no,snowboarding:knitting:fashion:camping:cooking,27 3rd Ave New York NY,19,yes,yes,football:computers:writing,14 E 47th St New York NY,0
+36,no,no,cooking,208 Varick St New York NY,25,no,yes,snowboarding:computers:scrabble,451 Lexington Ave New York NY,0
+41,yes,yes,snowboarding:football:reading:fashion:computers:camping:writing,26 Bowery New York NY,23,yes,no,skiing:football:movies:opera:shopping:travel,151 W 34th St New York NY,0
+21,no,no,snowboarding:football:camping:travel,2049 Broadway New York NY,18,yes,no,skiing:snowboarding:reading:fashion:art:animals:camping,1560 Broadway New York NY,1
+39,no,yes,soccer:dancing:writing:shopping:tv:scrabble,556 7th Ave New York NY,21,no,no,football:photography:scrabble,2049 Broadway New York NY,0
+24,no,no,snowboarding:computers,14 E 47th St New York NY,41,no,yes,soccer:reading:shopping:tv:cooking:scrabble,966 3rd Ave New York NY,0
+34,yes,yes,animals,2049 Broadway New York NY,33,no,yes,photography:dancing:travel,336 E 23rd St New York NY,1
+18,no,no,fashion:shopping,154 7th Ave New York NY,47,no,yes,football:computers:opera:travel:cooking,1286 1st Ave New York NY,0
+39,no,yes,skiing:computers:shopping:tv,102 1st Ave New York NY,20,no,no,soccer:reading:camping:opera,2271 Broadway New York NY,0
+43,no,yes,skiing:soccer:scrabble,336 E 23rd St New York NY,35,no,yes,reading:knitting:camping,966 3rd Ave New York NY,1
+30,no,no,soccer:photography:dancing:travel:scrabble,600 W 125th St New York NY,31,yes,yes,reading:animals,404 E 14th St New York NY,0
+35,no,no,football:dancing:scrabble,1188 Avenue of the Americas New York NY,32,no,yes,art:dancing:writing:shopping:tv,1560 Broadway New York NY,0
+27,yes,yes,skiing:photography:computers:cooking,208 Varick St New York NY,44,no,no,skiing:snowboarding:football:knitting:photography:dancing,208 Varick St New York NY,0
+30,no,no,soccer:running:art:dancing:tv:travel:scrabble,686 Avenue of the Americas New York NY,43,no,no,soccer:fashion:photography:camping:writing:shopping,3794 Broadway New York NY,1
+33,no,yes,snowboarding:photography:opera:tv:cooking,2271 Broadway New York NY,50,no,yes,skiing:running:computers:tv:scrabble,1188 Avenue of the Americas New York NY,1
+24,no,yes,dancing:scrabble,151 W 34th St New York NY,38,no,no,reading:scrabble,27 3rd Ave New York NY,0
+49,no,yes,soccer:reading:art:shopping:tv,686 Avenue of the Americas New York NY,49,no,no,skiing:snowboarding:soccer:football:reading:art:cooking:scrabble,208 Varick St New York NY,1
+34,no,no,art:movies:opera:writing,556 7th Ave New York NY,28,no,yes,reading:fashion:computers,220 W 42nd St New York NY,0
+38,no,yes,running:fashion:cooking,686 Avenue of the Americas New York NY,25,no,no,skiing:snowboarding:animals:camping:dancing:movies:writing,2049 Broadway New York NY,0
+50,no,no,running:photography:art:cooking:scrabble,1560 Broadway New York NY,34,no,yes,snowboarding:football:running:reading:knitting:art:computers:cooking,1560 Broadway New York NY,1
+29,no,no,photography:dancing:movies,404 E 14th St New York NY,45,no,yes,skiing:football:knitting:photography:dancing,27 3rd Ave New York NY,0
+43,no,yes,soccer:art:animals:camping:movies,39 Union sq W New York NY,20,no,no,fashion:travel,2049 Broadway New York NY,0
+41,no,no,camping,688 8th Ave New York NY,34,no,no,reading:fashion:art,556 7th Ave New York NY,1
+48,yes,yes,snowboarding:running:reading:photography:computers:animals:movies:opera:travel,3794 Broadway New York NY,45,no,yes,knitting:camping,14 E 47th St New York NY,1
+39,no,no,reading:computers:animals,102 1st Ave New York NY,33,no,yes,skiing:snowboarding:soccer:photography:dancing:tv,541 Avenue of the Americas New York NY,0
+31,no,yes,skiing:snowboarding:reading:photography:camping:tv:cooking,2049 Broadway New York NY,32,yes,no,knitting:photography:travel:cooking,102 1st Ave New York NY,0
+33,no,yes,skiing:soccer:football:reading:knitting:art:shopping:scrabble,336 E 23rd St New York NY,46,yes,no,opera:tv:travel:scrabble,966 3rd Ave New York NY,0
+25,no,no,skiing:knitting:photography:scrabble,208 Varick St New York NY,28,no,no,football:reading:camping:scrabble,3794 Broadway New York NY,1
+47,yes,yes,football:fashion:computers,427 10th Ave New York NY,19,no,no,photography:scrabble,39 Union sq W New York NY,0
+18,no,no,fashion:photography:animals,2271 Broadway New York NY,23,no,yes,reading:art:computers:movies:writing,1560 Broadway New York NY,0
+20,no,yes,running:movies:opera:writing:tv:scrabble,1286 1st Ave New York NY,26,no,no,running:animals:camping:tv:cooking:scrabble,556 7th Ave New York NY,0
+24,no,yes,knitting:photography,1083 2nd Ave New York NY,49,no,yes,skiing:running:photography:art:animals:camping:movies:writing:shopping,2049 Broadway New York NY,0
+28,no,yes,art:camping:dancing,208 Varick St New York NY,45,no,no,photography:travel,39 Union sq W New York NY,0
+39,no,yes,skiing:running:art:writing:scrabble,541 Avenue of the Americas New York NY,45,no,no,football:opera:tv,1560 Broadway New York NY,0
+27,no,no,opera:writing:shopping:scrabble,1083 2nd Ave New York NY,41,no,yes,football:animals:camping:cooking,1083 2nd Ave New York NY,0
+32,yes,no,football:fashion:photography:animals:tv:cooking,427 10th Ave New York NY,31,no,no,snowboarding:photography:travel,336 E 23rd St New York NY,1
+47,no,no,skiing:snowboarding:soccer:knitting:dancing:travel,1188 Avenue of the Americas New York NY,37,no,no,animals:writing,1286 1st Ave New York NY,1
+28,no,no,skiing:art:writing,14 E 47th St New York NY,41,no,yes,skiing:snowboarding:writing,220 W 42nd St New York NY,0
+34,no,no,skiing:snowboarding:soccer:camping:travel:cooking,3794 Broadway New York NY,19,no,yes,soccer:camping:scrabble,824 3rd Ave New York NY,0
+39,yes,yes,reading:photography:dancing:movies:writing:travel,1286 1st Ave New York NY,45,no,yes,reading:computers:movies:scrabble,427 10th Ave New York NY,1
+25,no,no,snowboarding:football:camping:travel,688 8th Ave New York NY,28,no,no,football:photography:computers:dancing:cooking,541 Avenue of the Americas New York NY,1
+47,no,yes,skiing:reading:cooking,600 W 125th St New York NY,29,no,no,soccer:writing:cooking,966 3rd Ave New York NY,0
+30,no,yes,football:photography:shopping:tv,154 7th Ave New York NY,48,no,yes,snowboarding:fashion:computers:cooking:scrabble,2271 Broadway New York NY,1
+48,no,yes,skiing:snowboarding:soccer:knitting:dancing:opera:writing:shopping:travel:scrabble,208 Varick St New York NY,35,no,no,skiing:fashion:art:computers:writing,556 7th Ave New York NY,0
+24,no,yes,soccer,556 7th Ave New York NY,44,no,yes,fashion:dancing:tv,427 10th Ave New York NY,0
+32,no,no,reading:fashion:photography:art:camping:dancing,154 7th Ave New York NY,50,no,no,football:computers:movies:opera,90 Maiden Ln New York NY,1
+47,no,no,soccer:running:reading:fashion:dancing:opera:scrabble,556 7th Ave New York NY,19,yes,yes,skiing:snowboarding:football:knitting:dancing:scrabble,600 W 125th St New York NY,0
+27,no,no,soccer:running:knitting:fashion:movies:tv:scrabble,208 Varick St New York NY,24,no,no,skiing:photography:dancing,39 Union sq W New York NY,1
+18,yes,no,art:computers:camping:dancing:cooking,451 Lexington Ave New York NY,34,no,no,animals:camping:writing,90 Maiden Ln New York NY,0
+26,no,yes,snowboarding:football:dancing:tv,451 Lexington Ave New York NY,46,yes,yes,skiing:computers,686 Avenue of the Americas New York NY,0
+49,no,no,running:reading,686 Avenue of the Americas New York NY,40,no,yes,soccer:camping:writing,336 E 23rd St New York NY,0
+32,no,no,soccer,404 E 14th St New York NY,36,no,no,skiing:running:knitting:animals:movies:travel:cooking,556 7th Ave New York NY,1
+27,no,no,soccer:knitting:art:writing,824 3rd Ave New York NY,36,yes,yes,snowboarding:soccer:running:photography:art:computers:writing:travel:cooking,1286 1st Ave New York NY,1
+42,no,yes,skiing:photography:computers:camping:opera:cooking,2049 Broadway New York NY,35,no,no,skiing:snowboarding:reading:art:travel,824 3rd Ave New York NY,0
+49,yes,yes,skiing:camping:movies,26 Bowery New York NY,26,no,no,skiing:running:knitting:opera,39 Union sq W New York NY,0
+36,no,yes,football:photography:art:computers:camping:writing:shopping:tv,1083 2nd Ave New York NY,18,no,yes,skiing:travel:cooking:scrabble,404 E 14th St New York NY,1
+20,no,yes,skiing:football:running:writing,404 E 14th St New York NY,32,no,yes,soccer:art:animals:opera:tv,1188 Avenue of the Americas New York NY,0
+36,no,yes,knitting:camping:opera:tv:travel,39 Union sq W New York NY,22,no,no,soccer:knitting:photography:art:dancing:writing:shopping,27 3rd Ave New York NY,0
+35,no,yes,knitting:art:tv,1499 3rd Ave New York NY,41,no,no,reading:photography:art:animals:movies:opera:shopping,102 1st Ave New York NY,0
+41,no,no,skiing:snowboarding:soccer:knitting:fashion,556 7th Ave New York NY,20,yes,no,skiing:art,39 Union sq W New York NY,1
+24,yes,no,snowboarding:computers:travel,14 E 47th St New York NY,21,no,no,soccer:fashion:camping:movies:shopping:travel:scrabble,2049 Broadway New York NY,1
+18,no,yes,skiing:soccer:running:movies:scrabble,1083 2nd Ave New York NY,47,yes,yes,skiing:photography:movies:shopping:tv:cooking,686 Avenue of the Americas New York NY,0
+32,no,no,writing:tv:travel,90 Maiden Ln New York NY,26,no,yes,skiing:running:fashion:computers,1083 2nd Ave New York NY,0
+21,yes,yes,knitting:camping:tv:scrabble,1286 1st Ave New York NY,19,yes,yes,soccer:reading:photography:movies:travel,2271 Broadway New York NY,1
+49,no,yes,skiing:soccer:knitting:art:shopping:tv:scrabble,208 Varick St New York NY,35,no,no,dancing:cooking,336 E 23rd St New York NY,0
+41,yes,yes,football:running:fashion:cooking,824 3rd Ave New York NY,44,no,yes,running:travel,404 E 14th St New York NY,1
+40,no,yes,football:scrabble,39 Union sq W New York NY,30,no,yes,snowboarding:knitting:fashion:animals:movies,14 E 47th St New York NY,1
+32,yes,no,camping,451 Lexington Ave New York NY,29,no,yes,running:fashion:animals:movies:opera:tv:travel,1499 3rd Ave New York NY,0
+48,no,yes,skiing:snowboarding:camping:shopping:cooking,1560 Broadway New York NY,29,no,no,soccer:reading:knitting:cooking,1560 Broadway New York NY,0
+50,no,no,art:tv,336 E 23rd St New York NY,19,no,yes,snowboarding:soccer:reading,102 1st Ave New York NY,0
+48,no,no,soccer:football:knitting:photography:writing:cooking,556 7th Ave New York NY,33,yes,no,snowboarding:fashion:photography:computers:movies:scrabble,336 E 23rd St New York NY,1
+50,no,no,travel,39 Union sq W New York NY,45,no,no,soccer:animals:dancing:cooking,336 E 23rd St New York NY,1
+22,no,yes,soccer:reading:fashion:movies:opera:travel,1083 2nd Ave New York NY,24,no,no,camping:tv,688 8th Ave New York NY,0
+41,no,no,soccer:reading:art:movies:tv,90 Maiden Ln New York NY,31,no,no,football:running:cooking,39 Union sq W New York NY,1
+49,no,no,running,39 Union sq W New York NY,27,yes,yes,soccer:art:writing:travel,1560 Broadway New York NY,0
+28,no,yes,running:opera:scrabble,90 Maiden Ln New York NY,47,no,no,running:reading:camping:travel:cooking,966 3rd Ave New York NY,0
+19,yes,no,football:running:computers:camping:opera:tv:cooking,26 Bowery New York NY,34,no,no,snowboarding:running:reading:dancing:movies:tv:travel:cooking,451 Lexington Ave New York NY,0
+26,no,yes,knitting:fashion:dancing:movies:opera:writing,151 W 34th St New York NY,33,no,yes,snowboarding:reading:writing:shopping:travel,3794 Broadway New York NY,1
+28,no,yes,knitting:art:computers:camping:dancing,824 3rd Ave New York NY,26,no,yes,skiing:football:running:computers:opera,14 E 47th St New York NY,1
+21,no,no,soccer:reading:fashion:camping:shopping,154 7th Ave New York NY,30,no,yes,skiing:running:fashion:shopping:tv:cooking,2271 Broadway New York NY,0
+50,no,yes,skiing:reading:fashion:opera:tv:scrabble,966 3rd Ave New York NY,21,no,no,knitting,1499 3rd Ave New York NY,0
+42,no,yes,skiing:snowboarding:opera:writing:tv,154 7th Ave New York NY,48,no,yes,photography:computers:opera:cooking:scrabble,688 8th Ave New York NY,1
+27,no,no,running:photography:computers:camping:writing:tv,90 Maiden Ln New York NY,24,yes,yes,knitting:movies,2271 Broadway New York NY,0
+18,no,yes,soccer:reading:knitting:opera:tv,336 E 23rd St New York NY,22,yes,yes,snowboarding:football:photography:tv:cooking,102 1st Ave New York NY,0
+21,no,yes,skiing:football:running:computers,26 Bowery New York NY,40,no,yes,movies:opera:tv,541 Avenue of the Americas New York NY,0
+28,no,no,soccer:reading:knitting:camping:movies:writing:travel:cooking,151 W 34th St New York NY,18,no,no,skiing:running:computers:camping:opera,1188 Avenue of the Americas New York NY,1
+27,no,no,soccer:fashion:computers:shopping:scrabble,14 E 47th St New York NY,21,yes,yes,snowboarding:soccer:football:knitting:computers:cooking,451 Lexington Ave New York NY,0
+37,yes,yes,football:computers:opera:tv:cooking,90 Maiden Ln New York NY,42,no,yes,skiing:reading:fashion:camping:tv:scrabble,39 Union sq W New York NY,1
+26,yes,no,skiing:football:running:fashion:photography:dancing:opera,1083 2nd Ave New York NY,35,no,no,knitting,1499 3rd Ave New York NY,1
+31,no,no,skiing:football:reading:knitting:art:movies:opera:cooking,208 Varick St New York NY,29,no,no,soccer:reading:photography,27 3rd Ave New York NY,1
+20,yes,yes,soccer:running:dancing:writing:travel,3794 Broadway New York NY,31,no,no,,14 E 47th St New York NY,0
+34,no,no,soccer:art:opera:scrabble,220 W 42nd St New York NY,34,no,yes,camping:movies,1083 2nd Ave New York NY,0
+47,no,yes,soccer,1560 Broadway New York NY,38,no,yes,snowboarding:soccer:computers:dancing:movies,688 8th Ave New York NY,1
+36,no,yes,art:dancing:scrabble,2049 Broadway New York NY,35,no,yes,fashion,427 10th Ave New York NY,1
+30,no,no,fashion:cooking,404 E 14th St New York NY,21,no,no,reading:movies,824 3rd Ave New York NY,1
+27,no,no,knitting:art:writing,90 Maiden Ln New York NY,19,no,yes,skiing:snowboarding:soccer:running:fashion:camping:writing:scrabble,26 Bowery New York NY,0
+37,no,yes,skiing,154 7th Ave New York NY,33,yes,no,fashion:dancing:shopping:tv:travel,404 E 14th St New York NY,0
+31,no,yes,dancing:travel:scrabble,541 Avenue of the Americas New York NY,35,no,yes,knitting:fashion:photography:cooking,27 3rd Ave New York NY,1
+37,no,yes,football:computers:dancing:shopping:travel:scrabble,26 Bowery New York NY,43,yes,yes,running:tv:cooking,427 10th Ave New York NY,1
+23,no,no,snowboarding:shopping:travel:scrabble,541 Avenue of the Americas New York NY,39,no,no,running:photography:cooking,3794 Broadway New York NY,0
+19,no,yes,reading:photography:travel:cooking,26 Bowery New York NY,32,no,no,animals:scrabble,451 Lexington Ave New York NY,0
+22,no,yes,skiing:soccer:knitting:tv,90 Maiden Ln New York NY,28,no,no,snowboarding:knitting:fashion:photography:computers:dancing:opera:scrabble,26 Bowery New York NY,0
+44,no,yes,running:reading:opera,404 E 14th St New York NY,20,no,yes,reading:photography:animals:camping:movies:tv:cooking:scrabble,451 Lexington Ave New York NY,0
+48,no,yes,art:movies:opera,688 8th Ave New York NY,23,no,yes,knitting:dancing:movies:opera:shopping:tv:cooking,686 Avenue of the Americas New York NY,0
+31,no,yes,football:writing:tv,14 E 47th St New York NY,27,no,no,skiing:knitting:opera:shopping:travel:scrabble,208 Varick St New York NY,0
+26,yes,yes,fashion:photography:opera,90 Maiden Ln New York NY,30,no,no,animals:opera:writing:tv:cooking,3794 Broadway New York NY,0
+45,no,no,skiing:snowboarding:photography:camping:tv:travel,1499 3rd Ave New York NY,42,no,yes,running:tv:cooking,102 1st Ave New York NY,0
+37,no,yes,skiing:running:art:dancing:opera,39 Union sq W New York NY,45,yes,no,snowboarding:knitting:movies,336 E 23rd St New York NY,0
+47,no,no,skiing:football:reading:tv,427 10th Ave New York NY,47,no,no,football:fashion,404 E 14th St New York NY,1
+47,no,no,soccer:fashion:dancing:opera:shopping:cooking,1499 3rd Ave New York NY,30,no,yes,soccer:running:reading:animals,427 10th Ave New York NY,0
+19,no,no,snowboarding:running:photography:cooking:scrabble,27 3rd Ave New York NY,34,yes,no,running:reading:tv,404 E 14th St New York NY,0
+35,no,no,reading:camping:opera:cooking:scrabble,1560 Broadway New York NY,30,no,yes,football:animals:shopping:travel:cooking,556 7th Ave New York NY,0
+44,yes,no,soccer:football:camping:movies:travel:scrabble,1188 Avenue of the Americas New York NY,34,no,no,reading:knitting:fashion:travel,3794 Broadway New York NY,1
+41,no,yes,football:fashion:animals:movies,1560 Broadway New York NY,32,yes,yes,tv:cooking:scrabble,1286 1st Ave New York NY,1
+26,no,no,,966 3rd Ave New York NY,37,yes,yes,soccer:fashion:art:computers:writing:tv:travel,151 W 34th St New York NY,0
+28,no,yes,snowboarding:reading:fashion:photography:writing:shopping:travel,26 Bowery New York NY,50,yes,no,art:tv,451 Lexington Ave New York NY,0
+47,no,yes,skiing:camping:opera:tv:scrabble,90 Maiden Ln New York NY,48,no,no,reading:photography:camping:dancing:movies:shopping:travel,1188 Avenue of the Americas New York NY,0
+38,no,yes,football:photography:tv,151 W 34th St New York NY,32,no,no,skiing:soccer:computers:camping:movies:travel,427 10th Ave New York NY,0
+41,no,no,camping:writing,154 7th Ave New York NY,26,no,no,skiing:snowboarding:computers:animals:writing,556 7th Ave New York NY,1
+49,no,yes,skiing:snowboarding:football:fashion:computers:camping:dancing:shopping:travel,404 E 14th St New York NY,50,yes,yes,skiing:running:knitting:fashion:art:animals:scrabble,3794 Broadway New York NY,1
+19,no,no,soccer:fashion:animals,824 3rd Ave New York NY,28,yes,no,skiing:running:knitting:fashion:computers:camping:tv,427 10th Ave New York NY,0
+30,yes,no,fashion:dancing,39 Union sq W New York NY,23,no,no,fashion:photography:animals:tv,102 1st Ave New York NY,1
+34,no,yes,snowboarding:soccer:knitting:art:computers:animals:shopping,220 W 42nd St New York NY,40,no,yes,animals:travel,1286 1st Ave New York NY,1
+43,no,no,fashion:writing:tv,154 7th Ave New York NY,23,no,no,,1188 Avenue of the Americas New York NY,0
+19,no,no,reading:animals:camping:opera:cooking,2271 Broadway New York NY,34,yes,no,snowboarding:football:fashion:photography:computers:camping,102 1st Ave New York NY,0
+48,no,yes,soccer:fashion:photography:art:computers:animals:movies:scrabble,600 W 125th St New York NY,48,yes,yes,running:fashion:cooking,154 7th Ave New York NY,1
+36,no,yes,soccer:animals:shopping,90 Maiden Ln New York NY,41,no,no,football:knitting:computers:opera:writing:cooking,26 Bowery New York NY,0
+48,no,no,skiing:fashion:camping:writing:tv,2049 Broadway New York NY,31,yes,no,fashion:dancing:movies,220 W 42nd St New York NY,1
+31,no,no,skiing:soccer:football:animals:opera:scrabble,556 7th Ave New York NY,44,no,yes,football:computers,14 E 47th St New York NY,0
+23,no,yes,movies:opera:writing,336 E 23rd St New York NY,27,no,yes,soccer:football:fashion:animals:tv,102 1st Ave New York NY,1
+48,no,yes,fashion:computers:animals,336 E 23rd St New York NY,22,yes,yes,skiing:reading:art:animals:dancing,2049 Broadway New York NY,0
+41,no,no,skiing:knitting:fashion:scrabble,220 W 42nd St New York NY,38,no,no,football:fashion:photography:dancing,220 W 42nd St New York NY,1
+40,no,no,reading:fashion:camping:cooking,39 Union sq W New York NY,37,yes,yes,skiing:fashion:shopping:travel,151 W 34th St New York NY,0
+47,no,yes,knitting:computers:animals:camping,1499 3rd Ave New York NY,47,no,no,skiing:soccer:football:computers:dancing:cooking,966 3rd Ave New York NY,0
+18,yes,yes,reading:knitting:computers:opera:scrabble,966 3rd Ave New York NY,33,no,yes,snowboarding:knitting:fashion:tv:scrabble,1560 Broadway New York NY,0
+34,yes,no,camping:travel,1560 Broadway New York NY,26,yes,no,knitting:fashion:tv:cooking:scrabble,220 W 42nd St New York NY,1
+26,no,no,snowboarding:football:running:animals:shopping:travel,556 7th Ave New York NY,21,no,yes,football:running:photography:computers:animals:writing,966 3rd Ave New York NY,1
+33,no,no,football:running:opera:writing:shopping:travel,541 Avenue of the Americas New York NY,19,no,yes,football:photography:animals:cooking,1560 Broadway New York NY,0
+45,no,no,knitting:fashion,686 Avenue of the Americas New York NY,47,no,yes,dancing:opera,2271 Broadway New York NY,0
+34,no,no,soccer:knitting:movies,404 E 14th St New York NY,21,no,no,soccer:computers:opera,102 1st Ave New York NY,1
+18,no,no,opera:scrabble,600 W 125th St New York NY,47,no,no,soccer:running:art:writing,2049 Broadway New York NY,0
+49,no,no,animals,220 W 42nd St New York NY,46,no,no,skiing:snowboarding:soccer:photography:art:dancing:opera:tv:travel,966 3rd Ave New York NY,1
+24,no,no,camping:writing:travel,2049 Broadway New York NY,28,no,yes,photography,688 8th Ave New York NY,0
+20,no,no,football:computers:camping:cooking,824 3rd Ave New York NY,36,no,no,football:running:reading:fashion:computers,27 3rd Ave New York NY,0
+34,no,yes,reading:animals:travel:cooking:scrabble,688 8th Ave New York NY,19,yes,yes,skiing:snowboarding:soccer:reading:fashion:dancing:movies:writing:cooking:scrabble,14 E 47th St New York NY,1
+26,no,no,art:animals:travel,1083 2nd Ave New York NY,22,no,yes,soccer:football:opera:shopping:cooking,688 8th Ave New York NY,0
+27,no,no,knitting:dancing:opera:cooking:scrabble,336 E 23rd St New York NY,34,no,yes,skiing:camping:opera,27 3rd Ave New York NY,0
+39,no,no,snowboarding:football:reading:photography:art:animals:dancing:writing:shopping:tv,2049 Broadway New York NY,36,no,no,fashion:art:dancing:movies:writing:tv:travel,2049 Broadway New York NY,1
+48,yes,yes,snowboarding:fashion:dancing,154 7th Ave New York NY,35,no,no,fashion:art:camping:tv,556 7th Ave New York NY,0
+20,yes,yes,movies:tv:cooking,1188 Avenue of the Americas New York NY,35,no,yes,skiing:running:knitting:art:computers:writing:cooking,220 W 42nd St New York NY,0
+24,no,no,football:fashion:animals:dancing:opera:tv,14 E 47th St New York NY,34,no,yes,skiing:snowboarding:art:dancing:writing,2271 Broadway New York NY,0
+26,no,yes,soccer:camping,1188 Avenue of the Americas New York NY,24,no,yes,snowboarding:knitting:art:opera:writing:shopping:travel,541 Avenue of the Americas New York NY,1
+48,no,no,art:camping:shopping:cooking:scrabble,1560 Broadway New York NY,25,no,yes,running:photography:computers:camping:movies:travel:cooking,2271 Broadway New York NY,0
+32,no,yes,skiing:football:fashion:dancing:opera:shopping:tv,1560 Broadway New York NY,36,no,yes,skiing:football:computers:animals:camping:opera:shopping,688 8th Ave New York NY,1
+34,no,no,computers:travel:cooking,541 Avenue of the Americas New York NY,33,no,no,running:photography:writing:tv,154 7th Ave New York NY,1
+31,no,no,skiing:snowboarding:fashion:animals:travel,208 Varick St New York NY,28,no,yes,photography:animals:camping:dancing:scrabble,3794 Broadway New York NY,0
+44,no,yes,snowboarding:animals:opera,1083 2nd Ave New York NY,33,no,no,art:animals:camping:writing:scrabble,90 Maiden Ln New York NY,0
+22,no,no,running:fashion,154 7th Ave New York NY,32,no,no,football:fashion:movies:shopping:cooking:scrabble,2271 Broadway New York NY,0
+41,no,yes,football:movies,39 Union sq W New York NY,39,yes,no,football:fashion:art:camping:movies:cooking:scrabble,1560 Broadway New York NY,0
+32,no,yes,soccer:football:knitting:tv,336 E 23rd St New York NY,48,no,yes,photography:animals:dancing:cooking,14 E 47th St New York NY,1
+21,no,yes,soccer:fashion:photography:writing,220 W 42nd St New York NY,21,no,no,snowboarding:running:knitting:dancing:movies:travel:scrabble,686 Avenue of the Americas New York NY,0
+49,no,no,reading:animals:opera:writing,14 E 47th St New York NY,48,no,yes,snowboarding:reading:knitting:fashion:movies,686 Avenue of the Americas New York NY,0
+49,no,no,skiing:art:opera,2271 Broadway New York NY,19,yes,no,fashion:photography:camping:shopping,824 3rd Ave New York NY,0
+34,no,no,animals:shopping:travel,90 Maiden Ln New York NY,43,yes,yes,soccer:art,688 8th Ave New York NY,0
+25,no,yes,fashion:animals:camping:shopping:cooking:scrabble,90 Maiden Ln New York NY,33,no,no,football:photography:computers:opera:writing:tv:cooking,1188 Avenue of the Americas New York NY,0
+30,yes,yes,soccer:reading:art:camping:movies:tv:travel,39 Union sq W New York NY,39,no,no,reading:knitting:writing:cooking:scrabble,556 7th Ave New York NY,0
+24,no,no,photography:tv,404 E 14th St New York NY,35,no,no,animals:camping:cooking:scrabble,404 E 14th St New York NY,0
+35,no,no,soccer:animals:camping:tv:scrabble,336 E 23rd St New York NY,36,no,yes,opera:writing:tv,27 3rd Ave New York NY,0
+39,no,no,soccer:running:reading:fashion:computers:writing:tv:travel:cooking,541 Avenue of the Americas New York NY,26,no,no,reading:knitting:computers:cooking,688 8th Ave New York NY,1
+19,yes,yes,camping:dancing:movies:opera:travel:cooking,556 7th Ave New York NY,29,no,no,snowboarding:photography:movies:opera:tv:travel:cooking:scrabble,451 Lexington Ave New York NY,0
+48,yes,no,running:photography:dancing:movies:shopping,1286 1st Ave New York NY,48,yes,yes,skiing:fashion:photography:dancing:writing:shopping:tv:cooking,3794 Broadway New York NY,1
+30,no,no,soccer:football:reading:knitting:art:animals:movies,39 Union sq W New York NY,44,no,no,skiing:knitting:animals:movies,427 10th Ave New York NY,1
+32,no,yes,,404 E 14th St New York NY,49,no,no,football:running:dancing:travel,3794 Broadway New York NY,0
+21,no,no,running:computers:cooking:scrabble,2049 Broadway New York NY,20,no,no,knitting:movies:shopping:scrabble,600 W 125th St New York NY,1
+20,yes,no,travel:scrabble,1286 1st Ave New York NY,46,no,no,reading:knitting:scrabble,427 10th Ave New York NY,0
+50,no,no,skiing:fashion:computers:camping,427 10th Ave New York NY,20,no,yes,reading:photography:scrabble,824 3rd Ave New York NY,0
+27,no,yes,skiing:photography:tv:cooking:scrabble,3794 Broadway New York NY,25,yes,yes,snowboarding:knitting:opera:shopping:travel,427 10th Ave New York NY,1
+20,no,no,skiing:reading:fashion:movies:scrabble,2049 Broadway New York NY,21,yes,yes,snowboarding:soccer:knitting:computers:animals:dancing,39 Union sq W New York NY,0
+29,no,no,reading:knitting:animals:camping:movies:cooking:scrabble,102 1st Ave New York NY,34,no,yes,snowboarding:football:fashion:travel,1083 2nd Ave New York NY,0
+35,no,yes,soccer:knitting:fashion:animals:movies:opera:scrabble,966 3rd Ave New York NY,32,no,yes,snowboarding:photography:animals:camping:dancing:shopping,1499 3rd Ave New York NY,1
+44,yes,no,snowboarding:football:photography:animals:dancing:opera:cooking,600 W 125th St New York NY,25,yes,yes,computers:animals:movies,2271 Broadway New York NY,0
+22,no,yes,fashion:art:camping:dancing:tv,39 Union sq W New York NY,34,no,no,football:camping:tv:travel,427 10th Ave New York NY,0
+41,yes,yes,skiing:running:fashion:computers:dancing:travel,1083 2nd Ave New York NY,19,no,yes,soccer:animals:dancing:cooking,14 E 47th St New York NY,1
+36,no,no,soccer:football:tv,2049 Broadway New York NY,19,no,yes,running:reading:knitting:animals:movies:opera:cooking,966 3rd Ave New York NY,0
+38,no,yes,photography:computers,90 Maiden Ln New York NY,44,no,no,soccer:running:reading:knitting:dancing:writing,1560 Broadway New York NY,0
+34,no,no,reading:animals:camping:dancing,1286 1st Ave New York NY,42,no,yes,snowboarding:soccer:football:dancing:opera:writing:shopping:tv,26 Bowery New York NY,0
+35,yes,no,skiing:snowboarding:dancing:opera:tv,404 E 14th St New York NY,26,no,no,reading:art:camping:dancing:writing:tv,1083 2nd Ave New York NY,1
+46,no,no,skiing:football:running:fashion:camping:writing,824 3rd Ave New York NY,40,no,no,skiing:reading:fashion:movies,600 W 125th St New York NY,1
+47,no,no,dancing:shopping:cooking:scrabble,688 8th Ave New York NY,18,no,yes,knitting:art:cooking,26 Bowery New York NY,0
+41,no,no,skiing:opera,427 10th Ave New York NY,37,no,no,skiing:fashion:movies,90 Maiden Ln New York NY,1
+46,no,yes,running:cooking,1083 2nd Ave New York NY,50,no,yes,skiing:football:photography:art:movies:travel:scrabble,966 3rd Ave New York NY,1
+18,no,no,football:tv,2271 Broadway New York NY,24,no,yes,football:photography:camping:scrabble,1083 2nd Ave New York NY,0
+20,no,no,soccer:computers:dancing:writing:cooking,90 Maiden Ln New York NY,30,no,no,skiing:snowboarding:reading:knitting:photography:dancing,39 Union sq W New York NY,0
+41,no,no,art:camping:cooking,824 3rd Ave New York NY,35,no,no,skiing:snowboarding:camping:dancing:movies:opera:tv,27 3rd Ave New York NY,1
+40,yes,yes,soccer:reading:writing:travel,1188 Avenue of the Americas New York NY,42,no,no,soccer:football:knitting:art:cooking,154 7th Ave New York NY,0
+20,yes,no,soccer:opera:shopping,102 1st Ave New York NY,39,no,no,snowboarding:football:computers:opera:writing:tv,90 Maiden Ln New York NY,0
+44,no,yes,soccer:travel,427 10th Ave New York NY,44,no,yes,fashion:art:computers:animals:camping:opera:tv:travel,1188 Avenue of the Americas New York NY,1
+20,no,yes,snowboarding:football:knitting:art:dancing:travel,427 10th Ave New York NY,26,no,no,snowboarding:football:movies,336 E 23rd St New York NY,0
+26,no,yes,fashion:computers:animals:opera:cooking:scrabble,404 E 14th St New York NY,25,no,yes,skiing:snowboarding:knitting:opera:tv:cooking,102 1st Ave New York NY,1
+35,no,yes,writing,154 7th Ave New York NY,44,yes,yes,snowboarding:running:computers,26 Bowery New York NY,1
+47,yes,no,snowboarding:fashion:movies:travel,220 W 42nd St New York NY,30,no,yes,soccer:running:knitting:animals:dancing:scrabble,220 W 42nd St New York NY,0
+47,no,yes,skiing:photography:art:dancing:movies:cooking,1286 1st Ave New York NY,43,no,yes,soccer:reading:art:animals:camping:scrabble,14 E 47th St New York NY,1
+22,no,no,snowboarding:camping:tv,102 1st Ave New York NY,38,yes,no,snowboarding:soccer:running:reading:knitting:art:shopping:travel:scrabble,220 W 42nd St New York NY,0
+37,yes,yes,snowboarding:running:fashion:art:animals:camping:dancing:movies:cooking,404 E 14th St New York NY,29,no,no,running:photography:camping:dancing,451 Lexington Ave New York NY,1
+29,yes,yes,soccer:dancing:movies:writing:shopping,102 1st Ave New York NY,41,no,no,football:fashion:animals:tv:cooking:scrabble,600 W 125th St New York NY,0
+33,no,yes,running,404 E 14th St New York NY,26,no,yes,running:scrabble,208 Varick St New York NY,1
+18,no,yes,fashion:art:writing,27 3rd Ave New York NY,21,no,no,running:fashion:photography:art:animals:camping:dancing:scrabble,14 E 47th St New York NY,0
+45,no,yes,knitting:travel:cooking,966 3rd Ave New York NY,28,no,no,knitting:fashion:art:computers:animals:travel,14 E 47th St New York NY,0
+48,no,no,skiing:computers:writing,2271 Broadway New York NY,49,no,yes,snowboarding:soccer:knitting:shopping,404 E 14th St New York NY,0
+25,yes,no,skiing:soccer:computers:tv:travel:cooking:scrabble,336 E 23rd St New York NY,31,yes,yes,fashion:opera:cooking,1083 2nd Ave New York NY,0
+18,no,no,running:fashion:shopping:travel:cooking,600 W 125th St New York NY,23,no,yes,snowboarding,208 Varick St New York NY,0
+37,no,yes,soccer:running:camping:dancing:tv,220 W 42nd St New York NY,43,yes,yes,skiing:snowboarding:running:reading:dancing:travel,27 3rd Ave New York NY,1
+43,no,no,soccer:running:writing,14 E 47th St New York NY,40,yes,yes,skiing:football:reading:animals:opera:cooking,541 Avenue of the Americas New York NY,0
+22,no,yes,reading:travel:cooking,1499 3rd Ave New York NY,42,no,yes,photography:dancing:writing,14 E 47th St New York NY,0
+23,no,yes,football:photography:animals:travel,556 7th Ave New York NY,46,no,yes,reading:fashion:photography:camping:shopping:travel:cooking,102 1st Ave New York NY,0
+45,no,no,soccer:art:movies:cooking,220 W 42nd St New York NY,24,no,no,soccer:photography:dancing:movies:shopping:tv,966 3rd Ave New York NY,0
+40,yes,yes,skiing:animals,1083 2nd Ave New York NY,47,yes,no,snowboarding:football:reading:art:dancing:cooking:scrabble,404 E 14th St New York NY,0
+18,yes,yes,football:art:dancing:opera:writing,151 W 34th St New York NY,31,yes,no,art:camping:opera:tv:travel,1560 Broadway New York NY,0
+41,no,yes,reading:fashion:animals:dancing:writing,556 7th Ave New York NY,41,yes,yes,knitting:movies:writing:shopping:scrabble,404 E 14th St New York NY,1
+25,no,yes,soccer:computers:cooking,686 Avenue of the Americas New York NY,34,no,yes,skiing:fashion:photography:art:computers:camping:movies:shopping:tv:scrabble,427 10th Ave New York NY,1
+33,no,no,snowboarding:soccer:photography:computers:animals:writing,1083 2nd Ave New York NY,28,no,yes,knitting:fashion:photography:camping,404 E 14th St New York NY,0
+47,no,no,skiing:soccer:fashion:photography:animals:travel,90 Maiden Ln New York NY,34,yes,yes,football:running:reading:computers:dancing:opera:travel,151 W 34th St New York NY,0
+40,no,no,football:dancing:movies:shopping:scrabble,2271 Broadway New York NY,22,no,yes,skiing:computers:writing:shopping:cooking:scrabble,2049 Broadway New York NY,0
+33,yes,no,art:dancing:opera:writing:tv,2271 Broadway New York NY,33,no,yes,soccer:running:art:camping:dancing:writing:shopping:tv:scrabble,824 3rd Ave New York NY,1
+30,no,yes,knitting:computers:movies:opera:writing,824 3rd Ave New York NY,32,no,yes,football,686 Avenue of the Americas New York NY,1
+23,no,yes,,154 7th Ave New York NY,18,no,no,skiing:snowboarding:soccer:football:scrabble,1188 Avenue of the Americas New York NY,0
+26,yes,no,reading:fashion,208 Varick St New York NY,18,no,yes,photography:shopping:tv,1083 2nd Ave New York NY,0
+22,no,no,soccer:photography:art:movies:opera:shopping,102 1st Ave New York NY,46,no,yes,skiing:running:knitting:photography:dancing:tv:scrabble,336 E 23rd St New York NY,0
+44,yes,yes,skiing:soccer,3794 Broadway New York NY,23,no,no,knitting:photography:animals:camping:opera:writing:scrabble,427 10th Ave New York NY,0
+27,no,no,skiing:soccer:running:knitting:cooking:scrabble,600 W 125th St New York NY,31,no,no,art:camping:dancing:opera:writing,14 E 47th St New York NY,1
+27,no,yes,snowboarding:football:photography:computers:animals:scrabble,27 3rd Ave New York NY,27,yes,no,knitting:computers:camping:shopping:cooking:scrabble,151 W 34th St New York NY,0
+25,no,no,football:computers:animals:scrabble,1286 1st Ave New York NY,42,no,no,soccer:football:reading:art:camping:writing,90 Maiden Ln New York NY,0
+34,no,no,writing,154 7th Ave New York NY,47,yes,yes,opera:shopping:cooking,541 Avenue of the Americas New York NY,0
+28,no,yes,football:photography:dancing:shopping:scrabble,90 Maiden Ln New York NY,45,no,no,knitting:writing:travel:cooking,208 Varick St New York NY,0
+22,no,yes,soccer:knitting:computers:dancing:writing,151 W 34th St New York NY,21,no,yes,snowboarding:soccer:computers:writing:travel,541 Avenue of the Americas New York NY,1
+47,no,no,running:reading:art:camping,404 E 14th St New York NY,36,no,yes,snowboarding:reading:camping:dancing,27 3rd Ave New York NY,0
+36,yes,yes,reading:knitting:photography:camping:opera,2271 Broadway New York NY,42,yes,no,skiing:snowboarding:art:movies:writing,90 Maiden Ln New York NY,0
+22,no,no,photography:writing,102 1st Ave New York NY,31,no,yes,photography:dancing,336 E 23rd St New York NY,0
+48,no,yes,snowboarding:football:reading:movies:opera,1083 2nd Ave New York NY,35,no,yes,reading:knitting:camping:writing,2271 Broadway New York NY,1
+32,no,no,reading:knitting:art:computers:animals:travel,154 7th Ave New York NY,29,no,yes,skiing:reading:computers:cooking,2271 Broadway New York NY,0
+20,no,yes,fashion:photography:computers:tv:travel:scrabble,556 7th Ave New York NY,24,no,no,reading:computers:dancing:cooking:scrabble,1560 Broadway New York NY,0
+20,no,yes,dancing:scrabble,336 E 23rd St New York NY,41,yes,yes,running:reading:knitting:writing,3794 Broadway New York NY,0
+31,no,no,reading:computers:opera,1286 1st Ave New York NY,25,no,no,football:photography:computers:dancing:opera:tv:scrabble,1083 2nd Ave New York NY,1
+48,no,yes,reading:knitting:camping:opera,39 Union sq W New York NY,47,no,yes,skiing:writing,966 3rd Ave New York NY,1
+42,no,yes,fashion:animals:camping:travel,14 E 47th St New York NY,22,no,no,football:knitting:shopping:travel,39 Union sq W New York NY,0
+31,no,no,football:running:reading:camping:writing,336 E 23rd St New York NY,47,no,yes,movies,26 Bowery New York NY,0
+19,yes,no,art:animals:dancing:movies:shopping:scrabble,1083 2nd Ave New York NY,38,yes,yes,cooking,824 3rd Ave New York NY,0
+26,no,no,knitting:fashion:animals:dancing,686 Avenue of the Americas New York NY,29,no,no,cooking,688 8th Ave New York NY,1
+35,yes,yes,running:tv:travel,824 3rd Ave New York NY,46,no,yes,skiing:reading:computers:dancing,2049 Broadway New York NY,1
+32,no,no,skiing:fashion:dancing,336 E 23rd St New York NY,46,yes,no,football:art:animals:shopping,2271 Broadway New York NY,1
+28,yes,yes,fashion:animals:opera:shopping,404 E 14th St New York NY,24,yes,yes,running:animals:movies:writing:tv:cooking:scrabble,966 3rd Ave New York NY,1
+38,yes,yes,computers:writing,1286 1st Ave New York NY,42,no,no,snowboarding:art:shopping:cooking:scrabble,966 3rd Ave New York NY,0
+48,no,no,photography:computers,220 W 42nd St New York NY,46,yes,yes,snowboarding:knitting:camping:tv,151 W 34th St New York NY,0
+46,no,no,photography:writing,3794 Broadway New York NY,44,no,no,skiing:reading:fashion:travel:scrabble,336 E 23rd St New York NY,1
+25,no,yes,reading:knitting:art:animals:tv,90 Maiden Ln New York NY,38,no,no,soccer:knitting:writing,824 3rd Ave New York NY,0
+25,no,yes,art:scrabble,451 Lexington Ave New York NY,26,no,yes,skiing:computers:movies:tv:travel:cooking,556 7th Ave New York NY,1
+48,no,yes,skiing:football:running:knitting:photography:art:computers:opera:travel:cooking,336 E 23rd St New York NY,38,no,yes,photography:art,220 W 42nd St New York NY,1
+37,no,yes,soccer:camping:movies,14 E 47th St New York NY,42,no,no,art:dancing:travel:cooking,1286 1st Ave New York NY,0
+25,yes,no,camping:writing:shopping:scrabble,556 7th Ave New York NY,49,yes,yes,football:reading:computers:camping:movies:travel,1286 1st Ave New York NY,0
+45,yes,no,skiing:soccer:writing:travel,427 10th Ave New York NY,29,no,no,football:movies:writing,151 W 34th St New York NY,1
+24,yes,yes,snowboarding:reading:art:animals:camping:writing:shopping:cooking,404 E 14th St New York NY,40,no,yes,soccer:running:knitting:dancing:opera:shopping,220 W 42nd St New York NY,0
+43,no,no,movies:writing:scrabble,2049 Broadway New York NY,45,yes,no,running:camping:travel,336 E 23rd St New York NY,1
+34,yes,yes,snowboarding:reading:knitting:photography:camping:scrabble,966 3rd Ave New York NY,43,yes,yes,snowboarding:reading:knitting:dancing:writing:scrabble,2049 Broadway New York NY,1
+42,no,no,snowboarding:art:tv,1286 1st Ave New York NY,22,no,yes,running:art:computers:dancing:travel,404 E 14th St New York NY,0
+47,no,no,soccer:knitting:animals:tv,102 1st Ave New York NY,27,no,yes,soccer:football:cooking,600 W 125th St New York NY,0
+24,no,no,dancing,1499 3rd Ave New York NY,33,no,yes,running:photography:computers:animals:cooking,1560 Broadway New York NY,0
+29,no,no,skiing,102 1st Ave New York NY,39,yes,yes,running:fashion:scrabble,1499 3rd Ave New York NY,0
+41,no,no,photography:animals:dancing:writing:travel,966 3rd Ave New York NY,33,no,yes,fashion:dancing,336 E 23rd St New York NY,0
+48,no,no,football:knitting:dancing:opera:shopping:tv,102 1st Ave New York NY,28,yes,no,animals:dancing,26 Bowery New York NY,1
+20,no,yes,skiing:fashion:animals:camping,1499 3rd Ave New York NY,35,no,yes,soccer:football:running:fashion:movies:travel,688 8th Ave New York NY,0
+36,no,no,football:opera:writing:shopping:cooking,27 3rd Ave New York NY,21,no,no,skiing:football:art:animals:opera:writing:tv,1560 Broadway New York NY,1
+32,no,yes,skiing:art:tv:cooking,14 E 47th St New York NY,29,yes,yes,snowboarding:reading:knitting:opera,220 W 42nd St New York NY,1
+23,no,yes,snowboarding:art:opera,26 Bowery New York NY,22,yes,no,animals:dancing:travel,39 Union sq W New York NY,0
+22,no,no,skiing:photography:opera:cooking,404 E 14th St New York NY,47,no,no,movies:opera,208 Varick St New York NY,0
+39,no,no,running:reading:art:animals:shopping,102 1st Ave New York NY,28,yes,yes,snowboarding:football:animals:movies:shopping:scrabble,39 Union sq W New York NY,0
+44,no,yes,snowboarding:running:knitting:fashion:camping:shopping,102 1st Ave New York NY,27,no,yes,soccer:art:writing,1286 1st Ave New York NY,1
+20,no,no,running:camping,102 1st Ave New York NY,33,no,no,knitting,90 Maiden Ln New York NY,0
+48,no,yes,skiing:football:running:knitting:fashion:camping,3794 Broadway New York NY,36,yes,no,football:movies:opera,1083 2nd Ave New York NY,0
+29,no,yes,reading:computers:travel,1286 1st Ave New York NY,25,no,no,knitting:fashion:cooking:scrabble,600 W 125th St New York NY,0
+26,no,no,reading:cooking,27 3rd Ave New York NY,39,no,no,computers:camping:opera:travel:cooking,3794 Broadway New York NY,1
+46,no,yes,skiing:snowboarding:soccer:running:reading:fashion:shopping,404 E 14th St New York NY,27,yes,yes,soccer:tv,102 1st Ave New York NY,1
+25,no,yes,animals:camping:opera:travel:cooking,1083 2nd Ave New York NY,21,no,yes,football:reading:knitting:fashion:computers:movies:travel,404 E 14th St New York NY,1
+32,no,no,soccer:running:dancing:movies:shopping:tv,1286 1st Ave New York NY,41,no,no,soccer:running:animals:dancing,2049 Broadway New York NY,1
+37,yes,no,football:fashion:camping:opera:travel,208 Varick St New York NY,48,no,yes,snowboarding:football:camping,1560 Broadway New York NY,0
+25,no,yes,snowboarding:soccer:football:reading:fashion:photography:movies:writing,102 1st Ave New York NY,22,no,yes,computers:writing:tv,1286 1st Ave New York NY,1
+29,no,yes,soccer:reading:fashion:animals:dancing:writing:shopping:tv:cooking,154 7th Ave New York NY,33,no,yes,snowboarding:art:computers:animals:travel,451 Lexington Ave New York NY,1
+44,yes,no,skiing:soccer:writing,1499 3rd Ave New York NY,23,no,yes,soccer:reading:art:animals:dancing:opera,1286 1st Ave New York NY,0
+28,no,yes,knitting:computers:dancing:shopping:tv,824 3rd Ave New York NY,46,no,yes,football:fashion:art:dancing:opera,824 3rd Ave New York NY,0
+45,no,yes,computers:cooking,1499 3rd Ave New York NY,32,no,no,football:running:reading:opera,1188 Avenue of the Americas New York NY,0
+49,no,yes,skiing:fashion:writing:shopping:travel,404 E 14th St New York NY,26,yes,yes,skiing:camping:shopping:cooking,600 W 125th St New York NY,1
+47,no,yes,soccer:knitting:computers:camping:dancing:tv:scrabble,1083 2nd Ave New York NY,18,no,no,soccer:reading:animals:tv,1499 3rd Ave New York NY,0
+19,no,no,skiing:snowboarding:running:reading:fashion:camping:opera:writing:tv:travel,1286 1st Ave New York NY,29,no,no,snowboarding:soccer:art:opera,966 3rd Ave New York NY,0
+34,no,yes,running:writing,1083 2nd Ave New York NY,27,no,yes,snowboarding:fashion:writing:shopping:cooking,39 Union sq W New York NY,1
+34,no,no,running:movies:cooking,556 7th Ave New York NY,46,no,no,knitting:animals:camping:opera,688 8th Ave New York NY,1
+49,no,no,photography:shopping:tv:scrabble,686 Avenue of the Americas New York NY,33,no,yes,soccer:dancing:writing:shopping:travel,26 Bowery New York NY,0
+21,no,yes,football:fashion:camping:dancing:writing:cooking:scrabble,3794 Broadway New York NY,18,no,no,skiing:football:running:reading:fashion:computers,1499 3rd Ave New York NY,0
+20,no,yes,skiing:snowboarding:soccer:reading:opera:writing,1083 2nd Ave New York NY,37,no,no,running:reading:writing,27 3rd Ave New York NY,0
+49,no,no,skiing:soccer:computers:animals:opera,208 Varick St New York NY,40,no,yes,snowboarding:soccer:knitting:art:dancing:shopping:cooking,336 E 23rd St New York NY,0
+43,no,no,reading:art:computers:shopping:scrabble,2271 Broadway New York NY,44,no,no,animals:writing:tv,154 7th Ave New York NY,1
+44,no,yes,skiing:reading:camping:cooking,966 3rd Ave New York NY,24,no,no,knitting:computers:opera,2271 Broadway New York NY,0
+24,no,yes,football:knitting:art:camping:writing:shopping,2271 Broadway New York NY,24,no,no,skiing:animals:dancing:scrabble,686 Avenue of the Americas New York NY,0
+28,no,yes,skiing:snowboarding:reading:shopping,1083 2nd Ave New York NY,19,no,yes,skiing:snowboarding:soccer:knitting:art:opera,824 3rd Ave New York NY,1
+50,no,no,skiing:soccer:football:knitting:art:dancing:scrabble,151 W 34th St New York NY,21,yes,yes,soccer:football:reading:fashion:shopping:tv,541 Avenue of the Americas New York NY,0
+41,no,no,knitting:photography:computers:writing,688 8th Ave New York NY,38,no,yes,skiing:fashion:photography,966 3rd Ave New York NY,0
+19,no,no,photography:movies:shopping:tv:cooking:scrabble,3794 Broadway New York NY,44,no,no,reading:photography:computers:tv:travel,556 7th Ave New York NY,0
+44,no,no,,39 Union sq W New York NY,47,no,no,reading:fashion:art:animals,1286 1st Ave New York NY,1
+30,no,no,cooking:scrabble,27 3rd Ave New York NY,43,no,yes,fashion:photography:art:computers:animals:movies:travel:cooking,151 W 34th St New York NY,0
+36,no,no,fashion:camping:tv:cooking,2271 Broadway New York NY,42,no,yes,reading:photography,90 Maiden Ln New York NY,0
+40,no,no,soccer:knitting:photography:computers:movies,26 Bowery New York NY,46,no,no,football:knitting:photography:writing:tv:scrabble,336 E 23rd St New York NY,1
+35,no,yes,football:running:photography:computers:animals:travel,1188 Avenue of the Americas New York NY,38,no,yes,soccer:knitting:photography:art:computers:travel:cooking:scrabble,1499 3rd Ave New York NY,1
+29,no,yes,soccer:computers:opera:scrabble,688 8th Ave New York NY,22,no,yes,running:dancing:scrabble,1188 Avenue of the Americas New York NY,1
+18,no,yes,fashion:computers:opera,1083 2nd Ave New York NY,32,yes,no,writing,90 Maiden Ln New York NY,0
+27,no,no,snowboarding:animals:dancing,27 3rd Ave New York NY,33,no,no,soccer:reading:computers:camping,39 Union sq W New York NY,1
+18,yes,yes,snowboarding:running:animals:camping:opera,26 Bowery New York NY,46,no,yes,snowboarding:soccer:football:running:animals:camping:opera:shopping,1083 2nd Ave New York NY,0
+26,no,no,skiing:soccer,966 3rd Ave New York NY,18,no,no,snowboarding:running:fashion:computers:writing:shopping,1188 Avenue of the Americas New York NY,1
+35,no,no,skiing:football:writing,404 E 14th St New York NY,49,no,no,photography:scrabble,1499 3rd Ave New York NY,1
+18,no,no,skiing:football:running:fashion:tv,600 W 125th St New York NY,44,no,yes,football:animals:shopping:travel,102 1st Ave New York NY,0
+18,no,no,football:photography:animals:cooking,14 E 47th St New York NY,38,no,yes,reading:fashion:art:opera:tv:cooking,14 E 47th St New York NY,0
+40,yes,yes,skiing:opera:scrabble,151 W 34th St New York NY,34,no,yes,snowboarding:animals:shopping,600 W 125th St New York NY,1
+21,no,yes,camping:opera:writing:cooking,336 E 23rd St New York NY,19,no,yes,skiing:running:reading:art:scrabble,404 E 14th St New York NY,1
+31,yes,yes,soccer:photography:camping:movies:opera:tv:scrabble,556 7th Ave New York NY,39,no,no,reading:knitting:computers,541 Avenue of the Americas New York NY,0
+29,no,yes,knitting:photography:animals:movies:opera:shopping:cooking,404 E 14th St New York NY,27,yes,no,skiing:knitting:movies:tv:cooking,688 8th Ave New York NY,1
+31,no,yes,opera,14 E 47th St New York NY,50,yes,no,fashion:art:computers:movies:tv,541 Avenue of the Americas New York NY,0
+22,no,yes,snowboarding:art:animals:shopping:tv:travel,208 Varick St New York NY,19,yes,yes,snowboarding:soccer:running,1188 Avenue of the Americas New York NY,1
+35,no,no,knitting:art:camping:opera,220 W 42nd St New York NY,35,no,no,skiing:soccer:football:reading,1083 2nd Ave New York NY,1
+43,no,yes,football:art:animals,26 Bowery New York NY,46,no,yes,soccer:photography:computers:camping:shopping,26 Bowery New York NY,1
+44,yes,no,fashion:art:writing,600 W 125th St New York NY,24,no,yes,running:art:dancing:opera:writing,151 W 34th St New York NY,0
+23,no,no,knitting:computers:camping:writing:cooking,686 Avenue of the Americas New York NY,28,yes,no,reading:computers:movies:writing,2271 Broadway New York NY,1
+40,no,no,snowboarding:soccer:reading:fashion:camping:cooking,3794 Broadway New York NY,43,no,yes,snowboarding:soccer:computers:animals:dancing:opera,151 W 34th St New York NY,0
+20,no,no,knitting:animals:tv:travel:cooking:scrabble,1083 2nd Ave New York NY,47,yes,no,soccer:reading:photography:dancing:writing:scrabble,208 Varick St New York NY,0
+23,no,yes,skiing:soccer:football:reading:camping:opera:writing:travel,90 Maiden Ln New York NY,31,no,no,snowboarding:fashion:computers:movies:opera:travel,151 W 34th St New York NY,0
+46,no,yes,fashion:opera:writing:shopping,26 Bowery New York NY,31,no,no,skiing:fashion:dancing:scrabble,220 W 42nd St New York NY,0
+48,no,no,dancing:writing:cooking,1286 1st Ave New York NY,40,no,yes,fashion:writing:tv:scrabble,600 W 125th St New York NY,0
+23,no,yes,movies:writing:shopping,102 1st Ave New York NY,49,yes,no,skiing:running:knitting:animals:opera:writing:tv,154 7th Ave New York NY,0
+21,no,yes,reading:fashion:computers,14 E 47th St New York NY,45,no,yes,,26 Bowery New York NY,0
+24,no,yes,running:photography:writing:scrabble,1083 2nd Ave New York NY,24,no,no,animals:tv,2049 Broadway New York NY,0
+45,no,yes,snowboarding:knitting:opera:scrabble,26 Bowery New York NY,21,yes,yes,football:running:dancing:cooking,824 3rd Ave New York NY,0
+33,no,yes,reading:computers:shopping:cooking:scrabble,556 7th Ave New York NY,46,yes,no,snowboarding:football:photography:dancing:travel:cooking,427 10th Ave New York NY,0
+37,no,no,snowboarding:running:knitting:art:movies:writing,1560 Broadway New York NY,39,no,yes,knitting:photography:writing:shopping:travel,451 Lexington Ave New York NY,0
+33,no,yes,snowboarding:photography:art:movies,686 Avenue of the Americas New York NY,36,no,yes,running:computers:travel:cooking,1083 2nd Ave New York NY,1
+23,no,no,soccer:running:photography,154 7th Ave New York NY,29,no,yes,skiing:running:fashion:photography,2271 Broadway New York NY,0
+35,no,yes,soccer:running:reading:travel:scrabble,1286 1st Ave New York NY,20,yes,yes,soccer:football:knitting:fashion:tv,336 E 23rd St New York NY,1
+23,no,no,skiing:animals:camping:writing:tv,90 Maiden Ln New York NY,38,yes,yes,snowboarding:soccer:football:photography:computers:opera:shopping,541 Avenue of the Americas New York NY,0
+48,no,no,snowboarding:football:writing:tv,1188 Avenue of the Americas New York NY,45,no,no,knitting:computers,14 E 47th St New York NY,1
+27,no,yes,skiing:reading:dancing:cooking,556 7th Ave New York NY,20,yes,yes,knitting:writing:scrabble,541 Avenue of the Americas New York NY,1
+37,no,no,snowboarding:soccer:football:computers:shopping:travel,27 3rd Ave New York NY,39,no,no,running:camping,336 E 23rd St New York NY,1
+24,no,yes,computers:camping:dancing:tv:scrabble,26 Bowery New York NY,47,no,no,snowboarding:fashion:shopping:cooking,541 Avenue of the Americas New York NY,0
+49,no,no,knitting:movies,688 8th Ave New York NY,24,yes,no,running:photography:movies:writing:cooking,14 E 47th St New York NY,0
+33,no,yes,soccer:photography:camping:tv:cooking,686 Avenue of the Americas New York NY,22,no,no,football:writing,27 3rd Ave New York NY,0
+21,yes,yes,fashion:dancing:opera:tv,154 7th Ave New York NY,32,no,no,fashion:scrabble,154 7th Ave New York NY,0
+45,no,yes,skiing:snowboarding:running:cooking:scrabble,451 Lexington Ave New York NY,28,no,yes,football:running:computers:opera,824 3rd Ave New York NY,1
+33,yes,yes,snowboarding:football:reading:animals:dancing:writing:cooking,27 3rd Ave New York NY,50,no,no,fashion:photography:art,14 E 47th St New York NY,0
+19,no,no,football:photography:dancing,1083 2nd Ave New York NY,34,no,yes,snowboarding:photography:opera,2049 Broadway New York NY,0
+35,no,yes,skiing:snowboarding:soccer:photography:computers:dancing:cooking,541 Avenue of the Americas New York NY,23,no,yes,reading:fashion:opera:shopping:scrabble,39 Union sq W New York NY,1
+38,no,no,skiing:football:reading:fashion:photography:camping:movies:opera,14 E 47th St New York NY,31,no,yes,photography:shopping:travel,90 Maiden Ln New York NY,0
+19,no,yes,soccer:knitting:fashion:computers:dancing:shopping:scrabble,600 W 125th St New York NY,30,no,yes,reading:fashion:animals:travel:scrabble,90 Maiden Ln New York NY,0
+22,yes,yes,running:computers:animals:dancing:movies,336 E 23rd St New York NY,34,no,yes,soccer:football:fashion:animals:tv,688 8th Ave New York NY,0
+36,no,yes,skiing:photography:movies,404 E 14th St New York NY,33,no,no,football:reading:knitting:animals:movies:opera:cooking,154 7th Ave New York NY,0
+42,no,yes,running:fashion:computers:dancing:movies,14 E 47th St New York NY,25,no,no,skiing:soccer:reading:fashion:computers:camping,1083 2nd Ave New York NY,0
+29,no,yes,reading:art:scrabble,90 Maiden Ln New York NY,27,no,yes,snowboarding:running:reading,556 7th Ave New York NY,1
+48,no,yes,art:dancing:travel,451 Lexington Ave New York NY,48,no,yes,reading:movies:travel,90 Maiden Ln New York NY,1
+27,no,no,fashion:photography:dancing:opera:shopping:cooking,541 Avenue of the Americas New York NY,26,no,no,knitting:computers:tv,39 Union sq W New York NY,1
+48,no,yes,skiing:reading:computers:opera,1560 Broadway New York NY,48,no,no,skiing:tv:travel,556 7th Ave New York NY,0
+26,no,no,photography:travel,1188 Avenue of the Americas New York NY,35,no,yes,movies:travel,1499 3rd Ave New York NY,0
+22,no,yes,soccer:running:fashion:art:opera:travel,102 1st Ave New York NY,43,no,yes,snowboarding:reading:computers:shopping:travel:cooking,220 W 42nd St New York NY,0
+33,yes,no,skiing:soccer:reading:fashion:computers:movies:shopping:cooking,600 W 125th St New York NY,48,no,no,snowboarding:soccer:fashion:computers:camping,208 Varick St New York NY,1
+24,no,yes,photography:opera,688 8th Ave New York NY,49,no,yes,soccer:animals:writing:tv,2049 Broadway New York NY,0
+33,no,no,snowboarding:reading:movies:writing:shopping,1286 1st Ave New York NY,48,yes,no,reading:fashion:scrabble,404 E 14th St New York NY,1
+26,no,yes,knitting:movies:writing:tv:scrabble,1560 Broadway New York NY,26,no,no,snowboarding:soccer:reading:knitting:animals:tv,451 Lexington Ave New York NY,0
+30,no,no,opera:tv,3794 Broadway New York NY,29,no,yes,soccer:running:dancing:movies:writing:tv,966 3rd Ave New York NY,0
+25,no,no,snowboarding:reading:movies:scrabble,2049 Broadway New York NY,49,no,yes,running:reading:photography:computers,2271 Broadway New York NY,0
+38,no,yes,snowboarding:football:running:photography:shopping:cooking,686 Avenue of the Americas New York NY,23,no,no,running:fashion:shopping:tv,824 3rd Ave New York NY,0
+39,no,no,soccer:dancing:tv:scrabble,1560 Broadway New York NY,39,no,no,football:reading:knitting:art:animals:dancing:travel:cooking,90 Maiden Ln New York NY,1
+27,no,no,football:running:knitting:fashion:travel,154 7th Ave New York NY,31,no,yes,computers:shopping:travel,427 10th Ave New York NY,0
+28,no,yes,running:knitting:photography:dancing:movies,966 3rd Ave New York NY,46,no,yes,knitting:shopping,404 E 14th St New York NY,0
+50,no,no,skiing:snowboarding:reading:computers:movies:travel:cooking:scrabble,824 3rd Ave New York NY,49,no,no,fashion:camping,27 3rd Ave New York NY,1
+34,yes,yes,soccer,688 8th Ave New York NY,48,no,yes,art:shopping:cooking:scrabble,404 E 14th St New York NY,1
+30,yes,yes,computers:camping:scrabble,427 10th Ave New York NY,37,no,no,skiing:snowboarding:reading:knitting:computers:tv,39 Union sq W New York NY,0
+27,yes,yes,running:camping:tv:travel:scrabble,824 3rd Ave New York NY,32,no,no,snowboarding:knitting:fashion:shopping,824 3rd Ave New York NY,0
+31,no,no,knitting:photography:dancing:shopping,541 Avenue of the Americas New York NY,25,no,yes,snowboarding:camping,1083 2nd Ave New York NY,0
+30,yes,no,snowboarding:art:camping:travel,556 7th Ave New York NY,32,yes,yes,skiing:snowboarding:knitting:animals:movies:opera:travel,336 E 23rd St New York NY,0
+42,no,yes,reading:travel,2271 Broadway New York NY,35,yes,no,skiing:snowboarding:computers:animals:dancing:opera,2049 Broadway New York NY,0
+25,no,yes,knitting:art:animals:camping:writing,220 W 42nd St New York NY,34,no,no,skiing:soccer:shopping,1188 Avenue of the Americas New York NY,0
+37,yes,yes,soccer:running:fashion:tv,824 3rd Ave New York NY,42,no,yes,running:photography:animals:dancing:opera:travel:cooking:scrabble,1083 2nd Ave New York NY,1
+47,yes,no,reading:fashion:photography,451 Lexington Ave New York NY,29,no,no,reading:dancing:movies:writing:shopping:tv,404 E 14th St New York NY,1
+31,no,no,camping:writing:scrabble,102 1st Ave New York NY,33,no,no,soccer:animals:dancing:writing:travel,686 Avenue of the Americas New York NY,1
+28,no,yes,reading:camping:scrabble,688 8th Ave New York NY,39,no,yes,skiing:running:shopping,14 E 47th St New York NY,1
+35,no,no,football:knitting:writing:shopping:tv,208 Varick St New York NY,48,yes,yes,skiing:photography:art:travel,686 Avenue of the Americas New York NY,0
+32,no,no,skiing:reading:photography:animals:dancing,451 Lexington Ave New York NY,35,no,no,soccer:reading:art,824 3rd Ave New York NY,1
+20,no,no,snowboarding:running:computers:camping:tv,688 8th Ave New York NY,49,no,no,football:reading,154 7th Ave New York NY,0
+27,no,yes,computers:opera,2271 Broadway New York NY,48,no,no,knitting:photography:animals:camping:dancing:tv:scrabble,39 Union sq W New York NY,0
+22,no,yes,photography:art:animals:opera:cooking,688 8th Ave New York NY,25,yes,no,art,27 3rd Ave New York NY,0
+38,no,yes,soccer:reading:dancing,2271 Broadway New York NY,18,no,yes,running:photography:computers:shopping,151 W 34th St New York NY,1
+43,no,yes,running:reading:scrabble,1083 2nd Ave New York NY,28,no,yes,photography:computers:writing:shopping:scrabble,451 Lexington Ave New York NY,1
+32,no,no,snowboarding:soccer:fashion:camping:opera:scrabble,26 Bowery New York NY,44,no,yes,reading:fashion:art:cooking:scrabble,2271 Broadway New York NY,0
+44,yes,yes,art:computers:animals:movies:writing:travel,1188 Avenue of the Americas New York NY,24,no,yes,reading:art:computers:travel:cooking,600 W 125th St New York NY,0
+19,no,no,skiing:soccer:running:reading:computers:animals:camping,3794 Broadway New York NY,34,yes,yes,skiing:running:dancing,824 3rd Ave New York NY,0
+36,no,yes,football:art:computers:animals:opera:tv:scrabble,686 Avenue of the Americas New York NY,31,yes,yes,fashion:photography:scrabble,102 1st Ave New York NY,1
+24,no,yes,snowboarding:soccer:football:photography:art:camping:dancing,600 W 125th St New York NY,37,yes,yes,camping:shopping,427 10th Ave New York NY,0
+41,no,yes,photography:art:computers:animals:dancing:shopping:travel:cooking,220 W 42nd St New York NY,49,yes,no,snowboarding:writing:cooking,427 10th Ave New York NY,0
+22,no,yes,computers:writing:tv,404 E 14th St New York NY,43,yes,no,animals:movies:writing:scrabble,1499 3rd Ave New York NY,0
+24,no,yes,fashion:movies:cooking:scrabble,686 Avenue of the Americas New York NY,32,yes,yes,skiing:running:scrabble,14 E 47th St New York NY,1
+42,no,yes,football:knitting:dancing:writing,3794 Broadway New York NY,27,yes,no,animals:opera:cooking,102 1st Ave New York NY,0
+29,no,no,reading:art:dancing:shopping:travel,154 7th Ave New York NY,23,no,no,snowboarding:football:computers:camping:movies,14 E 47th St New York NY,1
+32,no,yes,running:photography:art:movies:writing,208 Varick St New York NY,27,yes,yes,skiing:knitting:art:travel,151 W 34th St New York NY,1
+39,no,no,computers:camping:writing:tv,1286 1st Ave New York NY,20,no,no,running:opera:tv:travel,1286 1st Ave New York NY,1
+45,no,yes,art:camping:writing:shopping,1188 Avenue of the Americas New York NY,22,yes,yes,movies:travel,154 7th Ave New York NY,0
+36,no,yes,skiing:snowboarding:running:cooking,1083 2nd Ave New York NY,39,no,yes,skiing:football:fashion:photography:art:dancing:opera:travel,2049 Broadway New York NY,1
+18,no,yes,snowboarding:reading:photography:art:dancing,1499 3rd Ave New York NY,35,no,yes,soccer:knitting:shopping,451 Lexington Ave New York NY,0
+40,no,no,football:knitting:fashion:computers:animals:cooking,3794 Broadway New York NY,48,no,yes,skiing:snowboarding:soccer:computers:opera:tv:cooking,208 Varick St New York NY,0
+29,no,yes,snowboarding:reading:camping:dancing:shopping:tv,14 E 47th St New York NY,46,no,no,art:dancing:opera:scrabble,102 1st Ave New York NY,0
+25,no,yes,animals,336 E 23rd St New York NY,22,no,yes,snowboarding:writing:scrabble,336 E 23rd St New York NY,1
+38,no,yes,football:reading:camping:dancing:opera:writing,1560 Broadway New York NY,37,yes,no,skiing:snowboarding:running:knitting:dancing:opera:cooking:scrabble,451 Lexington Ave New York NY,0
+25,no,no,skiing:reading:fashion:camping:writing:scrabble,102 1st Ave New York NY,43,no,yes,skiing:soccer:running:art:opera,2271 Broadway New York NY,0
+44,no,yes,running:reading:movies,3794 Broadway New York NY,47,no,yes,football:movies:writing:shopping,3794 Broadway New York NY,1
+39,no,no,computers:camping:opera:tv,154 7th Ave New York NY,48,no,yes,skiing:knitting:camping:opera:cooking,336 E 23rd St New York NY,0
+41,no,yes,skiing:soccer:reading:camping,27 3rd Ave New York NY,43,no,no,soccer:running:dancing:opera:tv,2049 Broadway New York NY,0
+37,no,yes,soccer:fashion:dancing:opera:cooking,688 8th Ave New York NY,45,no,yes,camping:opera:shopping:scrabble,427 10th Ave New York NY,1
+50,no,yes,snowboarding:soccer:camping:dancing,966 3rd Ave New York NY,25,no,yes,skiing:computers:animals:opera:shopping:travel,220 W 42nd St New York NY,1
+35,no,no,running:knitting:art:tv,541 Avenue of the Americas New York NY,23,no,no,art,208 Varick St New York NY,1
+38,no,yes,running:tv:cooking:scrabble,1286 1st Ave New York NY,24,no,yes,snowboarding:movies,2271 Broadway New York NY,1
+41,yes,no,skiing,2049 Broadway New York NY,39,no,yes,skiing:soccer:art:dancing,208 Varick St New York NY,0
+26,no,no,knitting:photography:animals:shopping,336 E 23rd St New York NY,34,yes,yes,soccer:photography:camping:movies:writing,220 W 42nd St New York NY,0
+39,yes,no,opera:tv,154 7th Ave New York NY,50,yes,no,writing:cooking,27 3rd Ave New York NY,1
+40,no,no,snowboarding:dancing:scrabble,151 W 34th St New York NY,24,no,no,football:opera:scrabble,102 1st Ave New York NY,1
+47,no,yes,running,404 E 14th St New York NY,31,no,yes,computers:tv:cooking,451 Lexington Ave New York NY,1
+30,no,no,soccer:knitting:dancing:writing:shopping:tv,208 Varick St New York NY,18,no,no,knitting:opera:tv:scrabble,404 E 14th St New York NY,1
+29,yes,yes,reading:knitting:animals:cooking,208 Varick St New York NY,44,no,yes,reading:photography:animals,208 Varick St New York NY,1
+21,no,no,soccer:art:dancing:movies:writing:tv,220 W 42nd St New York NY,33,no,no,running:computers:camping:shopping:tv,966 3rd Ave New York NY,0
+41,no,yes,running:photography:writing:tv,2271 Broadway New York NY,18,no,no,football:reading:photography:travel,686 Avenue of the Americas New York NY,0
+32,no,no,skiing:running:animals:movies:travel,686 Avenue of the Americas New York NY,29,no,no,football:knitting:photography:art,90 Maiden Ln New York NY,1
+19,yes,no,fashion:computers:movies:cooking,14 E 47th St New York NY,20,no,no,snowboarding:art:cooking,2049 Broadway New York NY,1
+27,no,yes,snowboarding:football:running:art:computers:tv:cooking,1560 Broadway New York NY,21,no,yes,computers,824 3rd Ave New York NY,1
+46,no,no,art:camping:opera:cooking,600 W 125th St New York NY,34,no,no,football:photography:animals:dancing,1499 3rd Ave New York NY,1
+28,no,yes,skiing:football:photography:writing:shopping,427 10th Ave New York NY,34,no,yes,fashion:computers:travel:scrabble,427 10th Ave New York NY,1
+28,no,no,skiing:cooking,1560 Broadway New York NY,31,no,no,skiing:camping:dancing:cooking,686 Avenue of the Americas New York NY,1
+39,yes,no,photography:art:animals:camping:cooking:scrabble,1560 Broadway New York NY,39,no,no,knitting:computers,427 10th Ave New York NY,1
+42,yes,no,shopping:travel,154 7th Ave New York NY,18,no,no,skiing:football:running:reading:animals:camping:writing:tv:cooking,102 1st Ave New York NY,0
+47,no,no,photography:art:camping:travel:cooking,2271 Broadway New York NY,25,no,no,soccer:reading:fashion:photography:art:camping:travel:cooking,1286 1st Ave New York NY,1
+23,no,yes,fashion:computers:travel,556 7th Ave New York NY,19,no,no,skiing:running:fashion:art:computers:scrabble,686 Avenue of the Americas New York NY,0
+48,no,no,knitting:art:camping:scrabble,451 Lexington Ave New York NY,49,no,yes,camping:opera:travel,26 Bowery New York NY,0
+47,no,no,snowboarding:running:photography:dancing:opera:writing:travel:cooking,1083 2nd Ave New York NY,45,no,yes,knitting:fashion:photography:movies:tv,1560 Broadway New York NY,0
+20,yes,yes,skiing:snowboarding:soccer:computers,451 Lexington Ave New York NY,20,no,yes,snowboarding:photography,600 W 125th St New York NY,1
+34,yes,yes,computers:camping:movies:shopping:tv,27 3rd Ave New York NY,28,no,yes,snowboarding:soccer:running:reading:travel:cooking,1560 Broadway New York NY,1
+43,no,yes,reading:art:writing,824 3rd Ave New York NY,32,no,yes,fashion:photography:camping:movies:writing:cooking:scrabble,14 E 47th St New York NY,1
+33,yes,yes,snowboarding:art:animals:dancing:writing:travel:cooking,90 Maiden Ln New York NY,24,no,no,fashion:shopping:travel:cooking,208 Varick St New York NY,0
+48,no,yes,football:reading:photography:art:movies:shopping,541 Avenue of the Americas New York NY,36,yes,no,snowboarding:football:reading:art:animals:movies,26 Bowery New York NY,1
+31,no,yes,animals:camping,336 E 23rd St New York NY,39,no,yes,running:animals:travel,26 Bowery New York NY,1
+29,no,no,art:camping:scrabble,2271 Broadway New York NY,22,no,yes,football:camping,451 Lexington Ave New York NY,0
+46,yes,yes,animals:dancing:opera:cooking,451 Lexington Ave New York NY,25,yes,no,snowboarding:soccer:camping:cooking,824 3rd Ave New York NY,0
+30,no,no,skiing:writing,451 Lexington Ave New York NY,45,no,yes,snowboarding:knitting:movies,39 Union sq W New York NY,0
+45,no,yes,snowboarding:soccer:photography:computers:dancing:opera:writing:tv:scrabble,3794 Broadway New York NY,31,no,yes,football:computers:tv:travel,90 Maiden Ln New York NY,1
+40,no,no,photography:writing:travel:cooking:scrabble,154 7th Ave New York NY,43,no,no,football:camping:travel,1083 2nd Ave New York NY,1
+30,no,yes,football:writing:travel,686 Avenue of the Americas New York NY,39,no,yes,skiing:snowboarding:soccer:football:dancing:travel,2271 Broadway New York NY,1
+30,no,yes,dancing,27 3rd Ave New York NY,24,yes,no,skiing:computers:travel,686 Avenue of the Americas New York NY,0
+43,no,no,fashion:dancing:movies:writing,404 E 14th St New York NY,25,no,yes,photography:camping:dancing:writing:shopping:tv,336 E 23rd St New York NY,0
+40,yes,no,snowboarding:soccer:football:reading:art:animals:dancing:movies,1286 1st Ave New York NY,47,no,yes,fashion:opera:travel:cooking:scrabble,427 10th Ave New York NY,0
+43,no,no,skiing:football:fashion:art,427 10th Ave New York NY,19,yes,yes,snowboarding:knitting:computers:animals:opera:tv,102 1st Ave New York NY,0
+48,no,no,skiing:soccer:running:computers,1560 Broadway New York NY,45,yes,yes,skiing:knitting:dancing:shopping:tv,39 Union sq W New York NY,0
+33,no,no,photography:opera:scrabble,3794 Broadway New York NY,29,yes,no,football:knitting:art:camping,1286 1st Ave New York NY,1
+45,no,no,running:photography:computers:animals:shopping:travel,154 7th Ave New York NY,48,no,no,snowboarding:football:dancing,151 W 34th St New York NY,1
+21,yes,no,snowboarding:fashion:movies:tv:scrabble,90 Maiden Ln New York NY,27,no,no,reading:opera:shopping:tv:travel,220 W 42nd St New York NY,0
+30,no,yes,computers:tv:travel,1188 Avenue of the Americas New York NY,32,no,yes,soccer:computers:dancing,336 E 23rd St New York NY,1
+49,no,yes,snowboarding:animals,451 Lexington Ave New York NY,38,no,no,computers:movies:tv:travel,26 Bowery New York NY,0
+40,yes,yes,skiing:running:camping,1286 1st Ave New York NY,42,no,no,snowboarding:soccer:football:running:photography:camping:tv,14 E 47th St New York NY,0
+21,no,no,skiing:football:opera,336 E 23rd St New York NY,22,no,no,dancing:tv:cooking,102 1st Ave New York NY,1
+23,no,no,soccer:photography:camping,2049 Broadway New York NY,21,yes,yes,snowboarding:art:animals,686 Avenue of the Americas New York NY,0
+28,no,yes,skiing:photography:cooking,1286 1st Ave New York NY,24,no,yes,football:photography:movies:writing:travel:cooking,404 E 14th St New York NY,1
+24,no,no,running:knitting:writing:tv:cooking,154 7th Ave New York NY,23,no,yes,skiing:soccer:reading,2271 Broadway New York NY,0
+19,no,no,animals:dancing:tv,824 3rd Ave New York NY,39,no,no,knitting:fashion:photography:writing,3794 Broadway New York NY,0
+22,no,no,skiing:soccer:reading:knitting:photography:opera:scrabble,151 W 34th St New York NY,41,yes,no,skiing:soccer:football:photography:dancing:movies:shopping,404 E 14th St New York NY,0
+45,no,no,football:photography,3794 Broadway New York NY,32,no,yes,knitting:fashion:dancing,824 3rd Ave New York NY,0
+45,no,no,skiing:football:knitting:tv,1499 3rd Ave New York NY,24,no,no,photography:dancing:shopping:travel:scrabble,102 1st Ave New York NY,0
+30,no,no,fashion:dancing:scrabble,220 W 42nd St New York NY,36,no,yes,snowboarding:movies:scrabble,26 Bowery New York NY,0
+20,yes,yes,soccer:reading:opera:scrabble,151 W 34th St New York NY,18,no,no,snowboarding:fashion:movies,451 Lexington Ave New York NY,0
+20,no,no,skiing:soccer:fashion:dancing:opera:shopping:travel:cooking:scrabble,824 3rd Ave New York NY,24,yes,no,soccer:fashion:photography:computers,27 3rd Ave New York NY,0
+39,no,yes,skiing:soccer:running:reading:art:dancing:shopping:travel,600 W 125th St New York NY,49,no,yes,running:writing:shopping:cooking,824 3rd Ave New York NY,1
+24,no,no,fashion:art:dancing:cooking,102 1st Ave New York NY,23,no,yes,photography:opera:tv,336 E 23rd St New York NY,0
+49,no,no,skiing:knitting:art:animals:camping:tv:scrabble,404 E 14th St New York NY,20,no,yes,football:computers:animals:opera:writing:shopping,427 10th Ave New York NY,0
+40,no,yes,skiing:soccer:football:computers:movies,3794 Broadway New York NY,40,yes,yes,skiing:snowboarding:football:opera:scrabble,220 W 42nd St New York NY,1
+49,yes,no,knitting:writing:shopping,427 10th Ave New York NY,25,no,no,skiing:football:knitting:photography:shopping,3794 Broadway New York NY,1
+37,no,no,soccer:fashion:opera,427 10th Ave New York NY,48,no,yes,writing:travel:cooking,208 Varick St New York NY,0
+34,yes,no,movies:cooking,556 7th Ave New York NY,37,yes,no,skiing:football:photography:art:writing:scrabble,688 8th Ave New York NY,1
+31,no,yes,snowboarding:fashion:camping,90 Maiden Ln New York NY,50,yes,yes,skiing:snowboarding:soccer:shopping,1499 3rd Ave New York NY,1
+28,no,no,snowboarding:cooking,27 3rd Ave New York NY,26,no,no,knitting:fashion:photography:art:camping:scrabble,427 10th Ave New York NY,1
+31,no,no,soccer:reading,404 E 14th St New York NY,46,no,no,snowboarding:soccer:running:reading:knitting:photography:computers:shopping,427 10th Ave New York NY,1
+30,no,no,skiing,102 1st Ave New York NY,41,yes,no,knitting:opera:writing:tv:travel:scrabble,966 3rd Ave New York NY,1
+23,no,yes,computers:tv,404 E 14th St New York NY,34,no,yes,soccer:football:running:camping:dancing,27 3rd Ave New York NY,0
+42,no,no,running:photography:writing:travel:cooking,1560 Broadway New York NY,22,no,yes,running:art:animals:dancing:shopping:tv,336 E 23rd St New York NY,0
+50,no,no,snowboarding:running:fashion:writing:tv:cooking,27 3rd Ave New York NY,43,no,no,snowboarding:fashion:animals:writing:travel,39 Union sq W New York NY,1
+43,yes,no,knitting:photography:animals:dancing,427 10th Ave New York NY,45,no,no,knitting:computers:writing:cooking,966 3rd Ave New York NY,1
+24,no,yes,snowboarding:running:fashion:cooking,1560 Broadway New York NY,44,no,no,soccer:photography:writing,2049 Broadway New York NY,0
+25,no,yes,soccer:football:reading,2049 Broadway New York NY,18,no,yes,football:reading,541 Avenue of the Americas New York NY,1
+39,no,yes,running:fashion:art:travel,556 7th Ave New York NY,39,no,no,knitting:photography,404 E 14th St New York NY,0
+27,no,no,running:fashion:computers,966 3rd Ave New York NY,20,no,yes,running:reading:knitting:dancing:writing:tv:cooking:scrabble,966 3rd Ave New York NY,0

File Chapter7/numpredict.py

+from random import random,randint
+import math
+
+def wineprice(rating,age):
+  peak_age=rating-50
+  
+  # Calculate price based on rating
+  price=rating/2
+  if age>peak_age:
+    # Past its peak, goes bad in 10 years
+    price=price*(5-(age-peak_age)/2)
+  else:
+    # Increases to 5x original value as it
+    # approaches its peak
+    price=price*(5*((age+1)/peak_age))
+  if price<0: price=0
+  return price
+
+
+def wineset1():
+  rows=[]
+  for i in range(300):
+    # Create a random age and rating
+    rating=random()*50+50
+    age=random()*50
+
+    # Get reference price
+    price=wineprice(rating,age)
+    
+    # Add some noise
+    price*=(random()*0.2+0.9)
+
+    # Add to the dataset
+    rows.append({'input':(rating,age),
+                 'result':price})
+  return rows
+
+def euclidean(v1,v2):
+  d=0.0
+  for i in range(len(v1)):
+    d+=(v1[i]-v2[i])**2
+  return math.sqrt(d)
+
+
+def getdistances(data,vec1):
+  distancelist=[]
+  
+  # Loop over every item in the dataset
+  for i in range(len(data)):
+    vec2=data[i]['input']
+    
+    # Add the distance and the index
+    distancelist.append((euclidean(vec1,vec2),i))
+  
+  # Sort by distance
+  distancelist.sort()
+  return distancelist
+
+def knnestimate(data,vec1,k=5):
+  # Get sorted distances
+  dlist=getdistances(data,vec1)
+  avg=0.0
+  
+  # Take the average of the top k results
+  for i in range(k):
+    idx=dlist[i][1]
+    avg+=data[idx]['result']
+  avg=avg/k
+  return avg
+
+def inverseweight(dist,num=1.0,const=0.1):
+  return num/(dist+const)
+
+def subtractweight(dist,const=1.0):
+  if dist>const: 
+    return 0
+  else: 
+    return const-dist
+
+def gaussian(dist,sigma=5.0):
+  return math.e**(-dist**2/(2*sigma**2))
+
+def weightedknn(data,vec1,k=5,weightf=gaussian):
+  # Get distances
+  dlist=getdistances(data,vec1)
+  avg=0.0
+  totalweight=0.0
+  
+  # Get weighted average
+  for i in range(k):
+    dist=dlist[i][0]
+    idx=dlist[i][1]
+    weight=weightf(dist)
+    avg+=weight*data[idx]['result']
+    totalweight+=weight
+  if totalweight==0: return 0
+  avg=avg/totalweight
+  return avg
+
+def dividedata(data,test=0.05):
+  trainset=[]
+  testset=[]
+  for row in data:
+    if random()<test:
+      testset.append(row)
+    else:
+      trainset.append(row)
+  return trainset,testset
+
+def testalgorithm(algf,trainset,testset):
+  error=0.0
+  for row in testset:
+    guess=algf(trainset,row['input'])
+    error+=(row['result']-guess)**2
+    #print row['result'],guess
+  #print error/len(testset)
+  return error/len(testset)
+
+def crossvalidate(algf,data,trials=100,test=0.1):
+  error=0.0
+  for i in range(trials):
+    trainset,testset=dividedata(data,test)
+    error+=testalgorithm(algf,trainset,testset)
+  return error/trials
+
+def wineset2():
+  rows=[]
+  for i in range(300):
+    rating=random()*50+50
+    age=random()*50
+    aisle=float(randint(1,20))
+    bottlesize=[375.0,750.0,1500.0][randint(0,2)]
+    price=wineprice(rating,age)
+    price*=(bottlesize/750)
+    price*=(random()*0.2+0.9)
+    rows.append({'input':(rating,age,aisle,bottlesize),
+                 'result':price})
+  return rows
+
+def rescale(data,scale):
+  scaleddata=[]
+  for row in data:
+    scaled=[scale[i]*row['input'][i] for i in range(len(scale))]
+    scaleddata.append({'input':scaled,'result':row['result']})
+  return scaleddata
+
+def createcostfunction(algf,data):
+  def costf(scale):
+    sdata=rescale(data,scale)
+    return crossvalidate(algf,sdata,trials=20)
+  return costf
+
+weightdomain=[(0,10)]*4
+
+def wineset3():
+  rows=wineset1()
+  for row in rows:
+    if random()<0.5:
+      # Wine was bought at a discount store
+      row['result']*=0.6
+  return rows
+
+def probguess(data,vec1,low,high,k=5,weightf=gaussian):
+  dlist=getdistances(data,vec1)
+  nweight=0.0
+  tweight=0.0
+  
+  for i in range(k):
+    dist=dlist[i][0]
+    idx=dlist[i][1]
+    weight=weightf(dist)
+    v=data[idx]['result']
+    
+    # Is this point in the range?
+    if v>=low and v<=high:
+      nweight+=weight
+    tweight+=weight
+  if tweight==0: return 0
+  
+  # The probability is the weights in the range
+  # divided by all the weights
+  return nweight/tweight
+
+from pylab import *
+
+def cumulativegraph(data,vec1,high,k=5,weightf=gaussian):
+  t1=arange(0.0,high,0.1)
+  cprob=array([probguess(data,vec1,0,v,k,weightf) for v in t1])
+  plot(t1,cprob)
+  show()
+
+
+def probabilitygraph(data,vec1,high,k=5,weightf=gaussian,ss=5.0):
+  # Make a range for the prices
+  t1=arange(0.0,high,0.1)
+  
+  # Get the probabilities for the entire range
+  probs=[probguess(data,vec1,v,v+0.1,k,weightf) for v in t1]
+  
+  # Smooth them by adding the gaussian of the nearby probabilites
+  smoothed=[]
+  for i in range(len(probs)):
+    sv=0.0
+    for j in range(0,len(probs)):
+      dist=abs(i-j)*0.1
+      weight=gaussian(dist,sigma=ss)
+      sv+=weight*probs[j]
+    smoothed.append(sv)
+  smoothed=array(smoothed)
+    
+  plot(t1,smoothed)
+  show()

File Chapter7/optimization.py

+import time
+import random
+import math
+
+people = [('Seymour','BOS'),
+          ('Franny','DAL'),
+          ('Zooey','CAK'),
+          ('Walt','MIA'),
+          ('Buddy','ORD'),
+          ('Les','OMA')]
+# Laguardia
+destination='LGA'
+
+flights={}
+# 
+"""
+for line in file('schedule.txt'):
+  origin,dest,depart,arrive,price=line.strip().split(',')
+  flights.setdefault((origin,dest),[])
+
+  # Add details to the list of possible flights
+  flights[(origin,dest)].append((depart,arrive,int(price)))
+"""
+def getminutes(t):
+  x=time.strptime(t,'%H:%M')
+  return x[3]*60+x[4]
+
+def printschedule(r):
+  for d in range(len(r)/2):
+    name=people[d][0]
+    origin=people[d][1]
+    out=flights[(origin,destination)][int(r[d])]
+    ret=flights[(destination,origin)][int(r[d+1])]
+    print '%10s%10s %5s-%5s $%3s %5s-%5s $%3s' % (name,origin,
+                                                  out[0],out[1],out[2],
+                                                  ret[0],ret[1],ret[2])
+
+def schedulecost(sol):
+  totalprice=0
+  latestarrival=0
+  earliestdep=24*60
+
+  for d in range(len(sol)/2):
+    # Get the inbound and outbound flights
+    origin=people[d][1]
+    outbound=flights[(origin,destination)][int(sol[d])]
+    returnf=flights[(destination,origin)][int(sol[d+1])]
+    
+    # Total price is the price of all outbound and return flights
+    totalprice+=outbound[2]
+    totalprice+=returnf[2]
+    
+    # Track the latest arrival and earliest departure
+    if latestarrival<getminutes(outbound[1]): latestarrival=getminutes(outbound[1])
+    if earliestdep>getminutes(returnf[0]): earliestdep=getminutes(returnf[0])
+  
+  # Every person must wait at the airport until the latest person arrives.
+  # They also must arrive at the same time and wait for their flights.
+  totalwait=0  
+  for d in range(len(sol)/2):
+    origin=people[d][1]
+    outbound=flights[(origin,destination)][int(sol[d])]
+    returnf=flights[(destination,origin)][int(sol[d+1])]
+    totalwait+=latestarrival-getminutes(outbound[1])
+    totalwait+=getminutes(returnf[0])-earliestdep  
+
+  # Does this solution require an extra day of car rental? That'll be $50!
+  if latestarrival>earliestdep: totalprice+=50
+  
+  return totalprice+totalwait
+
+def randomoptimize(domain,costf):
+  best=999999999
+  bestr=None
+  for i in range(0,1000):
+    # Create a random solution
+    r=[float(random.randint(domain[i][0],domain[i][1])) 
+       for i in range(len(domain))]
+    
+    # Get the cost
+    cost=costf(r)
+    
+    # Compare it to the best one so far
+    if cost<best:
+      best=cost
+      bestr=r 
+  return r
+
+
+def annealingoptimize(domain,costf,T=10000.0,cool=0.95,step=1):
+  # Initialize the values randomly
+  vec=[float(random.randint(domain[i][0],domain[i][1])) 
+       for i in range(len(domain))]
+  
+  while T>0.1:
+    # Choose one of the indices
+    i=random.randint(0,len(domain)-1)
+
+    # Choose a direction to change it
+    dir=random.randint(-step,step)
+
+    # Create a new list with one of the values changed
+    vecb=vec[:]
+    vecb[i]+=dir
+    if vecb[i]<domain[i][0]: vecb[i]=domain[i][0]
+    elif vecb[i]>domain[i][1]: vecb[i]=domain[i][1]
+
+    # Calculate the current cost and the new cost
+    ea=costf(vec)
+    eb=costf(vecb)
+    p=pow(math.e,(-eb-ea)/T)
+
+    print vec,ea
+
+
+    # Is it better, or does it make the probability
+    # cutoff?
+    if (eb<ea or random.random()<p):
+      vec=vecb      
+
+    # Decrease the temperature
+    T=T*cool
+  return vec
+
+def swarmoptimize(domain,costf,popsize=20,lrate=0.1,maxv=2.0,iters=50):
+  # Initialize individuals
+  # current solutions
+  x=[]
+
+  # best solutions
+  p=[]
+
+  # velocities
+  v=[]
+  
+  for i in range(0,popsize):
+    vec=[float(random.randint(domain[i][0],domain[i][1])) 
+         for i in range(len(domain))]
+    x.append(vec)
+    p.append(vec[:])
+    v.append([0.0 for i in vec])
+  
+  
+  for ml in range(0,iters):
+    for i in range(0,popsize):
+      # Best solution for this particle
+      if costf(x[i])<costf(p[i]):
+        p[i]=x[i][:]
+      g=i
+
+      # Best solution for any particle
+      for j in range(0,popsize):
+        if costf(p[j])<costf(p[g]): g=j
+      for d in range(len(x[i])):
+        # Update the velocity of this particle
+        v[i][d]+=lrate*(p[i][d]-x[i][d])+lrate*(p[g][d]-x[i][d])
+
+        # constrain velocity to a maximum
+        if v[i][d]>maxv: v[i][d]=maxv
+        elif v[i][d]<-maxv: v[i][d]=-maxv
+
+        # constrain bounds of solutions
+        x[i][d]+=v[i][d]
+        if x[i][d]<domain[d][0]: x[i][d]=domain[d][0]
+        elif x[i][d]>domain[d][1]: x[i][d]=domain[d][1]
+
+    print p[g],costf(p[g])
+  return p[g]

File Chapter7/svm.py

+import svmc
+from svmc import C_SVC, NU_SVC, ONE_CLASS, EPSILON_SVR, NU_SVR
+from svmc import LINEAR, POLY, RBF, SIGMOID
+from math import exp, fabs
+
+def _int_array(seq):
+	size = len(seq)
+	array = svmc.new_int(size)
+	i = 0
+	for item in seq:
+		svmc.int_setitem(array,i,item)
+		i = i + 1
+	return array
+
+def _double_array(seq):
+	size = len(seq)
+	array = svmc.new_double(size)
+	i = 0
+	for item in seq:
+		svmc.double_setitem(array,i,item)
+		i = i + 1
+	return array
+
+def _free_int_array(x):
+	if x != 'NULL' and x != None:
+		svmc.delete_int(x)
+
+def _free_double_array(x):
+	if x != 'NULL' and x != None:
+		svmc.delete_double(x)
+
+def _int_array_to_list(x,n):
+	return map(svmc.int_getitem,[x]*n,range(n))
+
+def _double_array_to_list(x,n):
+	return map(svmc.double_getitem,[x]*n,range(n))
+
+class svm_parameter:
+	
+	# default values
+	default_parameters = {
+	'svm_type' : C_SVC,
+	'kernel_type' : RBF,
+	'degree' : 3,
+	'gamma' : 0,		# 1/k
+	'coef0' : 0,
+	'nu' : 0.5,
+	'cache_size' : 40,
+	'C' : 1,
+	'eps' : 1e-3,
+	'p' : 0.1,
+	'shrinking' : 1,
+	'nr_weight' : 0,
+	'weight_label' : [],
+	'weight' : [],
+	'probability' : 0
+	}
+
+	def __init__(self,**kw):
+		self.__dict__['param'] = svmc.new_svm_parameter()
+		for attr,val in self.default_parameters.items():
+			setattr(self,attr,val)
+		for attr,val in kw.items():
+			setattr(self,attr,val)
+
+	def __getattr__(self,attr):
+		get_func = getattr(svmc,'svm_parameter_%s_get' % (attr))
+		return get_func(self.param)
+
+	def __setattr__(self,attr,val):
+
+		if attr == 'weight_label':
+			self.__dict__['weight_label_len'] = len(val)
+			val = _int_array(val)
+			_free_int_array(self.weight_label)
+		elif attr == 'weight':
+			self.__dict__['weight_len'] = len(val)
+			val = _double_array(val)
+			_free_double_array(self.weight)
+
+		set_func = getattr(svmc,'svm_parameter_%s_set' % (attr))
+		set_func(self.param,val)
+
+	def __repr__(self):
+		ret = '<svm_parameter:'
+		for name in dir(svmc):
+			if name[:len('svm_parameter_')] == 'svm_parameter_' and name[-len('_set'):] == '_set':
+				attr = name[len('svm_parameter_'):-len('_set')]
+				if attr == 'weight_label':
+					ret = ret+' weight_label = %s,' % _int_array_to_list(self.weight_label,self.weight_label_len)
+				elif attr ==