주로 다루는 것은 데이타 덩어리를 가지고 있을 때
그들 간에 연관성을 찾아 그룹들을 발견해 내는 것이다.
만약 예상되는 결과값이 있다면 지도학습 ( Supervised Learning ) 이라 부르고
예상되는 결과값이 없다면 자율학습 ( Unsupervised Learning ) 이라고 부른다.
저자는 간단하게 그 알고리즘을 소개하는데,
- 다양한 소스에서 의미있는 데이터를 준비하기 : RSS Feed 사용
- 계산법
- 거리측정 알고리즘 ( distance metrics ) : 여기서는 Pearson Correlation를 사용한다.
- K-평균 알고리즘 ( K-Means )
- 거리측정 알고리즘 ( distance metrics ) : 여기서는 Pearson Correlation를 사용한다.
- 도표 시각화 알고리즘 : Dendrogram Tree을 사용했다.

- 복잡한 데이터 셋 : Zebo에서 그 데이터를 가져온다.
내용은 어려웠지만
큰 그림은 이것이 전부였던
정말 쉽게 쓴 책인 것 같다.
입문서로 추천!
그런데 Collective Intelligence라는 것이
결국 대용량 데이터에서 개인화에 맞추어 데이터 마이닝 하는 과정이고도 말할 수 있는 것 아닌가?
'공부노트' 카테고리의 다른 글
| 그룹 발견하기 ( Discovering Groups ) (2) | 2008/09/09 |
|---|---|
| 계층적 군집화 (0) | 2008/09/09 |
| 추천합니다. ( Making Recommendations ) (0) | 2008/09/02 |
| 집단 지성 소개 ( What is the Collective Intelligence ) (0) | 2008/09/01 |
여기서 우선 우리는 계층적 군집화를 알아보자
계층적 군집화는 책에 설명되어있는것 처럼 여러개의 군집들을 가까운것을 묶고 또 새로운 군집을 만들고 그것들과 또 가까운 그룹을 만드는 것을 재귀적으로 해서 마지막으로 하나의 군집을 만드는 것이다.
def hcluster(rows, distance=pearson): #{{{1
distances = {}
currentclustid = -1
clust = [ bicluster(rows[i],id=i) for i in range(len(rows)) ]
일단 코드에서는 줄만큼 군집을 만들어 낸다.
while len(clust) > 1:
그리고 군집이 하나가 될때까지 밑의 사항을 반복한다.
lowestpair = (0, 1)
closest = distance(clust[0].vec, clust[1].vec)
처음 값을 그냥 0,1번이 가지고 있는 값으로 세팅했다.
for i in range(len(clust)):
for j in range(i+1, len(clust)):
여기서는 군집들을 버블소트 알고리즘처럼 하나하나씩 전부 비교한다.
if (clust[i].id, clust[j].id) not in distances:
distances[(clust[i].id, clust[j].id)] = distance(clust[i].vec, clust[j].vec)
d = distances[(clust[i].id, clust[j].id)]
이부분은 다시 거리를 계산하지 않기위해서 각 비교값들을 저장하는 부분이다.
if d<closest:
closest = d
lowetpair = (i, j)
가장 작은 셋보다 작을 경우 그 주소를 작은 셋으로 저장한다.
mergevec = [
(clust[lowetpair[0]].vec[i] + clust[lowestpair[1]].vec[i])/2.0
for i in range(len(clust[0].vec))]
두 군집의 평군 값을 계산한다.
newcluster = bicluster(mergevec, left=clust[lowestpair[0]],
right=clust[lowestpair[1]],
distance=closest, id=currentclustid)
currentclustid-=1
del clust[lowestpair[1]]
del clust[lowestpair[0]]
clust.append(newcluster)
return clust[0]
계층적 군집방법은 모든 원소를 다비교해야한다. 그러므로 N*(N-1)만큼 비교를 해야한다.
'공부노트' 카테고리의 다른 글
| 그룹 발견하기 ( Discovering Groups ) (2) | 2008/09/09 |
|---|---|
| 계층적 군집화 (0) | 2008/09/09 |
| 추천합니다. ( Making Recommendations ) (0) | 2008/09/02 |
| 집단 지성 소개 ( What is the Collective Intelligence ) (0) | 2008/09/01 |
The user-based filtering algorithm is inefficient becase it compares a user to all other users every time a recommendation is needed. Write a function to precompute user similarities, and alter the recommendation code to user only the top five other users to get recommendations
간단하게 사용자 기반 필터링을 미리 뽑아두자 라는 의도인데
처음에는 다음과 같이 구현했었다
def calculateSimilarUser(prefs,n=10):
result={}
c=0
for user in prefs:
c+=1
if c%100==0: print "%d / %d" % (c,len(prefs))
scores=topMatches(prefs,user,n=n,similarity=sim_distance)
result[user]=scores
return result
>>> usersim = recommendations.calculateSimilarUser(recommendations.critics)
>>> usersim
{'Jack Matthews': [(0.80000000000000004, 'Gene Seymour'),(0.21052631578947367, 'Lisa Rose'), (0.18181818181818182, 'MichaelPhillips'), (0.18181818181818182, 'Claudia Puig'), (0.13793103448275862,
...
그런데 각 최상위 5개라는 말에 이런 구현은 어떨까? 싶었다.
def calculateSimilarUser(prefs,n=10):
result={}
c=0
for user in prefs:
c+=1
if c%100==0: print "%d / %d" % (c,len(prefs))
result[user]=getRecommendations(prefs,user)[0:5]
return result
유저별 추천 목록을 미리 계산해 두는 것이다.
>>> usersim = recommendations.calculateSimilarUser(recommendations.critics)
>>> usersim['Jack Matthews']
[(2.1505590044630245, 'Just My Luck')]
>>> for each in usersim:
... print usersim[each]
...
[(2.1505590044630245, 'Just My Luck')]
[]
[(2.683756272799255, 'Lady in the Water')]
[]
[(3.3477895267131013, 'The Night Listener'), (2.8325499182641614, 'Lady in the Water'), (2.5309807037655645, 'Just My Luck')]
[]
[(2.8092760065251268, 'Just My Luck'), (2.6946367039803629, 'You, Me and Dupree')]
비슷한 취향의 유저를 저장해두는 것과
아직 보지 않은 추천 항목을 저장해두는 것이
어떤 의미가 있을까?
'예제풀이' 카테고리의 다른 글
| Tanimoto Score 구현하기 (0) | 2008/09/02 |
|---|---|
| User-based efficiency 구현하기 (0) | 2008/09/02 |
| Tanimoto Score 구현하기 (0) | 2008/09/02 |
| Tag Similarity 구현하기 ( del.icio.us API 사용 ) (0) | 2008/09/02 |











Prev