Professional Documents
Culture Documents
Temel Programlama II: Hafta IV
Temel Programlama II: Hafta IV
Hafta IV
• Please elaborate...
What do these companies have in
common?
• The ability to collect information
• Sophisticated algorithms: combine data collected from many
different sources.
• The computational power to interpret it
• enabling great collaboration opportunities and a better
understanding of users/customers (Data Mining).
• Everyone wants to understand their customers better in order
to create more targeted advertising.
Combine data
• Machine learning
• a subfield of artificial intelligence (AI)
• focuses on algorithms that allow computers to
“learn”.
• in most cases:
• an algorithm is given a set of data and infers
information about the properties of the data.
Combine data
• What do we do with that information?
• make predictions about other data that it might see
in the future.
• How?: Patterns!
• Almost all nonrandom data contains patterns
• Patterns allow the machine to generalize.
• How does it generalize?
• builds and trains a model
• determines the important aspects of the data.
Real-Life Examples
• Google not only uses web links to rank pages
• it constantly gathers information on when
advertisements are clicked by different users
• target the advertising more effectively.
• Sites like Amazon and Netflix use information about the
things people buy or rent to
• determine similar people or items
• make recommendations based on purchase history.
Real-Life Examples
•Amazon.com
• Amazon tracks the purchasing habits of all its shoppers
• when you log onto the site, it uses this information to
suggest products you might like.
• Amazon can even suggest movies you might like, even if
you’ve only bought books from it before.
Collaborative Filtering
?
İleriDüzey Python
Kavramları
• Python’ın bazı özellikleri, doğru çalışan programlar yazılması için
zorunlu olmamakla birlikte;
• Daha kısa (daha az kod satırı), daha okunaklı ve daha etkin
kodlar yazmanıza yardımcı olur.
• Bugün, bir programı Python’ca (Pythonic way) yazmak olarak da
adlandırılan şekilde yazmanıza yardımcı olacak bu kavramların
bazılarını göreceğiz.
Şartlı İfadeler
• Kullanıcıdan alınan bir sayının logaritmasını bulan bir kod parçası
yazdığımızı düşünelim:
import math
x = (float)(input(‘Lutfen bir sayi giriniz))
if x > 0 :
y = math.log(x)
else :
y = float (‘nan’)
import math
x = (float)(input(‘Lutfen bir sayi giriniz))
y = math.log(x) if x > 0 else float (‘nan’)
Şartlı İfade kullanarak faktöriyel
bulan fonksiyon
def factorial (n):
if n == 0:
return 1
else:
return n * factorial (n-1)
def factorial(n):
return 1 if n == 0 else n*factorial(n-1)
List Comprehension
• İçinde 1’den 10’a kadar olan sayıları ‘string’ olarak tutan bir liste
oluşturmak istediğimizi düşünelim:
res = []
for i in range(1, 11):
res.append(str(i))
print (res)
def sadece_buyuk_harf(s):
res = []
for c in s :
if c.isupper():
res.append(c)
return res
List Comprehension
• Oysa, aynı işi çok daha kısa ve öz kod kullanarak yapan fonksiyon:
def sadece_buyuk_harf2(s):
return [c for c in s if c.isupper()]
• List Comprehension ile yazdığımız ifade bir iteratör olup, istenen listeyi
iterasyon yoluyla oluşturur:
List Comprehension
[expression for variable in list]
or
[expression for variable in list if condition]
>> l1 = [1, 2, 3, 4, 5, 6]
>> l2 = [v*10 for v in l1]
>> print l2
???
>> l3 = [v*10 for v in l1 if v>3]
>> print l2
???
Euclidean Distance
def sim_distance(prefs,person1,person2):
# Get the list of shared_items
si={}
for item in prefs[person1]:
if item in prefs[person2]: si[item]=1
return 1/(1+sqrt(sum_of_squares))
Pearson Correlation Score
def topMatches(prefs,person,n=5,similarity=sim_pearson):
scores=[(similarity(prefs,person,other),other)
for other in prefs if other!=person]
scores.sort()
scores.reverse()
return scores[0:n]