centrality.py 수정
- 데이터셋 정리 - 출력 형식 통일 - 영화별 출연진 betweenness 평균과 스크린 수 당 매출액 상관관계 산출 6월 면담확인서 제출 최종보고서 제출
Showing
3 changed files
with
29 additions
and
82 deletions
면담보고서/6월 면담확인서.hwp
0 → 100644
No preview for this file type
| 1 | from igraph import * | 1 | from igraph import * |
| 2 | import pymongo | 2 | import pymongo |
| 3 | +import matplotlib.pyplot as plt | ||
| 3 | 4 | ||
| 4 | conn = pymongo.MongoClient("localhost") | 5 | conn = pymongo.MongoClient("localhost") |
| 5 | db = conn.test | 6 | db = conn.test |
| ... | @@ -7,9 +8,11 @@ MOVIE = db.movie | ... | @@ -7,9 +8,11 @@ MOVIE = db.movie |
| 7 | cur = MOVIE.find() | 8 | cur = MOVIE.find() |
| 8 | audiences = {} | 9 | audiences = {} |
| 9 | salesPerScreens = [] | 10 | salesPerScreens = [] |
| 11 | +salesPerScreensToObj = {} | ||
| 10 | for c in cur: | 12 | for c in cur: |
| 11 | audiences[c["name"]] = c["audiences"] | 13 | audiences[c["name"]] = c["audiences"] |
| 12 | salesPerScreens.append({"name": c["name"], "value": c["sales"] / c["screens"]}) | 14 | salesPerScreens.append({"name": c["name"], "value": c["sales"] / c["screens"]}) |
| 15 | + salesPerScreensToObj[c["name"]] = round(c["sales"] / c["screens"], 5) | ||
| 13 | 16 | ||
| 14 | salesPerScreensTmp = salesPerScreens[:] | 17 | salesPerScreensTmp = salesPerScreens[:] |
| 15 | salesPerScreensSorted = sorted(salesPerScreensTmp, key=lambda n: salesPerScreens[salesPerScreens.index(n)]["value"], reverse=True)[:50] | 18 | salesPerScreensSorted = sorted(salesPerScreensTmp, key=lambda n: salesPerScreens[salesPerScreens.index(n)]["value"], reverse=True)[:50] |
| ... | @@ -143,78 +146,9 @@ data = { | ... | @@ -143,78 +146,9 @@ data = { |
| 143 | # "헬로우 고스트": "차태현,강예원,이문수,고창석,장영남,천보근,공호석,정규수,김진성,구승현", | 146 | # "헬로우 고스트": "차태현,강예원,이문수,고창석,장영남,천보근,공호석,정규수,김진성,구승현", |
| 144 | "하모니": "김윤진,나문희,강예원,이다희,장영남,박준면,정수영,이태경,문경민,도용구,지성원,차진혁,박혜진", #salesPerScreensSorted 44위 | 147 | "하모니": "김윤진,나문희,강예원,이다희,장영남,박준면,정수영,이태경,문경민,도용구,지성원,차진혁,박혜진", #salesPerScreensSorted 44위 |
| 145 | # "오싹한 연애": "손예진,이민기,박철민,김현숙,이미도,신성훈,윤지민,황승언,이현진", #128위. 300만 이상 | 148 | # "오싹한 연애": "손예진,이민기,박철민,김현숙,이미도,신성훈,윤지민,황승언,이현진", #128위. 300만 이상 |
| 146 | - # "방자전": "", | ||
| 147 | - # "형": "", | ||
| 148 | - # "마더": "", | ||
| 149 | - # "그놈 목소리": "", | ||
| 150 | - # "친구 2": "", | ||
| 151 | - # "식객": "", | ||
| 152 | - # "26년": "", | ||
| 153 | - # "고지전": "", | ||
| 154 | - # "워낭소리": "", #salesPerScreensSorted 30위 | ||
| 155 | - # "프리즌": "", | ||
| 156 | - # "가장 보통의 연애": "", | ||
| 157 | - # "말모이": "", | ||
| 158 | - # "극비수사": "", | ||
| 159 | - # "표적": "", | ||
| 160 | - # "너의 결혼식": "", | ||
| 161 | - # "내가 살인범이다": "", | ||
| 162 | - # "부당거래": "", | ||
| 163 | - # "소원": "", | ||
| 164 | "너는 내 운명": "전도연,황정민,나문희,정유석,서주희,윤제문,임종윤,김상호,고수희,김부선,김광규", #salesPerScreensSorted 42위 | 149 | "너는 내 운명": "전도연,황정민,나문희,정유석,서주희,윤제문,임종윤,김상호,고수희,김부선,김광규", #salesPerScreensSorted 42위 |
| 165 | - # "시라노; 연애조작단": "", | ||
| 166 | - # "곤지암": "", | ||
| 167 | - # "살인자의 기억법": "", | ||
| 168 | "마파도": "이정진,이문식,여운계,김수미,김을동,김형자,길해연,오달수,서영희", #salesPerScreensSorted 13위 | 150 | "마파도": "이정진,이문식,여운계,김수미,김을동,김형자,길해연,오달수,서영희", #salesPerScreensSorted 13위 |
| 169 | - # "후궁 : 제왕의 첩": "", | ||
| 170 | - # "탐정 : 더 비기닝": "", | ||
| 171 | - # "지금 만나러 갑니다": "", | ||
| 172 | - # "가문의 부활 - 가문의 영광3": "", | ||
| 173 | - # "위험한 상견례": "", | ||
| 174 | - # "아수라": "", | ||
| 175 | - # "보안관": "", | ||
| 176 | - # "기술자들": "", | ||
| 177 | - # "굿모닝 프레지던트": "", | ||
| 178 | "태극기 휘날리며": "장동건,원빈,이은주,공형진,장민호,이영란", #salesPerScreensSorted 2위 | 151 | "태극기 휘날리며": "장동건,원빈,이은주,공형진,장민호,이영란", #salesPerScreensSorted 2위 |
| 179 | - # "라스트 갓파더": "", | ||
| 180 | - # "1번가의 기적": "", | ||
| 181 | - # "증인": "", | ||
| 182 | - # "목격자": "", | ||
| 183 | - # "조작된 도시": "", | ||
| 184 | - # "블랙머니": "", | ||
| 185 | - # "반창꼬": "", | ||
| 186 | - # "우리들의 행복한 시간": "", | ||
| 187 | - # "조선명탐정: 흡혈괴마의 비밀": "", | ||
| 188 | - # "화차": "", | ||
| 189 | - # "이웃사람": "", | ||
| 190 | - # "재심": "", | ||
| 191 | - # "히트맨": "", | ||
| 192 | - # "사바하": "", | ||
| 193 | - # "화이: 괴물을 삼킨 아이": "", | ||
| 194 | - # "의뢰인": "", | ||
| 195 | - # "가문의 영광4 - 가문의 수난": "", | ||
| 196 | - # "블라인드": "", | ||
| 197 | - # "박열": "", | ||
| 198 | - # "미인도": "", | ||
| 199 | - # "음란서생": "", | ||
| 200 | - # "내 생애 가장 아름다운 일주일": "", | ||
| 201 | - # "하녀": "", | ||
| 202 | - # "황해": "", | ||
| 203 | - # "7광구": "", | ||
| 204 | - # "타짜: 원 아이드 잭": "", | ||
| 205 | - # "박쥐": "", | ||
| 206 | - # "마당을 나온 암탉": "", | ||
| 207 | - # "악의 연대기": "", | ||
| 208 | - # "강남 1970": "", | ||
| 209 | - # "신의 한 수: 귀수편": "", | ||
| 210 | - # "마이 웨이": "", | ||
| 211 | - # "나의 사랑 나의 신부": "", | ||
| 212 | - # "바르게 살자": "", | ||
| 213 | - # "내 사랑 내 곁에": "", | ||
| 214 | - # "초능력자": "", | ||
| 215 | - # "굿바이 싱글": "", | ||
| 216 | - # "몽타주": "", | ||
| 217 | - # "명당": "", | ||
| 218 | } | 152 | } |
| 219 | #500만 이상 + 스크린 수당 매출액 50위 이상 => 79개 영화, 730개 노드, 9348개 엣지 | 153 | #500만 이상 + 스크린 수당 매출액 50위 이상 => 79개 영화, 730개 노드, 9348개 엣지 |
| 220 | 154 | ||
| ... | @@ -239,15 +173,18 @@ def named_union(graph1, graph2): #두 그래프 합성 | ... | @@ -239,15 +173,18 @@ def named_union(graph1, graph2): #두 그래프 합성 |
| 239 | Z.vs["label"] = Z.vs["name"][:] | 173 | Z.vs["label"] = Z.vs["name"][:] |
| 240 | return Z | 174 | return Z |
| 241 | 175 | ||
| 176 | +def replaceText(x): | ||
| 177 | + for r in [" ", "-", ":", "(", ")", ",", "1", "2", "3", "4", "6", "7", "8", "9"]: | ||
| 178 | + x = x.replace(r, "") | ||
| 179 | + return x | ||
| 180 | + | ||
| 242 | def printResult(names, values, x, y, n): | 181 | def printResult(names, values, x, y, n): |
| 243 | for i in range(0, n): | 182 | for i in range(0, n): |
| 244 | - text = names[i][:] | 183 | + text = replaceText(names[i][:]) |
| 245 | - for r in [" ", "-", ":", "(", ")", ",", "1", "2", "3", "4", "6", "7", "8", "9"]: | ||
| 246 | - text = text.replace(r, "") | ||
| 247 | name = names[i].rjust(x - len(text)) | 184 | name = names[i].rjust(x - len(text)) |
| 248 | value = str(round(values[i], 5)) | 185 | value = str(round(values[i], 5)) |
| 249 | value = value.rjust(y) | 186 | value = value.rjust(y) |
| 250 | - print(i, name, value) | 187 | + print(name, value) |
| 251 | 188 | ||
| 252 | print("<스크린수 당 매출액 1~50위>") | 189 | print("<스크린수 당 매출액 1~50위>") |
| 253 | # nnn = 0 | 190 | # nnn = 0 |
| ... | @@ -304,13 +241,15 @@ for movie in data: | ... | @@ -304,13 +241,15 @@ for movie in data: |
| 304 | weight[join]["audiences"] += audiences[movie] | 241 | weight[join]["audiences"] += audiences[movie] |
| 305 | weight[join]["count"] += 1 | 242 | weight[join]["count"] += 1 |
| 306 | 243 | ||
| 244 | +print("\n<영화 출연 수>") | ||
| 307 | for f in sorted(list(frequency.keys()), key=lambda x: frequency[x], reverse=True)[:10]: | 245 | for f in sorted(list(frequency.keys()), key=lambda x: frequency[x], reverse=True)[:10]: |
| 308 | - print(f, frequency[f]) | 246 | + print(f, str(frequency[f]).rjust(3)) |
| 309 | 247 | ||
| 310 | print("\n<같은 영화에 같이 출연한 빈도수>") | 248 | print("\n<같은 영화에 같이 출연한 빈도수>") |
| 311 | topten = sorted(keys, key=lambda n: weight[n]["count"], reverse=True)[:10] | 249 | topten = sorted(keys, key=lambda n: weight[n]["count"], reverse=True)[:10] |
| 312 | for t in topten: | 250 | for t in topten: |
| 313 | - print(t, ":", weight[t]["count"]) | 251 | + tt = replaceText(t) |
| 252 | + print(t.rjust(14 - len(tt)) + " ", weight[t]["count"]) | ||
| 314 | 253 | ||
| 315 | names, names1, names2 = G.vs["name"][:], G.vs["name"][:], G.vs["name"][:] | 254 | names, names1, names2 = G.vs["name"][:], G.vs["name"][:], G.vs["name"][:] |
| 316 | 255 | ||
| ... | @@ -326,9 +265,8 @@ for k in keys: | ... | @@ -326,9 +265,8 @@ for k in keys: |
| 326 | continue | 265 | continue |
| 327 | [s, e] = k.split(",") | 266 | [s, e] = k.split(",") |
| 328 | sIdx, eIdx = names.index(s), names.index(e) | 267 | sIdx, eIdx = names.index(s), names.index(e) |
| 329 | - edges = G.es.select(_between = ([sIdx], [eIdx])) | 268 | + edge = G.es.select(_between = ([sIdx], [eIdx]))[0] |
| 330 | - for e in edges: | 269 | + edge_weight[edge.index] = weight[k]["count"] |
| 331 | - edge_weight[e.index] = weight[k]["count"] | ||
| 332 | 270 | ||
| 333 | print("\n<betweenness>") | 271 | print("\n<betweenness>") |
| 334 | bn = G.betweenness(weights=edge_weight) | 272 | bn = G.betweenness(weights=edge_weight) |
| ... | @@ -349,12 +287,14 @@ topEg = sorted(names1, key=lambda n: eg[names2.index(n)], reverse=True)[:10] | ... | @@ -349,12 +287,14 @@ topEg = sorted(names1, key=lambda n: eg[names2.index(n)], reverse=True)[:10] |
| 349 | printResult(topEg, egSorted, 5, 8, 10) | 287 | printResult(topEg, egSorted, 5, 8, 10) |
| 350 | 288 | ||
| 351 | avgOfBn = [] | 289 | avgOfBn = [] |
| 290 | +avgOfBnToObj = {} | ||
| 352 | totalBn = 0 | 291 | totalBn = 0 |
| 353 | topActors = topTmp.split(",") | 292 | topActors = topTmp.split(",") |
| 354 | for actor in topActors: | 293 | for actor in topActors: |
| 355 | i = names.index(actor) | 294 | i = names.index(actor) |
| 356 | totalBn += bn[i] | 295 | totalBn += bn[i] |
| 357 | -avgOfBn.append({"movie":"명량", "avgOfBn":totalBn / len(topActors)}) | 296 | +avgOfBn.append({"movie":"명량", "avgOfBn":round(totalBn / len(topActors), 5)}) |
| 297 | +avgOfBnToObj["명량"] = round(totalBn / len(topActors), 5) | ||
| 358 | 298 | ||
| 359 | for movie in data: | 299 | for movie in data: |
| 360 | totalBn = 0 | 300 | totalBn = 0 |
| ... | @@ -362,12 +302,14 @@ for movie in data: | ... | @@ -362,12 +302,14 @@ for movie in data: |
| 362 | for actor in actors: | 302 | for actor in actors: |
| 363 | i = names.index(actor) | 303 | i = names.index(actor) |
| 364 | totalBn += bn[i] | 304 | totalBn += bn[i] |
| 365 | - avgOfBn.append({"movie":movie, "avgOfBn":totalBn / len(actors)}) | 305 | + avgOfBn.append({"movie":movie, "avgOfBn":round(totalBn / len(actors), 5)}) |
| 306 | + avgOfBnToObj[movie] = round(totalBn / len(actors), 5) | ||
| 366 | 307 | ||
| 367 | print("\n<average of betweenness>") | 308 | print("\n<average of betweenness>") |
| 368 | avgOfBnSorted = sorted(avgOfBn, key=lambda n: n["avgOfBn"], reverse=True)[:10] | 309 | avgOfBnSorted = sorted(avgOfBn, key=lambda n: n["avgOfBn"], reverse=True)[:10] |
| 369 | for a in avgOfBnSorted: | 310 | for a in avgOfBnSorted: |
| 370 | - print(a["movie"], a["avgOfBn"]) | 311 | + text = replaceText(a["movie"]) |
| 312 | + print(a["movie"].rjust(30 - len(text)), str(a["avgOfBn"]).rjust(11)) | ||
| 371 | 313 | ||
| 372 | print("\n<total nodes>") | 314 | print("\n<total nodes>") |
| 373 | print(len(G.vs)) | 315 | print(len(G.vs)) |
| ... | @@ -388,4 +330,9 @@ out = plot(G, | ... | @@ -388,4 +330,9 @@ out = plot(G, |
| 388 | ) | 330 | ) |
| 389 | out.save("test.png") | 331 | out.save("test.png") |
| 390 | 332 | ||
| 391 | -#C:\Users\ghdms\2014104137\소스코드\centrality.py | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 333 | +x, y = [], [] | ||
| 334 | +for movie in avgOfBnToObj: | ||
| 335 | + x.append(avgOfBnToObj[movie]) | ||
| 336 | + y.append(salesPerScreensToObj[movie]) | ||
| 337 | +plt.scatter(x, y) | ||
| 338 | +plt.show() | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
진행보고서/최종보고서.docx
0 → 100644
No preview for this file type
-
Please register or login to post a comment