In [1]:
%%HTML
<style>
div.cell {
    background-color: rgba(255,200,255,0.85);  
    font-family: Georgia, Cursive;
    font-size: 120%;
    border-radius: 10px;
}

.MathJax_Display {
    text-align: center;
}


body {
    background-color: #AAFFFF;
    background-image: url('https://raw.github.com/chenleo/Resource/master/Images/FirstKiss1600X1200.jpg');
    background-size: cover;
    background-repeat: no-repeat;
    background--attachment: fixed;
}
</style>


Collective Intelligence


In [1]:
import os
import sys

In [2]:
%qtconsole

In [3]:
sys.version
#ipython-2.7 notebook (in office)


Out[3]:
'2.7.6 (default, Nov 12 2013, 13:10:34) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'

In [4]:
pwd


Out[4]:
u'/Users/chenchen/Documents/git/ipynotebook'

In [6]:
os.chdir("../programming-collective-intelligence-code/")

In [7]:
pwd


Out[7]:
u'/Users/chenchen/Documents/git/programming-collective-intelligence-code'

In [8]:
%timeit 1+1


10000000 loops, best of 3: 36 ns per loop

Chapter 2: Making Recoomendations


In [9]:
os.chdir("chapter2/")

In [10]:
!ls


deliciousrec.py     pydelicious.py      recommendations.py  recommendations.pyc

In [11]:
from recommendations import critics
import recommendations

Finding Similar Users

  • Euclidean distance
  • Pearson Collelation

Euclidean Distance

$Dist(P,Q) = {1 \over {1+\sum{(Q_i - P_i)^2}}}$

  • Dist = 1: same
  • Dist = 0: different

In [16]:
people = critics.keys()
print people


['Jack Matthews', 'Mick LaSalle', 'Claudia Puig', 'Lisa Rose', 'Toby', 'Gene Seymour', 'Michael Phillips']

In [17]:
recommendations.sim_distance(critics, people[3], people[5])


Out[17]:
0.14814814814814814

Person Correlation Score


In [ ]: