forked from brandomr/document_cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
film_cluster.html
747 lines (676 loc) · 17.1 KB
/
film_cluster.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
<html>
<head>
<meta charset="utf-8">
<title>Top 100 Films</title>
<link rel="stylesheet" type="text/css" href="brandonrose_doc.css">
<script type="text/javascript" src="d3/d3.v3.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48594970-1', 'brandonrose.org');
ga('send', 'pageview');
</script>
</head>
<style>
div {
font-family: "Helvetica Neue", Helvetica, sans-serif;
}
g.mpld3-xaxis, g.mpld3-yaxis {
display: none; }
svg.mpld3-figure {
margin-left: -200px;
}
#legend {
margin-top: -35px;
}
</style>
<body>
<header>
<a href="http://brandonrose.org">Home</a>
</header>
<div class= "main">
<h1>Top 100 Films of all Time</h1>
<div id="fig_el290745801570086793125459"></div>
<script type="text/javascript" src="cluster_script.js"></script>
<div id="legend"></div>
<div id="narrative">
<p>
How can you learn about the underlying structure of documents in a way that is informative and intuitive? This basic
motivating question led me on a journey to visualize and cluster documents in a two-dimensional space. What you see
above is an output of an analytical pipeline that begin by gathering synopses on the top 100 films of all time and ended by
analyzing the latent topics within each document. In between I ran significant manipulations on these synopses (tokenization, stemming),
transformed them into a vector space model (tf-idf), and clustered them into groups (k-means). You can learn all about how
I did this with my detailed guide to <a href="http://www.brandonrose.org/clustering">Document Clustering with Python</a>. But first, what did I learn?
</p>
</br>
<h3>
A bit of background
</h3>
<p>
I obtained a list of the top 100 films of all time from an IMDB user list called
<a href='http://www.imdb.com/list/ls055592025/'>
Top 100 Greatest Movies of All Time (The Ultimate List)
by ChrisWalczyk55.
</a> ChrisWalczyk55 claims that "My lists are <strong>not</strong> based on my own personal favorites;
they are based on the true greatness and/or sucess of the person, place, or thing
being ranked." Ok, sure, whatever. Using this list and it's ordinal rankings,
combined with synopses gathered from IMDB and Wikipedia, I was able to separate the films into 5 clusters.
Why 5? Clustering is more art than science and if I selected 20 clusters they would be too narrow to allow
me to draw any generalizations. If I picked 2 or 3 clusters they would be too broad. 5 to 8 generated a good fit,
but I chose 5 clusters since this led to the best intuition.
</p>
</br>
<h3>
Understanding the visualization
</h3>
<p>
The visualization at the top of the page is a 2-dimensional scatterplot of the cosine distance of each of the movies
(colored by cluster). The dimensions (X and Y) do not actually have labels. The way to interpret the the scatterplot is
by examining the location of one film, relative to others, in this 2-d space. Proximity in this space equates to similarity as
determined by a multi-dimensional scaling of the cosine distance (1 minus cosine similarity) between synopses contained
within the term frequency-inverse document frequency (tf-idf) matrix. That was probably confusing and I plan to explain it in a
more detailed write up of my methodology, but the basic intuition is that, based on the collected synopses, each film is plotted in relation
to its similarity to all other films contained in the plot. You might find some wierd relationships in this plot: keep in mind
that similarity was measured based on the words found in the film synopses. If the film synopses were written poorly or very short
the results were most certainly impacted. Garbage in, garbage out. Mostly I was interested in exploring the methodology.
</p>
</br>
<h3>
Scoring the clusters
</h3>
<p>
Based on the outcome of the clustering, I used the average rank from the IMDB list to score the clusters (lower is better).
</p>
<table>
<tr>
<th>Rank</th>
<th>Cluster</th>
<th>Score</th>
<th>Count</th>
</tr>
<tr>
<td style="background-color:#66a61e">1</td>
<td>Killed, soldiers, captain</td>
<td>43.7</td>
<td>26</td>
</tr>
<tr>
<td style="background-color:#1b9e77">2</td>
<td>Family, home, war</td>
<td>47.2</td>
<td>25</td>
</tr>
<tr>
<td style="background-color:#7570b3">3</td>
<td>Father, New York, brothers</td>
<td>49.4</td>
<td>21</td>
</tr>
<tr>
<td style="background-color:#e7298a">4</td>
<td>Dance, singing, love</td>
<td>54.5</td>
<td>12</td>
</tr>
<tr>
<td style="background-color:#d95f02">5</td>
<td>Police, killed, murders</td>
<td>58.8</td>
<td>16</td>
</tr>
</table>
<p>
You can see that the war movies scored the best. The basic war epic cluster was at the top, followed
closely by family/home with some war mixed in. Family and "New York" or perhaps just cities follows the war grouping.
Dancing, singing, love is beats out the crime-ish flicks which, in the scheme of the top 100 movies, tend towards the bottom.
This despite the dominance of the Godfather films.
</p>
<table border="1" class="dataframe">
<thead>
<tr>
<th colspan="2" style="background-color:#66a61e">Killed, soldiers, captain</th>
</tr>
<tr>
<th>Rank</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> 2</td>
<td> The Shawshank Redemption</td>
</tr>
<tr>
<td> 11</td>
<td> Lawrence of Arabia</td>
</tr>
<tr>
<td> 18</td>
<td> The Sound of Music</td>
</tr>
<tr>
<td> 20</td>
<td> Star Wars</td>
</tr>
<tr>
<td> 22</td>
<td> 2001: A Space Odyssey</td>
</tr>
<tr>
<td> 25</td>
<td> The Bridge on the River Kwai</td>
</tr>
<tr>
<td> 30</td>
<td> Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb</td>
</tr>
<tr>
<td> 32</td>
<td> Apocalypse Now</td>
</tr>
<tr>
<td> 34</td>
<td> The Lord of the Rings: The Return of the King</td>
</tr>
<tr>
<td> 35</td>
<td> Gladiator</td>
</tr>
<tr>
<td> 36</td>
<td> From Here to Eternity</td>
</tr>
<tr>
<td> 37</td>
<td> Saving Private Ryan</td>
</tr>
<tr>
<td> 38</td>
<td> Unforgiven</td>
</tr>
<tr>
<td> 39</td>
<td> Raiders of the Lost Ark</td>
</tr>
<tr>
<td> 49</td>
<td> Patton</td>
</tr>
<tr>
<td> 50</td>
<td> Jaws</td>
</tr>
<tr>
<td> 53</td>
<td> Butch Cassidy and the Sundance Kid</td>
</tr>
<tr>
<td> 54</td>
<td> The Treasure of the Sierra Madre</td>
</tr>
<tr>
<td> 56</td>
<td> Platoon</td>
</tr>
<tr>
<td> 58</td>
<td> Dances with Wolves</td>
</tr>
<tr>
<td> 62</td>
<td> The Deer Hunter</td>
</tr>
<tr>
<td> 63</td>
<td> All Quiet on the Western Front</td>
</tr>
<tr>
<td> 80</td>
<td> Shane</td>
</tr>
<tr>
<td> 81</td>
<td> The Green Mile</td>
</tr>
<tr>
<td> 88</td>
<td> The African Queen</td>
</tr>
<tr>
<td> 90</td>
<td> Mutiny on the Bounty</td>
</tr>
</tbody>
</table>
<table border="1" class="dataframe">
<thead>
<tr>
<th colspan="2" style="background-color:#1b9e77">Family, home, war</th>
</tr>
<tr>
<th>Rank</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> 3</td>
<td> Schindler's List</td>
</tr>
<tr>
<td> 6</td>
<td> One Flew Over the Cuckoo's Nest</td>
</tr>
<tr>
<td> 7</td>
<td> Gone with the Wind</td>
</tr>
<tr>
<td> 9</td>
<td> The Wizard of Oz</td>
</tr>
<tr>
<td> 10</td>
<td> Titanic</td>
</tr>
<tr>
<td> 17</td>
<td> Forrest Gump</td>
</tr>
<tr>
<td> 21</td>
<td> E.T. the Extra-Terrestrial</td>
</tr>
<tr>
<td> 23</td>
<td> The Silence of the Lambs</td>
</tr>
<tr>
<td> 33</td>
<td> Gandhi</td>
</tr>
<tr>
<td> 41</td>
<td> A Streetcar Named Desire</td>
</tr>
<tr>
<td> 45</td>
<td> The Best Years of Our Lives</td>
</tr>
<tr>
<td> 46</td>
<td> My Fair Lady</td>
</tr>
<tr>
<td> 47</td>
<td> Ben-Hur</td>
</tr>
<tr>
<td> 48</td>
<td> Doctor Zhivago</td>
</tr>
<tr>
<td> 59</td>
<td> The Pianist</td>
</tr>
<tr>
<td> 61</td>
<td> The Exorcist</td>
</tr>
<tr>
<td> 73</td>
<td> Out of Africa</td>
</tr>
<tr>
<td> 74</td>
<td> Good Will Hunting</td>
</tr>
<tr>
<td> 75</td>
<td> Terms of Endearment</td>
</tr>
<tr>
<td> 78</td>
<td> Giant</td>
</tr>
<tr>
<td> 79</td>
<td> The Grapes of Wrath</td>
</tr>
<tr>
<td> 82</td>
<td> Close Encounters of the Third Kind</td>
</tr>
<tr>
<td> 85</td>
<td> The Graduate</td>
</tr>
<tr>
<td> 89</td>
<td> Stagecoach</td>
</tr>
<tr>
<td> 94</td>
<td> Wuthering Heights</td>
</tr>
</tbody>
</table>
</br>
</br>
</br>
<table border="1" class="dataframe">
<thead>
<tr>
<th colspan="2" style="background-color:#7570b3">Father, New York, brothers</th>
</tr>
<tr>
<th>Rank</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> 1</td>
<td> The Godfather</td>
</tr>
<tr>
<td> 4</td>
<td> Raging Bull</td>
</tr>
<tr>
<td> 8</td>
<td> Citizen Kane</td>
</tr>
<tr>
<td> 12</td>
<td> The Godfather: Part II</td>
</tr>
<tr>
<td> 16</td>
<td> On the Waterfront</td>
</tr>
<tr>
<td> 29</td>
<td> 12 Angry Men</td>
</tr>
<tr>
<td> 40</td>
<td> Rocky</td>
</tr>
<tr>
<td> 43</td>
<td> To Kill a Mockingbird</td>
</tr>
<tr>
<td> 51</td>
<td> Braveheart</td>
</tr>
<tr>
<td> 52</td>
<td> The Good, the Bad and the Ugly</td>
</tr>
<tr>
<td> 55</td>
<td> The Apartment</td>
</tr>
<tr>
<td> 60</td>
<td> Goodfellas</td>
</tr>
<tr>
<td> 65</td>
<td> City Lights</td>
</tr>
<tr>
<td> 67</td>
<td> It Happened One Night</td>
</tr>
<tr>
<td> 69</td>
<td> Midnight Cowboy</td>
</tr>
<tr>
<td> 70</td>
<td> Mr. Smith Goes to Washington</td>
</tr>
<tr>
<td> 71</td>
<td> Rain Man</td>
</tr>
<tr>
<td> 72</td>
<td> Annie Hall</td>
</tr>
<tr>
<td> 83</td>
<td> Network</td>
</tr>
<tr>
<td> 93</td>
<td> Taxi Driver</td>
</tr>
<tr>
<td> 97</td>
<td> Rear Window</td>
</tr>
</tbody>
</table>
<table border="1" class="dataframe">
<thead>
<tr>
<th colspan="2" style="background-color:#e7298a">Dance, singing, love</th>
</tr>
<tr>
<th>Rank</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> 19</td>
<td> West Side Story</td>
</tr>
<tr>
<td> 26</td>
<td> Singin' in the Rain</td>
</tr>
<tr>
<td> 27</td>
<td> It's a Wonderful Life</td>
</tr>
<tr>
<td> 28</td>
<td> Some Like It Hot</td>
</tr>
<tr>
<td> 42</td>
<td> The Philadelphia Story</td>
</tr>
<tr>
<td> 44</td>
<td> An American in Paris</td>
</tr>
<tr>
<td> 66</td>
<td> The King's Speech</td>
</tr>
<tr>
<td> 68</td>
<td> A Place in the Sun</td>
</tr>
<tr>
<td> 76</td>
<td> Tootsie</td>
</tr>
<tr>
<td> 84</td>
<td> Nashville</td>
</tr>
<tr>
<td> 86</td>
<td> American Graffiti</td>
</tr>
<tr>
<td> 100</td>
<td> Yankee Doodle Dandy</td>
</tr>
</tbody>
</table>
</br>
</br>
</br>
<table border="1" class="dataframe">
<thead>
<tr>
<th colspan="2" style="background-color:#d95f02">Police, killed, murders</th>
</tr>
<tr">
<th>Rank</th>
<th>Title</th>
</tr>
</thead>
<tbody>
<tr>
<td> 5</td>
<td> Casablanca</td>
</tr>
<tr>
<td> 13</td>
<td> Psycho</td>
</tr>
<tr>
<td> 14</td>
<td> Sunset Blvd.</td>
</tr>
<tr>
<td> 15</td>
<td> Vertigo</td>
</tr>
<tr>
<td> 24</td>
<td> Chinatown</td>
</tr>
<tr>
<td> 31</td>
<td> Amadeus</td>
</tr>
<tr>
<td> 57</td>
<td> High Noon</td>
</tr>
<tr>
<td> 64</td>
<td> The French Connection</td>
</tr>
<tr>
<td> 77</td>
<td> Fargo</td>
</tr>
<tr>
<td> 87</td>
<td> Pulp Fiction</td>
</tr>
<tr>
<td> 91</td>
<td> The Maltese Falcon</td>
</tr>
<tr>
<td> 92</td>
<td> A Clockwork Orange</td>
</tr>
<tr>
<td> 95</td>
<td> Double Indemnity</td>
</tr>
<tr>
<td> 96</td>
<td> Rebel Without a Cause</td>
</tr>
<tr>
<td> 98</td>
<td> The Third Man</td>
</tr>
<tr>
<td> 99</td>
<td> North by Northwest</td>
</tr>
</tbody>
</table>
</br>
</br>
</br>
</div>
<script type="text/javascript">
//Make an SVG Container
var svgContainer = d3.select("#legend").append("svg")
.attr("width", 900)
.attr("height", 50);
//Draw the Circle
var circle = svgContainer.append("circle")
.attr("cx", 10)
.attr("cy", 25)
.attr("r", 7)
.style("fill", "#1b9e77")
.style("stroke", "none")
.style("stroke-width", "6");
var text = svgContainer.append("text")
.text("Family, home, war")
.attr("x", 20)
.attr("y", 30)
.attr("fill", "black")
.attr("font-size", 12);
var circle = svgContainer.append("circle")
.attr("cx", 155)
.attr("cy", 25)
.attr("r", 7)
.style("fill", "#d95f02")
.style("stroke", "none")
.style("stroke-width", "6");
var text = svgContainer.append("text")
.text("Police, killed, murders")
.attr("x", 165)
.attr("y", 30)
.attr("fill", "black")
.attr("font-size", 12);
var circle = svgContainer.append("circle")
.attr("cx", 315)
.attr("cy", 25)
.attr("r", 7)
.style("fill", "#7570b3")
.style("stroke", "none")
.style("stroke-width", "6");
var text = svgContainer.append("text")
.text("Father, New York, brothers")
.attr("x", 325)
.attr("y", 30)
.attr("fill", "black")
.attr("font-size", 12);
var circle = svgContainer.append("circle")
.attr("cx", 505)
.attr("cy", 25)
.attr("r", 7)
.style("fill", "#e7298a")
.style("stroke", "none")
.style("stroke-width", "6");
var text = svgContainer.append("text")
.text("Dance, singing, love")
.attr("x", 515)
.attr("y", 30)
.attr("fill", "black")
.attr("font-size", 12);
var circle = svgContainer.append("circle")
.attr("cx", 650)
.attr("cy", 25)
.attr("r", 7)
.style("fill", "#66a61e")
.style("stroke", "none")
var text = svgContainer.append("text")
.text("Killed, soldiers, captain")
.attr("x", 660)
.attr("y", 30)
.attr("fill", "black")
.attr("font-size", 12);
</script>
</body></html>