ݺߣ

ݺߣShare a Scribd company logo
Chapter 8, Building Price models
Programming Collective Intelligence
terasaka.k
2011-11-10
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
1.
2.
3.
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
1.
2.
?
1.
2.
?
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
1.
2.
?
1.
2.
?
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
?
1. Rating
2. Age
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
?
1. Rating
2. Age
Peak age
? (older)
Peak age
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
?
1. Rating
2. Age
Peak age
? (older)
?
? def wineprice(rating, age): 
?
? def wineset1(): 
? random
? rating  [50-100]
? age  [0-50]
? price *= [80-120%]
Peak age = rating-50
Chapter 8, Building Price models
Programming Collective Intelligence
?
? 
?
?
1. Rating
2. Age
Peak age
? (older)
?
? def wineprice(rating, age): 
?
? def wineset1(): 
? random
? rating  [50-100]
? age  [0-50]
? price *= [80-120%]
Peak age = rating-50
>>> data[0]
{'input': (63.602840187200407, 21.574120872184949), 'result': 34.565257353086487}
>>> data[1]
{'input': (74.994980945756794, 48.052051269308649), 'result': 0.0}
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
? 
as
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? k-Nearest Neighbors
?
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
peak age
Chapter 8, Building Price models
Programming Collective Intelligence
peak age
Squiggle
Chapter 8, Building Price models
Programming Collective Intelligence
Squiggle

peak age
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
20
Chapter 8, Building Price models
Programming Collective Intelligence
20
peak age
Chapter 8, Building Price models
Programming Collective Intelligence
20
peak age
Chapter 8, Building Price models
Programming Collective Intelligence
20
peak age
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k-Nearest Neighbors
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Optimization
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Optimization
Optimization
Chapter 8, Building Price models
Programming Collective Intelligence
k
20
peak age
k
Optimization
Optimization
Optimization
Programming Collective Intelligence
k
k
Optimization
Optimization
Optimization
Chapter 8, Building Price models
20
peak age
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
def knnestimate(data,vec1,k=5): 
getdistances k
?????????(???1, ??)?? /k
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
def knnestimate(data,vec1,k=5): 
getdistances k
?????????(???1, ??)?? /k
k
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
def knnestimate(data,vec1,k=5): 
getdistances k
?????????(???1, ??)?? /k
k>>> numpredict.knnestimate(data,(95.0,3.0))
29.176138546872018
>>> numpredict.knnestimate(data,(99.0,3.0))
22.356856188108672
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
def knnestimate(data,vec1,k=5): 
getdistances k
?????????(???1, ??)?? /k
k>>> numpredict.knnestimate(data,(95.0,3.0))
29.176138546872018
>>> numpredict.knnestimate(data,(99.0,3.0))
22.356856188108672
Chapter 8, Building Price models
Programming Collective Intelligence
? def euclidean(v1,v2): 
n
>>> numpredict.euclidean(data[0]['input'],data[1]['input'])
28.56386131112269def getdistances(data,vec1):
distancelist=[]
for i in range(len(data)):
vec2=data[i]['input']
distancelist.append((euclidean(vec1,vec2),i))
distancelist.sort( )
return distancelist
def knnestimate(data,vec1,k=5): 
getdistances k
?????????(???1, ??)?? /k
k>>> numpredict.knnestimate(data,(95.0,3.0))
29.176138546872018
>>> numpredict.knnestimate(data,(99.0,3.0))
22.356856188108672
kNN weakness
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
def inverseweight(dist,num=1.0,const=0.1):
return num/(dist+const)
Chapter 8, Building Price models
Programming Collective Intelligence
?
def inverseweight(dist,num=1.0,const=0.1):
return num/(dist+const)
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
 >0
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? ? = ?
?
dist2
2?2
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
weight distance ???1, ? th nearest ??? ? value ?
total weigh?
?<?
Chapter 8, Building Price models
Programming Collective Intelligence
weight distance ???1, ? th nearest ??? ? value ?
total weigh?
?<?
>>> numpredict.weightedknn(data,(99.0,5.0))
32.640981119354301
Chapter 8, Building Price models
Programming Collective Intelligence
weight distance ???1, ? th nearest ??? ? value ?
total weigh?
?<?
>>> numpredict.weightedknn(data,(99.0,5.0))
32.640981119354301
rigorous
Chapter 8, Building Price models
Programming Collective Intelligence
weight distance ???1, ? th nearest ??? ? value ?
total weigh?
?<?
>>> numpredict.weightedknn(data,(99.0,5.0))
32.640981119354301
rigorous
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
95%
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def dividedata(data,test=0.05):

return trainset,testset
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def testalgorithm(algf,trainset,testset):

return
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def testalgorithm(algf,trainset,testset):

return
? 2
???????
???????
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def testalgorithm(algf,trainset,testset):

return
? 2
???????
???????
def crossvalidate(algf,data,trials=100,test=0.05):

return testalgorithm trials
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def testalgorithm(algf,trainset,testset):

return
? 2
???????
???????
def crossvalidate(algf,data,trials=100,test=0.05):

return testalgorithm trials
algf gaussian
Chapter 8, Building Price models
Programming Collective Intelligence
? technique
? Training set Test set
?
1.Training set
2.Test set
3.
def testalgorithm(algf,trainset,testset):

return
? 2
???????
???????
def crossvalidate(algf,data,trials=100,test=0.05):

return testalgorithm trials
algf gaussian
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
? 
rating, age, aisle, bottlesize
? aisle
? bottlesize (ml)
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
? 
rating, age, aisle, bottlesize
? aisle
? bottlesize (ml)
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? i i
Chapter 8, Building Price models
Programming Collective Intelligence
? i i
?
Chapter 8, Building Price models
Programming Collective Intelligence
? i i
?
def rescale(data,scale):
 i scale[i]
return scaleddata
Chapter 8, Building Price models
Programming Collective Intelligence
? i i
?
def rescale(data,scale):
 i scale[i]
return scaleddata
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
scale algf
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
>>>import optimization
>>>costf=numpredict.createcostfunction(numpredict.knnestimate,data)
>>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2)
[11,18,0,6]
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
>>>import optimization
>>>costf=numpredict.createcostfunction(numpredict.knnestimate,data)
>>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2)
[11,18,0,6]
rating, age, aisle, bottlesize
aisle
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
>>>import optimization
>>>costf=numpredict.createcostfunction(numpredict.knnestimate,data)
>>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2)
[11,18,0,6]
bottlesize
Chapter 8, Building Price models
Programming Collective Intelligence
? Chapter 5 Optimization
?
?
?
def createcostfunction(algf,data):
def costf(scale):
sdata=rescale(data,scale)
return crossvalidate(algf,sdata,trials=10)
return costf
weightdomain=[(0,20)]*4
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
1/2 60%
def wineset3():
Chapter 8, Building Price models
Programming Collective Intelligence
?
1/2 60%
def wineset3():
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
Chapter 8, Building Price models
Programming Collective Intelligence
?
?
? 60% -
? 35% -
?
Chapter 8, Building Price models
Programming Collective Intelligence
def probguess(data,vec1,low,high,k=5,weightf=gaussian):

return vec1 low-high
Chapter 8, Building Price models
Programming Collective Intelligence
def probguess(data,vec1,low,high,k=5,weightf=gaussian):

return vec1 low-high
k low-high
nweight += weight
return nweight(=low-high weight / k weight
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 - 5
? 0-10
? 0-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 - 5
? 0-10
? 0-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 - 5
? 0-10
? 0-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 - 5
? 0-10
? 0-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 C 5
? 5 - 10
? 10-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 C 5
? 5 - 10
? 10-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 C 5
? 5 - 10
? 10-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 C 5
? 5 - 10
? 10-15
?
Chapter 8, Building Price models
Programming Collective Intelligence
? 0 C 5
? 5 - 10
? 10-15
? 
0
Gaussian
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD X-Y 60%
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD X-Y 60%
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD X-Y 60%
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD X-Y 60%
DD
Chapter 8, Building Price models
Programming Collective Intelligence
DD
DD
DD k
DD DDGaussian
? DDCross-Validation
? Training set test set &
DDkNN
? DD
DD
DD
? DD X-Y 60%
DD
Chapter 8, Building Price models
Programming Collective Intelligence
Chapter 8, Building Price models
Programming Collective Intelligence
terasaka.k
Chapter 8, Building Price models
Programming Collective Intelligence
? DD
? DD
? kNNDD k
? DD DDGaussian
? DDCross-Validation
? Training set test set &
? DDkNN
? DD
? DD
? DD
? DD X-Y 60%
? DD
Chapter 8, Building Price models
Programming Collective Intelligence
terasaka.k
2011-11-09T17:39:24

More Related Content

Viewers also liked (16)

Tema 4.1 las regencias y el problema carlista-cristina y elisaTema 4.1 las regencias y el problema carlista-cristina y elisa
Tema 4.1 las regencias y el problema carlista-cristina y elisa
jjsg23
?
Tema 6.2 oposicin al sistema de la restauracin-marta e ireneTema 6.2 oposicin al sistema de la restauracin-marta e irene
Tema 6.2 oposicin al sistema de la restauracin-marta e irene
jjsg23
?
Tema 5.1 el sexenio democrtico-natalia y mnicaTema 5.1 el sexenio democrtico-natalia y mnica
Tema 5.1 el sexenio democrtico-natalia y mnica
jjsg23
?
Tema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngelTema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngel
Tema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngel
jjsg23
?
Tema 5.2 economa y sociedad en el s. xix-desire y mari carmenTema 5.2 economa y sociedad en el s. xix-desire y mari carmen
Tema 5.2 economa y sociedad en el s. xix-desire y mari carmen
jjsg23
?
Deepak uikey
Deepak uikeyDeepak uikey
Deepak uikey
likeysahu
?
Curriculum vitae
Curriculum vitaeCurriculum vitae
Curriculum vitae
Addi Jr
?
ROSA M BARRIOS
ROSA M BARRIOSROSA M BARRIOS
ROSA M BARRIOS
Rosa Barrios
?
MSA Wittenberg August 2016 reworked
MSA Wittenberg August 2016 reworkedMSA Wittenberg August 2016 reworked
MSA Wittenberg August 2016 reworked
Master of Science in Analytics, Wittenberg U.
?
Antje Richter - Fire Marshal Training Certificate
Antje Richter - Fire Marshal Training CertificateAntje Richter - Fire Marshal Training Certificate
Antje Richter - Fire Marshal Training Certificate
Antje Richter
?
IBM_Cloud_10_23_01_AM
IBM_Cloud_10_23_01_AMIBM_Cloud_10_23_01_AM
IBM_Cloud_10_23_01_AM
Apurba Chakraborty
?
Bolos GeladosBolos Gelados
Bolos Gelados
Culinaria Fabula
?
Museo De SissMuseo De Siss
Museo De Siss
susita
?
Web analytics para empresasWeb analytics para empresas
Web analytics para empresas
Matias Dell'Anno Irigoyen
?
Tema 11.1 el 2? franquismo. evolucion politica.robi y yeniferTema 11.1 el 2? franquismo. evolucion politica.robi y yenifer
Tema 11.1 el 2? franquismo. evolucion politica.robi y yenifer
jjsg23
?
Tema 4.1 las regencias y el problema carlista-cristina y elisaTema 4.1 las regencias y el problema carlista-cristina y elisa
Tema 4.1 las regencias y el problema carlista-cristina y elisa
jjsg23
?
Tema 6.2 oposicin al sistema de la restauracin-marta e ireneTema 6.2 oposicin al sistema de la restauracin-marta e irene
Tema 6.2 oposicin al sistema de la restauracin-marta e irene
jjsg23
?
Tema 5.1 el sexenio democrtico-natalia y mnicaTema 5.1 el sexenio democrtico-natalia y mnica
Tema 5.1 el sexenio democrtico-natalia y mnica
jjsg23
?
Tema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngelTema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngel
Tema 11.3 oposicin poltica al rgimen de franco (1959-1975)-sergio y ngel
jjsg23
?
Tema 5.2 economa y sociedad en el s. xix-desire y mari carmenTema 5.2 economa y sociedad en el s. xix-desire y mari carmen
Tema 5.2 economa y sociedad en el s. xix-desire y mari carmen
jjsg23
?
Curriculum vitae
Curriculum vitaeCurriculum vitae
Curriculum vitae
Addi Jr
?
Antje Richter - Fire Marshal Training Certificate
Antje Richter - Fire Marshal Training CertificateAntje Richter - Fire Marshal Training Certificate
Antje Richter - Fire Marshal Training Certificate
Antje Richter
?
Bolos GeladosBolos Gelados
Bolos Gelados
Culinaria Fabula
?
Museo De SissMuseo De Siss
Museo De Siss
susita
?
Web analytics para empresasWeb analytics para empresas
Web analytics para empresas
Matias Dell'Anno Irigoyen
?
Tema 11.1 el 2? franquismo. evolucion politica.robi y yeniferTema 11.1 el 2? franquismo. evolucion politica.robi y yenifer
Tema 11.1 el 2? franquismo. evolucion politica.robi y yenifer
jjsg23
?

Similar to 8ء֪ץߥ󥰡Ŀ㏊ @Էǰ (20)

Learning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method NamesLearning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method Names
Dongsun Kim
?
Boost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringBoost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineering
Miro Wengner
?
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
Ivn Fernndez Perea
?
Rc bldg. modeling & analysis
Rc bldg. modeling & analysisRc bldg. modeling & analysis
Rc bldg. modeling & analysis
Ramil Artates
?
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Databricks
?
A04230105
A04230105A04230105
A04230105
ijceronline
?
The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.3 book - Part 8 of 88The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.3 book - Part 8 of 88
Mahmoud Samir Fayed
?
PF_IDETC_2012_Souma
PF_IDETC_2012_SoumaPF_IDETC_2012_Souma
PF_IDETC_2012_Souma
MDO_Lab
?
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015
Christian Peel
?
David Bilk: Anko C modern way to build your layouts?
David Bilk: Anko C modern way to build your layouts?David Bilk: Anko C modern way to build your layouts?
David Bilk: Anko C modern way to build your layouts?
mdevtalk
?
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AIQualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Research
?
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI ProjectsDiscovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Wee Hyong Tok
?
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
Microsoft
?
Key projects in AI, ML and Generative AI
Key projects in AI, ML and Generative AIKey projects in AI, ML and Generative AI
Key projects in AI, ML and Generative AI
Vijayananda Mohire
?
pyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdfpyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdf
Asher Sterkin
?
Metaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdfMetaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdf
ׅ Tommy Wu
?
Engineering + Programming portfolio
Engineering + Programming portfolioEngineering + Programming portfolio
Engineering + Programming portfolio
JosephDonnelly14
?
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
Kevin Keraudren
?
Duel of Two Libraries: Cairo & Skia
Duel of Two Libraries: Cairo & SkiaDuel of Two Libraries: Cairo & Skia
Duel of Two Libraries: Cairo & Skia
Samsung Open Source Group
?
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
Edge AI and Vision Alliance
?
Learning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method NamesLearning to Spot and Refactor Inconsistent Method Names
Learning to Spot and Refactor Inconsistent Method Names
Dongsun Kim
?
Boost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineeringBoost delivery stream with code discipline engineering
Boost delivery stream with code discipline engineering
Miro Wengner
?
Rc bldg. modeling & analysis
Rc bldg. modeling & analysisRc bldg. modeling & analysis
Rc bldg. modeling & analysis
Ramil Artates
?
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML ToolkitAugmenting Machine Learning with Databricks Labs AutoML Toolkit
Augmenting Machine Learning with Databricks Labs AutoML Toolkit
Databricks
?
The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.3 book - Part 8 of 88The Ring programming language version 1.3 book - Part 8 of 88
The Ring programming language version 1.3 book - Part 8 of 88
Mahmoud Samir Fayed
?
PF_IDETC_2012_Souma
PF_IDETC_2012_SoumaPF_IDETC_2012_Souma
PF_IDETC_2012_Souma
MDO_Lab
?
Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015Ehsan parallel accelerator-dec2015
Ehsan parallel accelerator-dec2015
Christian Peel
?
David Bilk: Anko C modern way to build your layouts?
David Bilk: Anko C modern way to build your layouts?David Bilk: Anko C modern way to build your layouts?
David Bilk: Anko C modern way to build your layouts?
mdevtalk
?
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AIQualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Webinar: Solving Unsolvable Combinatorial Problems with AI
Qualcomm Research
?
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI ProjectsDiscovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Discovering Your AI Super Powers - Tips and Tricks to Jumpstart your AI Projects
Wee Hyong Tok
?
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
Microsoft
?
Key projects in AI, ML and Generative AI
Key projects in AI, ML and Generative AIKey projects in AI, ML and Generative AI
Key projects in AI, ML and Generative AI
Vijayananda Mohire
?
pyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdfpyjamas22_ generic composite in python.pdf
pyjamas22_ generic composite in python.pdf
Asher Sterkin
?
Metaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdfMetaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdf
ׅ Tommy Wu
?
Engineering + Programming portfolio
Engineering + Programming portfolioEngineering + Programming portfolio
Engineering + Programming portfolio
JosephDonnelly14
?
Introduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimizationIntroduction to cython: example of GCoptimization
Introduction to cython: example of GCoptimization
Kevin Keraudren
?
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
State-of-the-art Model Quantization and Optimization for Efficient Edge AI,...
Edge AI and Vision Alliance
?

8ء֪ץߥ󥰡Ŀ㏊ @Էǰ

  • 1. Chapter 8, Building Price models Programming Collective Intelligence terasaka.k 2011-11-10
  • 2. Chapter 8, Building Price models Programming Collective Intelligence ? ? 1. 2. 3.
  • 3. Chapter 8, Building Price models Programming Collective Intelligence ? ? 1. 2. ? 1. 2. ? ? ?
  • 4. Chapter 8, Building Price models Programming Collective Intelligence ? ? 1. 2. ? 1. 2. ? ? ?
  • 5. Chapter 8, Building Price models Programming Collective Intelligence ? ? ?
  • 6. Chapter 8, Building Price models Programming Collective Intelligence ? ? ?
  • 7. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? ? 1. Rating 2. Age
  • 8. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? ? 1. Rating 2. Age Peak age ? (older) Peak age
  • 9. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? ? 1. Rating 2. Age Peak age ? (older) ? ? def wineprice(rating, age): ? ? def wineset1(): ? random ? rating [50-100] ? age [0-50] ? price *= [80-120%] Peak age = rating-50
  • 10. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? ? 1. Rating 2. Age Peak age ? (older) ? ? def wineprice(rating, age): ? ? def wineset1(): ? random ? rating [50-100] ? age [0-50] ? price *= [80-120%] Peak age = rating-50 >>> data[0] {'input': (63.602840187200407, 21.574120872184949), 'result': 34.565257353086487} >>> data[1] {'input': (74.994980945756794, 48.052051269308649), 'result': 0.0}
  • 11. Chapter 8, Building Price models Programming Collective Intelligence
  • 12. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 13. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? as
  • 14. Chapter 8, Building Price models Programming Collective Intelligence
  • 15. Chapter 8, Building Price models Programming Collective Intelligence ? k-Nearest Neighbors ?
  • 16. Chapter 8, Building Price models Programming Collective Intelligence
  • 17. Chapter 8, Building Price models Programming Collective Intelligence
  • 18. Chapter 8, Building Price models Programming Collective Intelligence
  • 19. Chapter 8, Building Price models Programming Collective Intelligence
  • 20. Chapter 8, Building Price models Programming Collective Intelligence
  • 21. Chapter 8, Building Price models Programming Collective Intelligence peak age
  • 22. Chapter 8, Building Price models Programming Collective Intelligence peak age Squiggle
  • 23. Chapter 8, Building Price models Programming Collective Intelligence Squiggle peak age
  • 24. Chapter 8, Building Price models Programming Collective Intelligence
  • 25. Chapter 8, Building Price models Programming Collective Intelligence
  • 26. Chapter 8, Building Price models Programming Collective Intelligence 20
  • 27. Chapter 8, Building Price models Programming Collective Intelligence 20 peak age
  • 28. Chapter 8, Building Price models Programming Collective Intelligence 20 peak age
  • 29. Chapter 8, Building Price models Programming Collective Intelligence 20 peak age
  • 30. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k-Nearest Neighbors
  • 31. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k
  • 32. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k
  • 33. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k
  • 34. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k Optimization
  • 35. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k Optimization Optimization
  • 36. Chapter 8, Building Price models Programming Collective Intelligence k 20 peak age k Optimization Optimization Optimization
  • 38. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n
  • 39. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269
  • 40. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist
  • 41. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist def knnestimate(data,vec1,k=5): getdistances k ?????????(???1, ??)?? /k
  • 42. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist def knnestimate(data,vec1,k=5): getdistances k ?????????(???1, ??)?? /k k
  • 43. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist def knnestimate(data,vec1,k=5): getdistances k ?????????(???1, ??)?? /k k>>> numpredict.knnestimate(data,(95.0,3.0)) 29.176138546872018 >>> numpredict.knnestimate(data,(99.0,3.0)) 22.356856188108672
  • 44. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist def knnestimate(data,vec1,k=5): getdistances k ?????????(???1, ??)?? /k k>>> numpredict.knnestimate(data,(95.0,3.0)) 29.176138546872018 >>> numpredict.knnestimate(data,(99.0,3.0)) 22.356856188108672
  • 45. Chapter 8, Building Price models Programming Collective Intelligence ? def euclidean(v1,v2): n >>> numpredict.euclidean(data[0]['input'],data[1]['input']) 28.56386131112269def getdistances(data,vec1): distancelist=[] for i in range(len(data)): vec2=data[i]['input'] distancelist.append((euclidean(vec1,vec2),i)) distancelist.sort( ) return distancelist def knnestimate(data,vec1,k=5): getdistances k ?????????(???1, ??)?? /k k>>> numpredict.knnestimate(data,(95.0,3.0)) 29.176138546872018 >>> numpredict.knnestimate(data,(99.0,3.0)) 22.356856188108672 kNN weakness
  • 46. Chapter 8, Building Price models Programming Collective Intelligence
  • 47. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 48. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 49. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 50. Chapter 8, Building Price models Programming Collective Intelligence ? def inverseweight(dist,num=1.0,const=0.1): return num/(dist+const)
  • 51. Chapter 8, Building Price models Programming Collective Intelligence ? def inverseweight(dist,num=1.0,const=0.1): return num/(dist+const)
  • 52. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 53. Chapter 8, Building Price models Programming Collective Intelligence ? >0
  • 54. Chapter 8, Building Price models Programming Collective Intelligence
  • 55. Chapter 8, Building Price models Programming Collective Intelligence
  • 56. Chapter 8, Building Price models Programming Collective Intelligence ? ? = ? ? dist2 2?2
  • 57. Chapter 8, Building Price models Programming Collective Intelligence
  • 58. Chapter 8, Building Price models Programming Collective Intelligence weight distance ???1, ? th nearest ??? ? value ? total weigh? ?<?
  • 59. Chapter 8, Building Price models Programming Collective Intelligence weight distance ???1, ? th nearest ??? ? value ? total weigh? ?<? >>> numpredict.weightedknn(data,(99.0,5.0)) 32.640981119354301
  • 60. Chapter 8, Building Price models Programming Collective Intelligence weight distance ???1, ? th nearest ??? ? value ? total weigh? ?<? >>> numpredict.weightedknn(data,(99.0,5.0)) 32.640981119354301 rigorous
  • 61. Chapter 8, Building Price models Programming Collective Intelligence weight distance ???1, ? th nearest ??? ? value ? total weigh? ?<? >>> numpredict.weightedknn(data,(99.0,5.0)) 32.640981119354301 rigorous
  • 62. Chapter 8, Building Price models Programming Collective Intelligence
  • 63. Chapter 8, Building Price models Programming Collective Intelligence
  • 64. Chapter 8, Building Price models Programming Collective Intelligence ? technique
  • 65. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set
  • 66. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set 95%
  • 67. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ?
  • 68. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set
  • 69. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set
  • 70. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 71. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 72. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 73. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 74. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 75. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 76. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3.
  • 77. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def dividedata(data,test=0.05): return trainset,testset
  • 78. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def testalgorithm(algf,trainset,testset): return
  • 79. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def testalgorithm(algf,trainset,testset): return ? 2 ??????? ???????
  • 80. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def testalgorithm(algf,trainset,testset): return ? 2 ??????? ??????? def crossvalidate(algf,data,trials=100,test=0.05): return testalgorithm trials
  • 81. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def testalgorithm(algf,trainset,testset): return ? 2 ??????? ??????? def crossvalidate(algf,data,trials=100,test=0.05): return testalgorithm trials algf gaussian
  • 82. Chapter 8, Building Price models Programming Collective Intelligence ? technique ? Training set Test set ? 1.Training set 2.Test set 3. def testalgorithm(algf,trainset,testset): return ? 2 ??????? ??????? def crossvalidate(algf,data,trials=100,test=0.05): return testalgorithm trials algf gaussian
  • 83. Chapter 8, Building Price models Programming Collective Intelligence
  • 84. Chapter 8, Building Price models Programming Collective Intelligence
  • 85. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 86. Chapter 8, Building Price models Programming Collective Intelligence ? ? ?
  • 87. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? rating, age, aisle, bottlesize ? aisle ? bottlesize (ml)
  • 88. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? rating, age, aisle, bottlesize ? aisle ? bottlesize (ml)
  • 89. Chapter 8, Building Price models Programming Collective Intelligence
  • 90. Chapter 8, Building Price models Programming Collective Intelligence ? i i
  • 91. Chapter 8, Building Price models Programming Collective Intelligence ? i i ?
  • 92. Chapter 8, Building Price models Programming Collective Intelligence ? i i ? def rescale(data,scale): i scale[i] return scaleddata
  • 93. Chapter 8, Building Price models Programming Collective Intelligence ? i i ? def rescale(data,scale): i scale[i] return scaleddata
  • 94. Chapter 8, Building Price models Programming Collective Intelligence
  • 95. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 96. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 97. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 98. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 99. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 100. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization
  • 101. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ?
  • 102. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ?
  • 103. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ?
  • 104. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf
  • 105. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf scale algf
  • 106. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf
  • 107. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4
  • 108. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4
  • 109. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4
  • 110. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4 >>>import optimization >>>costf=numpredict.createcostfunction(numpredict.knnestimate,data) >>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2) [11,18,0,6]
  • 111. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4 >>>import optimization >>>costf=numpredict.createcostfunction(numpredict.knnestimate,data) >>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2) [11,18,0,6] rating, age, aisle, bottlesize aisle
  • 112. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4 >>>import optimization >>>costf=numpredict.createcostfunction(numpredict.knnestimate,data) >>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2) [11,18,0,6] bottlesize
  • 113. Chapter 8, Building Price models Programming Collective Intelligence ? Chapter 5 Optimization ? ? ? def createcostfunction(algf,data): def costf(scale): sdata=rescale(data,scale) return crossvalidate(algf,sdata,trials=10) return costf weightdomain=[(0,20)]*4
  • 114. Chapter 8, Building Price models Programming Collective Intelligence
  • 115. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 116. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 117. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 118. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 119. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 120. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 121. Chapter 8, Building Price models Programming Collective Intelligence ?
  • 122. Chapter 8, Building Price models Programming Collective Intelligence ? 1/2 60% def wineset3():
  • 123. Chapter 8, Building Price models Programming Collective Intelligence ? 1/2 60% def wineset3():
  • 124. Chapter 8, Building Price models Programming Collective Intelligence ? ?
  • 125. Chapter 8, Building Price models Programming Collective Intelligence ? ? ? 60% - ? 35% - ?
  • 126. Chapter 8, Building Price models Programming Collective Intelligence def probguess(data,vec1,low,high,k=5,weightf=gaussian): return vec1 low-high
  • 127. Chapter 8, Building Price models Programming Collective Intelligence def probguess(data,vec1,low,high,k=5,weightf=gaussian): return vec1 low-high k low-high nweight += weight return nweight(=low-high weight / k weight
  • 128. Chapter 8, Building Price models Programming Collective Intelligence
  • 129. Chapter 8, Building Price models Programming Collective Intelligence
  • 130. Chapter 8, Building Price models Programming Collective Intelligence
  • 131. Chapter 8, Building Price models Programming Collective Intelligence
  • 132. Chapter 8, Building Price models Programming Collective Intelligence
  • 133. Chapter 8, Building Price models Programming Collective Intelligence
  • 134. Chapter 8, Building Price models Programming Collective Intelligence ? 0 - 5 ? 0-10 ? 0-15 ?
  • 135. Chapter 8, Building Price models Programming Collective Intelligence ? 0 - 5 ? 0-10 ? 0-15 ?
  • 136. Chapter 8, Building Price models Programming Collective Intelligence ? 0 - 5 ? 0-10 ? 0-15 ?
  • 137. Chapter 8, Building Price models Programming Collective Intelligence ? 0 - 5 ? 0-10 ? 0-15 ?
  • 138. Chapter 8, Building Price models Programming Collective Intelligence
  • 139. Chapter 8, Building Price models Programming Collective Intelligence ? 0 C 5 ? 5 - 10 ? 10-15 ?
  • 140. Chapter 8, Building Price models Programming Collective Intelligence ? 0 C 5 ? 5 - 10 ? 10-15 ?
  • 141. Chapter 8, Building Price models Programming Collective Intelligence ? 0 C 5 ? 5 - 10 ? 10-15 ?
  • 142. Chapter 8, Building Price models Programming Collective Intelligence ? 0 C 5 ? 5 - 10 ? 10-15 ?
  • 143. Chapter 8, Building Price models Programming Collective Intelligence ? 0 C 5 ? 5 - 10 ? 10-15 ? 0 Gaussian
  • 144. Chapter 8, Building Price models Programming Collective Intelligence
  • 145. Chapter 8, Building Price models Programming Collective Intelligence
  • 146. Chapter 8, Building Price models Programming Collective Intelligence
  • 147. Chapter 8, Building Price models Programming Collective Intelligence
  • 148. Chapter 8, Building Price models Programming Collective Intelligence
  • 149. Chapter 8, Building Price models Programming Collective Intelligence DD
  • 150. Chapter 8, Building Price models Programming Collective Intelligence DD
  • 151. Chapter 8, Building Price models Programming Collective Intelligence DD DD
  • 152. Chapter 8, Building Price models Programming Collective Intelligence DD DD
  • 153. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD
  • 154. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k
  • 155. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD
  • 156. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian
  • 157. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DD
  • 158. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation
  • 159. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set
  • 160. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set &
  • 161. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DD
  • 162. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN
  • 163. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD
  • 164. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD
  • 165. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD
  • 166. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD
  • 167. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD
  • 168. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD
  • 169. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD
  • 170. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD X-Y 60%
  • 171. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD X-Y 60% DD
  • 172. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD X-Y 60% DD
  • 173. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD X-Y 60% DD
  • 174. Chapter 8, Building Price models Programming Collective Intelligence DD DD DD k DD DDGaussian ? DDCross-Validation ? Training set test set & DDkNN ? DD DD DD ? DD X-Y 60% DD
  • 175. Chapter 8, Building Price models Programming Collective Intelligence
  • 176. Chapter 8, Building Price models Programming Collective Intelligence
  • 177. terasaka.k Chapter 8, Building Price models Programming Collective Intelligence ? DD ? DD ? kNNDD k ? DD DDGaussian ? DDCross-Validation ? Training set test set & ? DDkNN ? DD ? DD ? DD ? DD X-Y 60% ? DD
  • 178. Chapter 8, Building Price models Programming Collective Intelligence terasaka.k 2011-11-09T17:39:24