Chapter 8, Building Price modelsProgramming Collective Intelligenceterasaka.k2011-11-10
Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.3.
Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.•1.2.•••
Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.•1.2.•••
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →•
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →•
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. Age
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak age• (older)Peak age
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak age• (older)•• def wineprice(...
Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak age• (older)•• def wineprice(...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••• →as
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence• k-Nearest Neighbors• …
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligencepeak age
Chapter 8, Building Price modelsProgramming Collective Intelligencepeak ageSquiggle
Chapter 8, Building Price modelsProgramming Collective IntelligenceSquiggle…peak age
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence20
Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek-Nearest Neighbors
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimization
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimizationOptimization
Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimizationOptimizationOptimization
Programming Collective IntelligencekkOptimizationOptimizationOptimizationChapter 8, Building Price models20peak age
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•def inverseweight(dist,num=1.0,const=0.1):return num/(...
Chapter 8, Building Price modelsProgramming Collective Intelligence•def inverseweight(dist,num=1.0,const=0.1):return num/(...
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•→ >0
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence𝑓 𝑥 = 𝑒−dist22𝜎2
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total w...
Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total w...
Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total w...
Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total w...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set95%
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••• →
Chapter 8, Building Price modelsProgramming Collective Intelligence••• →rating, age, aisle, bottlesize• aisle• bottlesize ...
Chapter 8, Building Price modelsProgramming Collective Intelligence••• →rating, age, aisle, bottlesize• aisle• bottlesize ...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence• i i
Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•
Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•def rescale(data,scale):… i scale[i]return scaled...
Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•def rescale(data,scale):… i scale[i]return scaled...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization••
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•
Chapter 8, Building Price modelsProgramming Collective Intelligence•1/2 60%def wineset3():…
Chapter 8, Building Price modelsProgramming Collective Intelligence•1/2 60%def wineset3():…
Chapter 8, Building Price modelsProgramming Collective Intelligence••
Chapter 8, Building Price modelsProgramming Collective Intelligence••• 60% -• 35% -• …
Chapter 8, Building Price modelsProgramming Collective Intelligencedef probguess(data,vec1,low,high,k=5,weightf=gaussian):...
Chapter 8, Building Price modelsProgramming Collective Intelligencedef probguess(data,vec1,low,high,k=5,weightf=gaussian):...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …0Gaussian
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence――
Chapter 8, Building Price modelsProgramming Collective Intelligence――
Chapter 8, Building Price modelsProgramming Collective Intelligence――――
Chapter 8, Building Price modelsProgramming Collective Intelligence――――
Chapter 8, Building Price modelsProgramming Collective Intelligence――――――
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k――
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set...
Chapter 8, Building Price modelsProgramming Collective Intelligence
Chapter 8, Building Price modelsProgramming Collective Intelligence
terasaka.kChapter 8, Building Price modelsProgramming Collective Intelligence• ――• ――• kNN―― k• ―― ――Gaussian• ――Cross-Val...
Chapter 8, Building Price modelsProgramming Collective Intelligenceterasaka.k2011-11-09T17:39:24
Upcoming SlideShare
Loading in …5
×

第8回「集合知プログラミング」真面目に勉強する会 @外苑前

464 views

Published on

第8回「集合知プログラミング」真面目に勉強する会 @外苑前

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
464
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

第8回「集合知プログラミング」真面目に勉強する会 @外苑前

  1. 1. Chapter 8, Building Price modelsProgramming Collective Intelligenceterasaka.k2011-11-10
  2. 2. Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.3.
  3. 3. Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.•1.2.•••
  4. 4. Chapter 8, Building Price modelsProgramming Collective Intelligence••1.2.•1.2.•••
  5. 5. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →•
  6. 6. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →•
  7. 7. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. Age
  8. 8. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak age• (older)Peak age
  9. 9. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak age• (older)•• def wineprice(rating, age): …•• def wineset1(): …• random• rating ∈ [50-100]• age ∈ [0-50]• price *= [80-120%]Peak age = rating-50
  10. 10. Chapter 8, Building Price modelsProgramming Collective Intelligence•• →••1. Rating2. AgePeak 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. 11. Chapter 8, Building Price modelsProgramming Collective Intelligence
  12. 12. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  13. 13. Chapter 8, Building Price modelsProgramming Collective Intelligence••• →as
  14. 14. Chapter 8, Building Price modelsProgramming Collective Intelligence
  15. 15. Chapter 8, Building Price modelsProgramming Collective Intelligence• k-Nearest Neighbors• …
  16. 16. Chapter 8, Building Price modelsProgramming Collective Intelligence
  17. 17. Chapter 8, Building Price modelsProgramming Collective Intelligence
  18. 18. Chapter 8, Building Price modelsProgramming Collective Intelligence
  19. 19. Chapter 8, Building Price modelsProgramming Collective Intelligence
  20. 20. Chapter 8, Building Price modelsProgramming Collective Intelligence
  21. 21. Chapter 8, Building Price modelsProgramming Collective Intelligencepeak age
  22. 22. Chapter 8, Building Price modelsProgramming Collective Intelligencepeak ageSquiggle
  23. 23. Chapter 8, Building Price modelsProgramming Collective IntelligenceSquiggle…peak age
  24. 24. Chapter 8, Building Price modelsProgramming Collective Intelligence
  25. 25. Chapter 8, Building Price modelsProgramming Collective Intelligence
  26. 26. Chapter 8, Building Price modelsProgramming Collective Intelligence20
  27. 27. Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
  28. 28. Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
  29. 29. Chapter 8, Building Price modelsProgramming Collective Intelligence20peak age
  30. 30. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek-Nearest Neighbors
  31. 31. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
  32. 32. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
  33. 33. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agek
  34. 34. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimization
  35. 35. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimizationOptimization
  36. 36. Chapter 8, Building Price modelsProgramming Collective Intelligencek20peak agekOptimizationOptimizationOptimization
  37. 37. Programming Collective IntelligencekkOptimizationOptimizationOptimizationChapter 8, Building Price models20peak age
  38. 38. Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n
  39. 39. Chapter 8, Building Price modelsProgramming Collective Intelligence• def euclidean(v1,v2): …n>>> numpredict.euclidean(data[0][input],data[1][input])28.56386131112269
  40. 40. Chapter 8, Building Price modelsProgramming 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. 41. Chapter 8, Building Price modelsProgramming 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 distancelistdef knnestimate(data,vec1,k=5): …getdistances k𝑒𝑢𝑐𝑙𝑖𝑑𝑖𝑎𝑛(𝑣𝑒𝑐1, 𝑣𝑖)𝑖≤𝑘 /k
  42. 42. Chapter 8, Building Price modelsProgramming 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 distancelistdef knnestimate(data,vec1,k=5): …getdistances k𝑒𝑢𝑐𝑙𝑖𝑑𝑖𝑎𝑛(𝑣𝑒𝑐1, 𝑣𝑖)𝑖≤𝑘 /kk
  43. 43. Chapter 8, Building Price modelsProgramming 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 distancelistdef knnestimate(data,vec1,k=5): …getdistances k𝑒𝑢𝑐𝑙𝑖𝑑𝑖𝑎𝑛(𝑣𝑒𝑐1, 𝑣𝑖)𝑖≤𝑘 /kk>>> numpredict.knnestimate(data,(95.0,3.0))29.176138546872018>>> numpredict.knnestimate(data,(99.0,3.0))22.356856188108672
  44. 44. Chapter 8, Building Price modelsProgramming 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 distancelistdef knnestimate(data,vec1,k=5): …getdistances k𝑒𝑢𝑐𝑙𝑖𝑑𝑖𝑎𝑛(𝑣𝑒𝑐1, 𝑣𝑖)𝑖≤𝑘 /kk>>> numpredict.knnestimate(data,(95.0,3.0))29.176138546872018>>> numpredict.knnestimate(data,(99.0,3.0))22.356856188108672
  45. 45. Chapter 8, Building Price modelsProgramming 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 distancelistdef knnestimate(data,vec1,k=5): …getdistances k𝑒𝑢𝑐𝑙𝑖𝑑𝑖𝑎𝑛(𝑣𝑒𝑐1, 𝑣𝑖)𝑖≤𝑘 /kk>>> numpredict.knnestimate(data,(95.0,3.0))29.176138546872018>>> numpredict.knnestimate(data,(99.0,3.0))22.356856188108672kNN weakness
  46. 46. Chapter 8, Building Price modelsProgramming Collective Intelligence
  47. 47. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  48. 48. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  49. 49. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  50. 50. Chapter 8, Building Price modelsProgramming Collective Intelligence•def inverseweight(dist,num=1.0,const=0.1):return num/(dist+const)
  51. 51. Chapter 8, Building Price modelsProgramming Collective Intelligence•def inverseweight(dist,num=1.0,const=0.1):return num/(dist+const)→
  52. 52. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  53. 53. Chapter 8, Building Price modelsProgramming Collective Intelligence•→ >0
  54. 54. Chapter 8, Building Price modelsProgramming Collective Intelligence
  55. 55. Chapter 8, Building Price modelsProgramming Collective Intelligence
  56. 56. Chapter 8, Building Price modelsProgramming Collective Intelligence𝑓 𝑥 = 𝑒−dist22𝜎2
  57. 57. Chapter 8, Building Price modelsProgramming Collective Intelligence
  58. 58. Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total weigh𝑡𝑖<𝑘
  59. 59. Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total weigh𝑡𝑖<𝑘>>> numpredict.weightedknn(data,(99.0,5.0))32.640981119354301
  60. 60. Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total weigh𝑡𝑖<𝑘>>> numpredict.weightedknn(data,(99.0,5.0))32.640981119354301rigorous
  61. 61. Chapter 8, Building Price modelsProgramming Collective Intelligenceweight distance 𝑣𝑒𝑐1, 𝑖 th nearest 𝑣𝑒𝑐 ∗ value 𝑖total weigh𝑡𝑖<𝑘>>> numpredict.weightedknn(data,(99.0,5.0))32.640981119354301rigorous
  62. 62. Chapter 8, Building Price modelsProgramming Collective Intelligence
  63. 63. Chapter 8, Building Price modelsProgramming Collective Intelligence
  64. 64. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique
  65. 65. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set
  66. 66. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set95%
  67. 67. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•
  68. 68. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set
  69. 69. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set
  70. 70. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  71. 71. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  72. 72. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  73. 73. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  74. 74. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  75. 75. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  76. 76. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.
  77. 77. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def dividedata(data,test=0.05):…return trainset,testset
  78. 78. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def testalgorithm(algf,trainset,testset):…return
  79. 79. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def testalgorithm(algf,trainset,testset):…return− 2𝑡𝑒𝑠𝑡𝑠𝑒𝑡𝑡𝑒𝑠𝑡𝑠𝑒𝑡
  80. 80. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def testalgorithm(algf,trainset,testset):…return− 2𝑡𝑒𝑠𝑡𝑠𝑒𝑡𝑡𝑒𝑠𝑡𝑠𝑒𝑡def crossvalidate(algf,data,trials=100,test=0.05):…return testalgorithm trials
  81. 81. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def testalgorithm(algf,trainset,testset):…return− 2𝑡𝑒𝑠𝑡𝑠𝑒𝑡𝑡𝑒𝑠𝑡𝑠𝑒𝑡def crossvalidate(algf,data,trials=100,test=0.05):…return testalgorithm trialsalgf gaussian
  82. 82. Chapter 8, Building Price modelsProgramming Collective Intelligence• technique• Training set Test set•1.Training set2.Test set3.def testalgorithm(algf,trainset,testset):…return− 2𝑡𝑒𝑠𝑡𝑠𝑒𝑡𝑡𝑒𝑠𝑡𝑠𝑒𝑡def crossvalidate(algf,data,trials=100,test=0.05):…return testalgorithm trialsalgf gaussian
  83. 83. Chapter 8, Building Price modelsProgramming Collective Intelligence
  84. 84. Chapter 8, Building Price modelsProgramming Collective Intelligence
  85. 85. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  86. 86. Chapter 8, Building Price modelsProgramming Collective Intelligence••• →
  87. 87. Chapter 8, Building Price modelsProgramming Collective Intelligence••• →rating, age, aisle, bottlesize• aisle• bottlesize (ml)
  88. 88. Chapter 8, Building Price modelsProgramming Collective Intelligence••• →rating, age, aisle, bottlesize• aisle• bottlesize (ml)
  89. 89. Chapter 8, Building Price modelsProgramming Collective Intelligence
  90. 90. Chapter 8, Building Price modelsProgramming Collective Intelligence• i i
  91. 91. Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•
  92. 92. Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•def rescale(data,scale):… i scale[i]return scaleddata
  93. 93. Chapter 8, Building Price modelsProgramming Collective Intelligence• i i•def rescale(data,scale):… i scale[i]return scaleddata
  94. 94. Chapter 8, Building Price modelsProgramming Collective Intelligence
  95. 95. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  96. 96. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  97. 97. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  98. 98. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  99. 99. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  100. 100. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization
  101. 101. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•
  102. 102. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization••
  103. 103. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••
  104. 104. Chapter 8, Building Price modelsProgramming 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. 105. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfscale algf
  106. 106. Chapter 8, Building Price modelsProgramming 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. 107. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4
  108. 108. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4
  109. 109. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4
  110. 110. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4>>>import optimization>>>costf=numpredict.createcostfunction(numpredict.knnestimate,data)>>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2)[11,18,0,6]
  111. 111. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(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, bottlesizeaisle
  112. 112. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4>>>import optimization>>>costf=numpredict.createcostfunction(numpredict.knnestimate,data)>>> optimization.annealingoptimize(numpredict.weightdomain,costf,step=2)[11,18,0,6]bottlesize
  113. 113. Chapter 8, Building Price modelsProgramming Collective Intelligence• Chapter 5 Optimization•••def createcostfunction(algf,data):def costf(scale):sdata=rescale(data,scale)return crossvalidate(algf,sdata,trials=10)return costfweightdomain=[(0,20)]*4
  114. 114. Chapter 8, Building Price modelsProgramming Collective Intelligence
  115. 115. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  116. 116. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  117. 117. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  118. 118. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  119. 119. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  120. 120. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  121. 121. Chapter 8, Building Price modelsProgramming Collective Intelligence•
  122. 122. Chapter 8, Building Price modelsProgramming Collective Intelligence•1/2 60%def wineset3():…
  123. 123. Chapter 8, Building Price modelsProgramming Collective Intelligence•1/2 60%def wineset3():…
  124. 124. Chapter 8, Building Price modelsProgramming Collective Intelligence••
  125. 125. Chapter 8, Building Price modelsProgramming Collective Intelligence••• 60% -• 35% -• …
  126. 126. Chapter 8, Building Price modelsProgramming Collective Intelligencedef probguess(data,vec1,low,high,k=5,weightf=gaussian):…return vec1 low-high
  127. 127. Chapter 8, Building Price modelsProgramming Collective Intelligencedef probguess(data,vec1,low,high,k=5,weightf=gaussian):…return vec1 low-highk low-highnweight += weightreturn nweight(=low-high weight / k weight
  128. 128. Chapter 8, Building Price modelsProgramming Collective Intelligence
  129. 129. Chapter 8, Building Price modelsProgramming Collective Intelligence
  130. 130. Chapter 8, Building Price modelsProgramming Collective Intelligence
  131. 131. Chapter 8, Building Price modelsProgramming Collective Intelligence
  132. 132. Chapter 8, Building Price modelsProgramming Collective Intelligence
  133. 133. Chapter 8, Building Price modelsProgramming Collective Intelligence
  134. 134. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
  135. 135. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
  136. 136. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
  137. 137. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 - 5• 0-10• 0-15• …
  138. 138. Chapter 8, Building Price modelsProgramming Collective Intelligence
  139. 139. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
  140. 140. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
  141. 141. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
  142. 142. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …
  143. 143. Chapter 8, Building Price modelsProgramming Collective Intelligence• 0 – 5• 5 - 10• 10-15• …0Gaussian
  144. 144. Chapter 8, Building Price modelsProgramming Collective Intelligence
  145. 145. Chapter 8, Building Price modelsProgramming Collective Intelligence
  146. 146. Chapter 8, Building Price modelsProgramming Collective Intelligence
  147. 147. Chapter 8, Building Price modelsProgramming Collective Intelligence
  148. 148. Chapter 8, Building Price modelsProgramming Collective Intelligence
  149. 149. Chapter 8, Building Price modelsProgramming Collective Intelligence――
  150. 150. Chapter 8, Building Price modelsProgramming Collective Intelligence――
  151. 151. Chapter 8, Building Price modelsProgramming Collective Intelligence――――
  152. 152. Chapter 8, Building Price modelsProgramming Collective Intelligence――――
  153. 153. Chapter 8, Building Price modelsProgramming Collective Intelligence――――――
  154. 154. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k
  155. 155. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k――
  156. 156. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian
  157. 157. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――
  158. 158. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation
  159. 159. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set
  160. 160. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &
  161. 161. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――
  162. 162. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN
  163. 163. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――
  164. 164. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――
  165. 165. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――
  166. 166. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――
  167. 167. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――
  168. 168. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――
  169. 169. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ――
  170. 170. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ―― X-Y 60%
  171. 171. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ―― X-Y 60%――
  172. 172. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ―― X-Y 60%――
  173. 173. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ―― X-Y 60%――
  174. 174. Chapter 8, Building Price modelsProgramming Collective Intelligence―――――― k―― ――Gaussian• ――Cross-Validation• Training set test set &――kNN• ――――――• ―― X-Y 60%――
  175. 175. Chapter 8, Building Price modelsProgramming Collective Intelligence
  176. 176. Chapter 8, Building Price modelsProgramming Collective Intelligence
  177. 177. terasaka.kChapter 8, Building Price modelsProgramming Collective Intelligence• ――• ――• kNN―― k• ―― ――Gaussian• ――Cross-Validation• Training set test set &• ――kNN• ――• ――• ――• ―― X-Y 60%• ――
  178. 178. Chapter 8, Building Price modelsProgramming Collective Intelligenceterasaka.k2011-11-09T17:39:24

×