Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

ClusterStats.qmd 3.4 KB

You have to be logged in to leave a comment. Sign In
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
  1. ---
  2. title: Book Clustering Statistics
  3. jupyter:
  4. jupytext:
  5. text_representation:
  6. extension: .qmd
  7. format_name: quarto
  8. format_version: '1.0'
  9. jupytext_version: 1.14.7
  10. kernelspec:
  11. display_name: R (IRkernel)
  12. language: R
  13. name: ir
  14. ---
  15. This notebook provides statistics on the results of our book clustering.
  16. ## Setup
  17. ```{r}
  18. library(tidyverse, warn.conflicts=FALSE)
  19. library(arrow, warn.conflicts=FALSE)
  20. ```
  21. I want to use `theme_minimal()` by default:
  22. ```{r}
  23. theme_set(theme_minimal())
  24. ```
  25. And default image sizes aren't great:
  26. ```{r}
  27. options(repr.plot.width = 7,
  28. repr.plot.height = 4)
  29. ```
  30. ## Load Data
  31. Let's start by getting our clusters and their statistics:
  32. ```{r}
  33. clusters = read_parquet("book-links/cluster-stats.parquet", as_data_frame=FALSE)
  34. glimpse(clusters)
  35. ```
  36. Describe the count columns for basic descriptive stats:
  37. ```{r}
  38. clusters %>%
  39. select(-cluster) %>%
  40. collect() %>%
  41. summary()
  42. ```
  43. 75% of clusters only contain 2 ISBNs (probably -10 and -13) and one book. OpenLibrary also contributes to the largest number of clusters.
  44. ## Clusters per Source
  45. How many clusters are connected to each source?
  46. ```{r}
  47. src_counts = clusters %>%
  48. summarize(across(-cluster, ~ sum(.x > 0))) %>%
  49. collect() %>%
  50. pivot_longer(everything(), names_to="source", values_to="count")
  51. src_counts
  52. ```
  53. ```{r}
  54. ggplot(src_counts, aes(y=source, x=count)) +
  55. geom_bar(stat='identity')
  56. ```
  57. ## Distributions
  58. Let's look at the distributions of cluster sizes. Let's first compute histograms
  59. of the number of records per cluster for each cluster type.
  60. ```{r}
  61. size_dists = collect(clusters) %>%
  62. gather(rec_type, nrecs, -cluster, factor_key=TRUE) %>%
  63. summarize(count=n(), .by=c("rec_type", "nrecs"))
  64. head(size_dists)
  65. ```
  66. ```{r}
  67. ggplot(size_dists) +
  68. aes(x=nrecs, y=count, color=rec_type) +
  69. geom_point() +
  70. scale_x_log10() +
  71. scale_y_log10() +
  72. scale_color_brewer(type="qual", palette="Dark2") +
  73. xlab("# of Records") +
  74. xlab("# of Clusters") +
  75. ggtitle("Distribution of cluster counts")
  76. ```
  77. Looks mostly fine - we expect a lot of power laws - but the number of clusters with merged GoodReads works is concerning.
  78. ## GoodReads Work Merging
  79. What's going on with these clusters? Let's take a peek at them.
  80. ```{r}
  81. gr_big = clusters %>%
  82. filter(n_gr_works > 1) %>%
  83. arrange(desc(n_gr_works))
  84. gr_big %>% glimpse()
  85. ```
  86. We have a lot of these clusters. What fraction of the GoodReads-affected clusters is this?
  87. ```{r}
  88. nrow(gr_big) / sum(!is.na(clusters$n_gr_books))
  89. ```
  90. Less than 1%. Not bad, but let's look at these largest clusters.
  91. ```{r}
  92. gr_big %>% head() %>% collect()
  93. ```
  94. ## Large Cluster Debugging
  95. We have some pretty big clusters:
  96. ```{r}
  97. big = clusters %>% slice_max(n_nodes, n=5, with_ties=FALSE) %>%
  98. collect()
  99. big
  100. ```
  101. What is up with this? We should figure out what went wrong, if we can. What are its ISBNs?
  102. ```{r}
  103. isbns = read_parquet('book-links/all-isbns.parquet', as_data_frame=FALSE)
  104. glimpse(isbns)
  105. ```
  106. ```{r}
  107. links = read_parquet("book-links/isbn-clusters.parquet", as_data_frame=FALSE) %>%
  108. select(isbn_id, cluster)
  109. glimpse(links)
  110. ```
  111. Now let's look up data for the largest cluster.
  112. ```{r}
  113. big_id = big$cluster[1]
  114. big_id
  115. ```
  116. ```{r}
  117. bl = links %>% filter(cluster == big_id)
  118. bl = semi_join(isbns, bl) %>% arrange(isbn)
  119. bl %>% glimpse()
  120. ```
  121. What are the things with the highest record count?
  122. ```{r}
  123. bl %>% collect() %>% rowwise() %>% mutate(
  124. btot = sum(c_across(!starts_with("isbn")))
  125. ) %>% slice_max(btot, n=20)
  126. ```
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...