Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

K 결정 및 알고리즘 성능 판단(실루엣 이용) 함수 추가, 테스트 #33

Merged
merged 13 commits into from
Nov 26, 2020

Conversation

A-by-alimelon
Copy link
Collaborator

구현내용

[feat] [test]

  • k 결정 방법 Rule of Thumb 구현
  • k 검증 - Average Silhouette Calculator 클래스 구현
  • 테스트 함수 작성

Silhouette Method

스크린샷 2020-11-26 오후 5 11 12

현재 클러스터의 응집도와 다른 클러스터 간의 결합도를 정량적으로 판단하여 클러스터링이 잘 되었는지 판단하는 방법

i번째 데이터에 대하여

a(i) :  같은 클러스터 안에 있는 다른 데이터 포인트와의 평균거리(dissimilarity).

b(i) : i가 속하지 않은 다른 클러스터와의 평균 거리 중 가장 작은 거리

  • 해석
  1. b가 a보다 많이 클수록 1에 가까워지고 좋다.
  2. 0이면 지금 클러스터나 이웃 클러스터나 어디 있든 상관 없다.
  3. silhouette는 -1 부터 1 사이의 값을 가진다 → 1일수록 잘 부합하는 거고, -1일수록 잘못 뭉쳐져 있다는 뜻

논의사항

rule of thumb와 silhouette 검증 방법을 결합해서 적절한 K 값을 구하는 방법을 사용하면 좋을 것 같은데,
어떻게 결합할지 논의해 보면 좋겠어요!
많은 피드백 부탁드립니다🙇🏻‍♀️

화면

스크린샷 2020-11-26 오후 4 56 41

A-by-alimelon and others added 12 commits November 25, 2020 14:31
- 5000개 데이터 일 때 K 확인
- 8000개 데이터 일 때 K 확인
다른 점과의 거리 구하는 distanceTo 함수
+ 연산
- 연산
/ 연산
각 점에서의 클러스터 내의 응집도를 구하는 findCohesion 함수 구현
각 점에서의 실루엣 값을 구하는 findSilhouette 함수 구현
cluster equtable 채택
다른 클러스터와의 분리도를 구하는 findSeparation 구현
클러스터의 각 점에 대한 실루엣 값의 평균 계산
center 연산 프로퍼티로 변경
A점 silhouette 값 테스트
B점 silhouette 값 테스트
클러스터1 평균 silhouette 값 테스
Copy link
Collaborator

@eunjeongS2 eunjeongS2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트할때 계산하시느라 고생하셨겠네용 ㅠㅠ
고생하셨어요 ~~~~

Comment on lines 11 to 13
func KwithRuleOfThumb(numberOfData: Int) -> Int {
return Int(sqrt(Double(numberOfData/2)))
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 return 생략 가능한거 어떻게 맞추면 좋을지 논의해보면 좋을 거 같애용 ㅎ_ㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return 이 생략가능하다는게 어떤 의미인지 좀 더 설명해 주실 수 있나요!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func KwithRuleOfThumb(numberOfData: Int) -> Int {
    Int(sqrt(Double(numberOfData/2)))
}

이렇게용 ! 함수내부에 반환만하면 return 생략 가능하지 않나요 ~~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 오오 이런 방법이 있는 줄은 몰랐네요! 생략을 하는게 더 나을까요 ? ? 논의 해봅시당 ㅎㅎ

}

func findAverageSilhouette(cluster: Cluster) -> Double {
var silhouettes = [Double]()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

띄어쓰기가 두번이..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

린트에서 오류가 뜨진 않았나요?

}

// 점과 현재 포함된 클러스터의 응집도 계산
func findCohesion(in cluster: Cluster, target: Coordinate) -> Double {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

응집도 계산이라서 find 보다 calculate 이런게 나아보여요!
제가 동작을 잘 몰라서 그런거일수도 있습니당

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

클래스 명이 계산기니까 calculate가 더 나아 보이네요!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그냥 cohesion 도 괜찮을거 같구용 !

}

// 점과 포함되지 않은 클러스터 간의 분리도 계산
func findSeparation(in cluster: Cluster, target: Coordinate) -> Double {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기두 calculate가 나을거같은데 아니면 말씀해주세용!

return silhouettes.reduce(.zero, +) / Double(silhouettes.count)
}

func findSilhouette(with cluster: Cluster, target: Coordinate) -> Double {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기두 계산아닌가용..?

Comment on lines 49 to 59
let powX = pow(self.x - other.x, 2.0)
let powY = pow(self.y - other.y, 2.0)

return sqrt(powX + powY)
}

static func + (left: Coordinate, right: Coordinate) -> Coordinate {
let x = left.x + right.x
let y = left.y + right.y
return Coordinate(x: x, y: y)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 개행 통일하면 보기 더 예쁠(?) 것 같아용 ㅎㅎ
지금도 좋습니다 ~~!

XCTAssertEqual(KwithRuleOfThumb(numberOfData: numberOfData), expected)
}

func test_find_find_cohesion() throws {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_find_cohesion() ...?
밑에는 이렇게 되어있는 것 같아서요 ~~

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엥 이상한 이름들이 많네요 큐ㅠㅠ 바로 수정하겠습니다!

Comment on lines 58 to 74
func test_find_silhouette_A() throws {
guard let result = avc?.findSilhouette(with: cluster1, target: cluster1.coordinates[0]) else {
return
}

let expected = 0.619912
XCTAssertEqual(expected, result, accuracy: accuracy)
}

func test_find_silhouette_B() throws {
guard let result = avc?.findSilhouette(with: cluster1, target: cluster1.coordinates[1]) else {
return
}

let expected = 0.717126
XCTAssertEqual(expected, result, accuracy: accuracy)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 두 테스트 함수의 차이는 무엇인가요??? 같은 행동을 한다면 하나의 함수에서 하는건 어떤가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트 함수당 xctAssert 함수가 하나씩 들어가는 게 이상적이라고 생각해서 나눴습니다!!

Copy link
Collaborator

@beggu84 beggu84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

궁금증. 여기서 말하는 '실루엣'이 무슨 의미로 쓰인거에요?

@@ -56,6 +83,11 @@ struct Coordinate: Equatable {
}

struct Cluster {
let center: Coordinate
let coordinates: [Coordinate]
var coordinates: [Coordinate]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘(coordinates) 는 let 으로 놔둬도 되지 않아요? 나중에 수정할 예정인건가요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 팀원들이랑 논의하다가 뒤에 var로 바꿀일이 있어서 저도 바꿔놓았는데 사실상 이번 PR에서의 의미는 없네요 😅

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아아, 논의하신거라면 패쓰~

@A-by-alimelon
Copy link
Collaborator Author

궁금증. 여기서 말하는 '실루엣'이 무슨 의미로 쓰인거에요?

https://en.wikipedia.org/wiki/Silhouette_(clustering)
클러스터링 알고리즘을 확인하는 방법론의 이름이라고 생각했습니다
실루엣 값이라고 하는 위의 수식에 대한 값이요!

@beggu84
Copy link
Collaborator

beggu84 commented Nov 26, 2020

PR 내용도 잘 올리고, 단위 테스트도 다들 잘 하시고, 논의 사항도 남겨두고,
C 팀의 silhouette 이 1에 가까운가 봐요.

@A-by-alimelon
Copy link
Collaborator Author

PR 내용도 잘 올리고, 단위 테스트도 다들 잘 하시고, 논의 사항도 남겨두고,
C 팀의 silhouette 이 1에 가까운가 봐요.

1이 되려고 노력중입니다🔥🔥🔥

Sprint 2 automation moved this from To do to In progress Nov 26, 2020
Copy link
Collaborator

@rnfxl92 rnfxl92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고 많으셨습니다.

}

func findAverageSilhouette(cluster: Cluster) -> Double {
var silhouettes = [Double]()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

린트에서 오류가 뜨진 않았나요?

@donggeonoh donggeonoh merged commit 26c96df into develop Nov 26, 2020
Sprint 2 automation moved this from In progress to Done Nov 26, 2020
@A-by-alimelon A-by-alimelon deleted the feature/kmeans/select-k-coefficient branch December 3, 2020 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

5 participants