-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
- 5000개 데이터 일 때 K 확인 - 8000개 데이터 일 때 K 확인
다른 점과의 거리 구하는 distanceTo 함수 + 연산 - 연산 / 연산
각 점에서의 클러스터 내의 응집도를 구하는 findCohesion 함수 구현 각 점에서의 실루엣 값을 구하는 findSilhouette 함수 구현
cluster equtable 채택 다른 클러스터와의 분리도를 구하는 findSeparation 구현
클러스터의 각 점에 대한 실루엣 값의 평균 계산
center 연산 프로퍼티로 변경
A점 silhouette 값 테스트 B점 silhouette 값 테스트 클러스터1 평균 silhouette 값 테스
There was a problem hiding this comment.
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 { | ||
return Int(sqrt(Double(numberOfData/2))) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 return 생략 가능한거 어떻게 맞추면 좋을지 논의해보면 좋을 거 같애용 ㅎ_ㅎ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 이 생략가능하다는게 어떤 의미인지 좀 더 설명해 주실 수 있나요!!
There was a problem hiding this comment.
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 생략 가능하지 않나요 ~~
There was a problem hiding this 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]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
띄어쓰기가 두번이..
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
응집도 계산이라서 find 보다 calculate 이런게 나아보여요!
제가 동작을 잘 몰라서 그런거일수도 있습니당
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
클래스 명이 계산기니까 calculate가 더 나아 보이네요!!
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기두 계산아닌가용..?
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) | ||
} |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test_find_cohesion() ...?
밑에는 이렇게 되어있는 것 같아서요 ~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엥 이상한 이름들이 많네요 큐ㅠㅠ 바로 수정하겠습니다!
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 두 테스트 함수의 차이는 무엇인가요??? 같은 행동을 한다면 하나의 함수에서 하는건 어떤가요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 함수당 xctAssert 함수가 하나씩 들어가는 게 이상적이라고 생각해서 나눴습니다!!
There was a problem hiding this 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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
얘(coordinates
) 는 let
으로 놔둬도 되지 않아요? 나중에 수정할 예정인건가요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기는 팀원들이랑 논의하다가 뒤에 var로 바꿀일이 있어서 저도 바꿔놓았는데 사실상 이번 PR에서의 의미는 없네요 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아아, 논의하신거라면 패쓰~
https://en.wikipedia.org/wiki/Silhouette_(clustering) |
PR 내용도 잘 올리고, 단위 테스트도 다들 잘 하시고, 논의 사항도 남겨두고, |
1이 되려고 노력중입니다🔥🔥🔥 |
There was a problem hiding this 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]() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
린트에서 오류가 뜨진 않았나요?
구현내용
[feat] [test]
Silhouette Method
![스크린샷 2020-11-26 오후 5 11 12](https://user-images.githubusercontent.com/62557093/100324299-63f8fb80-300a-11eb-8bc6-117387ed2076.png)
현재 클러스터의 응집도와 다른 클러스터 간의 결합도를 정량적으로 판단하여 클러스터링이 잘 되었는지 판단하는 방법i번째 데이터에 대하여
a(i) : 같은 클러스터 안에 있는 다른 데이터 포인트와의 평균거리(dissimilarity).
b(i) : i가 속하지 않은 다른 클러스터와의 평균 거리 중 가장 작은 거리
논의사항
rule of thumb와 silhouette 검증 방법을 결합해서 적절한 K 값을 구하는 방법을 사용하면 좋을 것 같은데,
어떻게 결합할지 논의해 보면 좋겠어요!
많은 피드백 부탁드립니다🙇🏻♀️
화면