SeeTrees¤
The seetrees module provides stylometric analysis and visualization tools for document-term-style data. It is especially useful for comparing document profiles, computing distance matrices, visualizing document relationships, and exploring feature importance across clusters.
SeeTrees is adapted from the R 'see' package by Artjoms Šeļa.
The SeeTrees Class¤
SeeTrees
pydantic-model
¤
Bases: BaseModel
SeeTrees class for stylometric analysis and visualization.
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
distance_table(DataFrame) -
dtm(DTM | None) -
features(list[str]) -
frequencies(DataFrame) -
labels(list[str]) -
stylo_res(dict | None) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/__init__.py
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 | |
distance_table: pd.DataFrame
pydantic-field
¤
Optional distance matrix.
dtm: DTM | None = None
pydantic-field
¤
Optional Lexos DTM to initialize frequencies from.
features: list[str]
pydantic-field
¤
Optional list of feature names.
frequencies: pd.DataFrame
pydantic-field
¤
Optional frequency table.
labels: list[str]
pydantic-field
¤
Document labels derived from the distance matrix or frequency table.
stylo_res: dict | None = None
pydantic-field
¤
Optional dictionary containing stylo output keys such as frequencies, distance_table, and features.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib Figure object for plotting.
__init__(**data)
¤
Initialize a SeeTrees instance.
Source code in lexos/cluster/seetrees/__init__.py
get_difference_plot(source_text: str, target_text: str, top_diff: int = 10, max_rank: int = 100, title: str | None = None, base_color: str = 'gray', highlight_color: str = 'red') -> DifferencePlot
¤
Get a difference plot for two documents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_text
|
str
|
The reference text label. |
required |
target_text
|
str
|
The text label to compare. |
required |
top_diff
|
int
|
Number of top differing features to label. |
10
|
max_rank
|
int
|
Maximum feature frequency rank to display. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
DifferencePlot |
DifferencePlot
|
An object for visualizing the difference in z-scores. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the frequency table is empty or either label is missing. |
Source code in lexos/cluster/seetrees/__init__.py
get_overlay_plot(source_text: str, target_text: str, top_diff: int = 10, max_rank: int = 100, title: str | None = None, source_color: str = '#ff9999', target_color: str = '#99c2ff') -> OverlayPlot
¤
Compare two documents using overlay plotting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_text
|
str
|
The reference text label. |
required |
target_text
|
str
|
The text label to compare. |
required |
top_diff
|
int
|
Number of top differing features to label. |
10
|
max_rank
|
int
|
Maximum feature frequency rank to display. |
100
|
Returns:
| Name | Type | Description |
|---|---|---|
OverlayPlot |
OverlayPlot
|
An OverlayPlot object for the specified documents. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the frequency table is empty or either label is missing. |
Source code in lexos/cluster/seetrees/__init__.py
compute_distances(metric: str = 'delta') -> pd.DataFrame
¤
Compute a stylometric distance matrix from frequency data.
Supports multiple stylometric metrics including Burrows' Delta, Eder's Delta, and cosine variants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
str
|
Distance metric to compute. Valid values are:
|
'delta'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Pairwise distance matrix indexed by the original labels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the frequency table is empty or the metric is unknown. |
Source code in lexos/cluster/seetrees/__init__.py
get_density_plot(group: bool = True, author: str | None = None, pattern: str = '^.*?(?=[_\\s-]|\\d)', title: str | None = None, palette: dict[str, str] | None = None, color: str = '#cccccc', left: float = 0.14, right: float = 0.95, top: float = 0.92, bottom: float = 0.15) -> DensityPlot
¤
Return a DensityPlot object for viewing distances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
bool
|
Whether to group distances by the same author/class. |
True
|
author
|
str | None
|
Specific author/class to highlight in the plot. |
None
|
pattern
|
str
|
Regex pattern to extract author classes from labels. |
'^.*?(?=[_\\s-]|\\d)'
|
title
|
str | None
|
Optional title for the density plot. |
None
|
palette
|
dict[str, str] | None
|
Optional color palette for grouped density curves. |
None
|
color
|
str
|
Fill color for ungrouped density plots. |
'#cccccc'
|
left
|
float
|
Left margin for the figure layout. |
0.14
|
right
|
float
|
Right margin for the figure layout. |
0.95
|
top
|
float
|
Top margin for the figure layout. |
0.92
|
bottom
|
float
|
Bottom margin for the figure layout. |
0.15
|
Returns:
| Name | Type | Description |
|---|---|---|
DensityPlot |
DensityPlot
|
Configured DensityPlot object. |
Source code in lexos/cluster/seetrees/__init__.py
get_mds_plot(group: bool = True, author: str | None = None, pattern: str = '^.*?(?=[_\\s-]|\\d)', title: str | None = None, left: float = 0.12, right: float = 0.96, top: float = 0.94, bottom: float = 0.12) -> MDS
¤
Return an MDS object for viewing distances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
bool
|
Whether to group distances by the same author/class. |
True
|
author
|
str | None
|
Specific author/class to highlight in the plot. |
None
|
pattern
|
str
|
Regex pattern to extract author classes from labels. |
'^.*?(?=[_\\s-]|\\d)'
|
title
|
str | None
|
Optional title for the MDS plot. |
None
|
left
|
float
|
Left margin for the figure layout. |
0.12
|
right
|
float
|
Right margin for the figure layout. |
0.96
|
top
|
float
|
Top margin for the figure layout. |
0.94
|
bottom
|
float
|
Bottom margin for the figure layout. |
0.12
|
Returns:
| Name | Type | Description |
|---|---|---|
MDS |
MDS
|
Configured MDS object. |
Source code in lexos/cluster/seetrees/__init__.py
get_pca_plot(author: str | None = None, pattern: str = '^.*?(?=[_\\s-]|\\d)', title: str | None = None, left: float = 0.12, right: float = 0.96, top: float = 0.94, bottom: float = 0.12) -> PCA
¤
Return a PCA object for viewing distances.
Source code in lexos/cluster/seetrees/__init__.py
get_feature_summary(target_text: str, top: int = 20)
¤
Return the most distinctive features for a target text.
Source code in lexos/cluster/seetrees/__init__.py
get_tree(k: int = 2, method: str = 'ward', title: str | None = None, top_n_words: int = 10, orientation: str = 'right', label_buffer: float = 0.0, outline_y_pad: float = 0.3, outline_axis_y_pad: float = 0.1, outline_tip_pad_ratio: float = 0.002, outline_root_pad_ratio: float = 0.1) -> Tree
¤
Return a Tree object for further customization or saving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k
|
int
|
Number of clusters to display in the dendrogram. |
2
|
method
|
str
|
Linkage method for hierarchical clustering. |
'ward'
|
title
|
str | None
|
Optional title for the dendrogram. |
None
|
top_n_words
|
int
|
Number of top words to display for each cluster. |
10
|
orientation
|
str
|
Dendrogram orientation. One of 'left', 'right', 'top', or 'bottom'. |
'right'
|
label_buffer
|
float
|
Extra subplot margin reserved for leaf labels on the active label side. |
0.0
|
outline_y_pad
|
float
|
Vertical padding for cluster outlines. |
0.3
|
outline_axis_y_pad
|
float
|
Additional vertical padding for the axis. |
0.1
|
outline_tip_pad_ratio
|
float
|
Horizontal padding ratio for dendrogram tips. |
0.002
|
outline_root_pad_ratio
|
float
|
Horizontal padding ratio for dendrogram root. |
0.1
|
Source code in lexos/cluster/seetrees/__init__.py
get_feature_score_plot(target_text: str, top: int = 20, title: str | None = None, positive_color: str = '#f6c1cc', negative_color: str = '#b9dff1', guide_color: str = '#c9ced6', zero_line_color: str = 'red', height: int = 600, width: int = 800) -> DistinctiveFeaturePlot
¤
Return a DistinctiveFeaturePlot object for top feature score visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_text
|
str
|
The text to analyze for distinctive features. |
required |
top
|
int
|
Number of top features to display. |
20
|
title
|
str | None
|
Optional chart title. |
None
|
positive_color
|
str
|
Bar color for positive z-scores. |
'#f6c1cc'
|
negative_color
|
str
|
Bar color for negative z-scores. |
'#b9dff1'
|
guide_color
|
str
|
Dotted guide-line color for non-zero SD lines. |
'#c9ced6'
|
zero_line_color
|
str
|
Dotted guide-line color for the zero SD line. |
'red'
|
height
|
int
|
Figure height in pixels. |
600
|
width
|
int
|
Figure width in pixels. |
800
|
Returns:
| Name | Type | Description |
|---|---|---|
DistinctiveFeaturePlot |
DistinctiveFeaturePlot
|
Configured Plotly plot object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the frequency table is empty or if the target text is not found. |
Source code in lexos/cluster/seetrees/__init__.py
members: true
The comparison Classes¤
ComparisonPlot
pydantic-model
¤
Bases: BaseModel
Base class for stylometric comparison plots.
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
frequencies(DataFrame) -
source_text(str) -
target_text(str) -
top_diff(int) -
max_rank(int) -
title(str | None) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/comparison.py
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
source_text: str = ''
pydantic-field
¤
Label for the source text.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top_diff: int = 10
pydantic-field
¤
Number of top differences to highlight.
max_rank: int = 100
pydantic-field
¤
Limit for the number of features to rank.
title: str | None = None
pydantic-field
¤
Optional title for the comparison plot.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure object.
members: true
DifferencePlot
pydantic-model
¤
Bases: ComparisonPlot
Plot the z-score difference between two texts.
Fields:
-
base_color(str) -
highlight_color(str) -
frequencies(DataFrame) -
source_text(str) -
target_text(str) -
top_diff(int) -
max_rank(int) -
title(str | None) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/comparison.py
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 | |
base_color: str = 'gray'
pydantic-field
¤
Color used for non-highlighted difference bars.
highlight_color: str = 'red'
pydantic-field
¤
Color used for highlighted difference bars.
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
source_text: str = ''
pydantic-field
¤
Label for the source text.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top_diff: int = 10
pydantic-field
¤
Number of top differences to highlight.
max_rank: int = 100
pydantic-field
¤
Limit for the number of features to rank.
title: str | None = None
pydantic-field
¤
Optional title for the comparison plot.
__init__(**data)
¤
plot_difference() -> plt.Figure
¤
Plot the difference in z-scores between the source and target texts.
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure: Matplotlib figure containing the difference plot. |
Source code in lexos/cluster/seetrees/comparison.py
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 | |
members: true
OverlayPlot
pydantic-model
¤
Bases: ComparisonPlot
Plot the stylometric overlay of two texts.
Fields:
-
source_color(str) -
target_color(str) -
frequencies(DataFrame) -
source_text(str) -
target_text(str) -
top_diff(int) -
max_rank(int) -
title(str | None) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/comparison.py
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 | |
source_color: str = '#ff9999'
pydantic-field
¤
Color used for the source text overlay line.
target_color: str = '#99c2ff'
pydantic-field
¤
Color used for the target text overlay line.
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
source_text: str = ''
pydantic-field
¤
Label for the source text.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top_diff: int = 10
pydantic-field
¤
Number of top differences to highlight.
max_rank: int = 100
pydantic-field
¤
Limit for the number of features to rank.
title: str | None = None
pydantic-field
¤
Optional title for the comparison plot.
__init__(**data)
¤
plot_overlay() -> plt.Figure
¤
Plot the stylometric overlays of the source and target texts.
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure: Matplotlib figure containing the overlay plot. |
Source code in lexos/cluster/seetrees/comparison.py
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 | |
members: true
The density_plot Class¤
DensityPlot
pydantic-model
¤
Bases: BaseModel
Encapsulate view_distances plotting logic as a density plot.
Config:
arbitrary_types_allowed:True
Fields:
-
distance_table(DataFrame) -
labels(list[str]) -
frequencies(DataFrame) -
author(str | None) -
group(bool) -
pattern(str) -
title(str | None) -
palette(dict[str, str] | None) -
color(str) -
left(float) -
show_on_init(bool) -
right(float) -
top(float) -
bottom(float) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/density_plot.py
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 | |
distance_table: pd.DataFrame
pydantic-field
¤
Distance table containing pairwise distances between items.
author: str | None = None
pydantic-field
¤
Specific author to highlight in the plot.
group: bool = True
pydantic-field
¤
Whether to group distances by same author.
pattern: str = '^.*?(?=[_\\s-]|\\d)'
pydantic-field
¤
Regular expression pattern to extract author classes from labels.
title: str | None = None
pydantic-field
¤
Optional title for the density plot.
palette: dict[str, str] | None = None
pydantic-field
¤
Optional color palette for grouped density curves. Keys should be 'True' and 'False'.
color: str = '#cccccc'
pydantic-field
¤
Fill color for ungrouped density plots.
left: float = 0.14
pydantic-field
¤
Left margin for the figure layout.
show_on_init: bool = False
pydantic-field
¤
Whether to display the plot immediately when the object is created.
right: float = 0.95
pydantic-field
¤
Right margin for the figure layout.
top: float = 0.92
pydantic-field
¤
Top margin for the figure layout.
bottom: float = 0.15
pydantic-field
¤
Bottom margin for the figure layout.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure containing the density plot.
__init__(**data)
¤
Initialize the DensityPlot object.
Source code in lexos/cluster/seetrees/density_plot.py
plot_density()
¤
Plot the density of distances, optionally grouped by author.
Source code in lexos/cluster/seetrees/density_plot.py
members: true
The projection_plot Classes¤
ProjectionPlot
pydantic-model
¤
Bases: BaseModel
Base class for projection plots with lazy figure creation.
Config:
arbitrary_types_allowed:True
Fields:
-
author(str | None) -
pattern(str) -
distance_table(DataFrame) -
frequencies(DataFrame) -
labels(list[str]) -
title(str | None) -
left(float) -
right(float) -
top(float) -
bottom(float) -
show_on_init(bool) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/projection_plot.py
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 | |
author: str | None = None
pydantic-field
¤
Specific author to highlight in the plot.
pattern: str = '^.*?(?=[_\\s-]|\\d)'
pydantic-field
¤
Regular expression pattern to extract author classes from labels.
distance_table: pd.DataFrame
pydantic-field
¤
Distance table containing pairwise distances between items.
title: str | None = None
pydantic-field
¤
Optional title for the projection plot.
left: float = 0.12
pydantic-field
¤
Left margin for the figure layout.
right: float = 0.96
pydantic-field
¤
Right margin for the figure layout.
top: float = 0.94
pydantic-field
¤
Top margin for the figure layout.
bottom: float = 0.12
pydantic-field
¤
Bottom margin for the figure layout.
show_on_init: bool = False
pydantic-field
¤
Whether to display the plot immediately when the object is created.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure containing the projection plot.
__init__(**data)
¤
Initialize the ProjectionPlot object.
Source code in lexos/cluster/seetrees/projection_plot.py
plot_projection() -> None
¤
Compute coordinates, create the figure, plot the base scatter, and finalize the figure.
Source code in lexos/cluster/seetrees/projection_plot.py
members: true
MDS
pydantic-model
¤
Bases: ProjectionPlot
Encapsulate view_distances plotting logic as an MDS projection plot.
Fields:
-
author(str | None) -
pattern(str) -
distance_table(DataFrame) -
frequencies(DataFrame) -
labels(list[str]) -
title(str | None) -
left(float) -
right(float) -
top(float) -
bottom(float) -
show_on_init(bool) -
fig(Figure | None) -
metric(str | None) -
random_state(int)
Source code in lexos/cluster/seetrees/projection_plot.py
metric: str | None = None
pydantic-field
¤
Distance metric for MDS.
random_state: int = 42
pydantic-field
¤
Random seed for reproducibility.
author: str | None = None
pydantic-field
¤
Specific author to highlight in the plot.
pattern: str = '^.*?(?=[_\\s-]|\\d)'
pydantic-field
¤
Regular expression pattern to extract author classes from labels.
distance_table: pd.DataFrame
pydantic-field
¤
Distance table containing pairwise distances between items.
title: str | None = None
pydantic-field
¤
Optional title for the projection plot.
left: float = 0.12
pydantic-field
¤
Left margin for the figure layout.
right: float = 0.96
pydantic-field
¤
Right margin for the figure layout.
top: float = 0.94
pydantic-field
¤
Top margin for the figure layout.
bottom: float = 0.12
pydantic-field
¤
Bottom margin for the figure layout.
show_on_init: bool = False
pydantic-field
¤
Whether to display the plot immediately when the object is created.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure containing the projection plot.
__init__(**data)
¤
Initialize the ProjectionPlot object.
Source code in lexos/cluster/seetrees/projection_plot.py
plot_projection() -> None
¤
Compute coordinates, create the figure, plot the base scatter, and finalize the figure.
Source code in lexos/cluster/seetrees/projection_plot.py
members: true
PCA
pydantic-model
¤
Bases: ProjectionPlot
Encapsulate view_distances plotting logic as a PCA projection plot.
Fields:
-
author(str | None) -
pattern(str) -
frequencies(DataFrame) -
labels(list[str]) -
title(str | None) -
left(float) -
right(float) -
top(float) -
bottom(float) -
show_on_init(bool) -
fig(Figure | None) -
distance_table(DataFrame) -
random_state(int)
Source code in lexos/cluster/seetrees/projection_plot.py
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 | |
distance_table: pd.DataFrame
pydantic-field
¤
Optional distance table for compatibility; PCA uses frequencies.
random_state: int = 42
pydantic-field
¤
Random seed for reproducibility.
author: str | None = None
pydantic-field
¤
Specific author to highlight in the plot.
pattern: str = '^.*?(?=[_\\s-]|\\d)'
pydantic-field
¤
Regular expression pattern to extract author classes from labels.
title: str | None = None
pydantic-field
¤
Optional title for the projection plot.
left: float = 0.12
pydantic-field
¤
Left margin for the figure layout.
right: float = 0.96
pydantic-field
¤
Right margin for the figure layout.
top: float = 0.94
pydantic-field
¤
Top margin for the figure layout.
bottom: float = 0.12
pydantic-field
¤
Bottom margin for the figure layout.
show_on_init: bool = False
pydantic-field
¤
Whether to display the plot immediately when the object is created.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure containing the projection plot.
__init__(**data)
¤
Initialize the ProjectionPlot object.
Source code in lexos/cluster/seetrees/projection_plot.py
plot_projection() -> None
¤
Compute coordinates, create the figure, plot the base scatter, and finalize the figure.
Source code in lexos/cluster/seetrees/projection_plot.py
members: true
The tree Class¤
Tree
pydantic-model
¤
Bases: BaseModel
Render a stylometric dendrogram and cluster word summary.
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
labels(list[str]) -
distance_table(DataFrame) -
frequencies(DataFrame) -
title(str | None) -
show_on_init(bool) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/tree.py
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 | |
distance_table: pd.DataFrame
pydantic-field
¤
Pairwise distance table.
title: str | None = None
pydantic-field
¤
Optional title for the dendrogram.
show_on_init: bool = False
pydantic-field
¤
Whether to display the plot immediately when the object is created.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib figure containing the dendrogram plot.
__init__(**data)
¤
Initialize the Tree object.
Source code in lexos/cluster/seetrees/tree.py
plot_tree(k: int = 2, method: Literal['single', 'complete', 'average', 'weighted', 'centroid', 'median', 'ward'] = 'ward', top_n_words: int = 10, orientation: Literal['left', 'right', 'top', 'bottom'] = 'right', label_buffer: float = 0.0, outline_y_pad: float = 0.3, outline_axis_y_pad: float = 0.1, outline_tip_pad_ratio: float = 0.002, outline_root_pad_ratio: float = 0.1) -> plt.Figure
¤
Create the dendrogram figure without displaying it.
Source code in lexos/cluster/seetrees/tree.py
members: true
The zscores Classes¤
ZscorePlot
pydantic-model
¤
Bases: BaseModel
Render a ranked z-score bar chart for a target text.
The current SeeTrees class only creates DistinctiveFeaturePlot objects, since the plot can be quite cluttered. This class is provided as a basis for further development for users who prefer Matplotlib.
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
frequencies(DataFrame) -
target_text(str) -
top(int) -
title(str | None) -
positive_color(str) -
negative_color(str) -
guide_color(str) -
zero_line_color(str) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/zscores.py
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 | |
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top: int = 20
pydantic-field
¤
Number of features to display.
title: str | None = None
pydantic-field
¤
Optional plot title.
positive_color: str = '#f6c1cc'
pydantic-field
¤
Bar color for positive z-scores.
negative_color: str = '#b9dff1'
pydantic-field
¤
Bar color for negative z-scores.
guide_color: str = '#c9ced6'
pydantic-field
¤
Guide line color for non-zero SD lines.
zero_line_color: str = 'red'
pydantic-field
¤
Guide line color for the zero SD line.
fig: plt.Figure | None = None
pydantic-field
¤
Matplotlib Figure object for plotting.
plot() -> plt.Figure
¤
Render the z-score chart and return the figure.
Source code in lexos/cluster/seetrees/zscores.py
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 | |
members: true
DistinctiveFeaturePlot
pydantic-model
¤
Bases: BaseModel
Render a ranked z-score bar chart for a target text using Plotly.
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
frequencies(DataFrame) -
target_text(str) -
top(int) -
title(str | None) -
positive_color(str) -
negative_color(str) -
guide_color(str) -
zero_line_color(str) -
width(int) -
height(int) -
fig(Figure | None)
Source code in lexos/cluster/seetrees/zscores.py
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 | |
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top: int = 20
pydantic-field
¤
Number of features to display.
title: str | None = None
pydantic-field
¤
Optional plot title.
positive_color: str = '#f6c1cc'
pydantic-field
¤
Bar color for positive z-scores.
negative_color: str = '#b9dff1'
pydantic-field
¤
Bar color for negative z-scores.
guide_color: str = '#c9ced6'
pydantic-field
¤
Guide line color for non-zero SD lines.
zero_line_color: str = 'red'
pydantic-field
¤
Guide line color for the zero SD line.
width: int = 800
pydantic-field
¤
Figure width in pixels.
height: int = 600
pydantic-field
¤
Figure height in pixels.
fig: go.Figure | None = None
pydantic-field
¤
Plotly Figure object for plotting.
plot() -> go.Figure
¤
Render the z-score chart and return the Plotly figure.
Source code in lexos/cluster/seetrees/zscores.py
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 | |
show() -> None
¤
members: true
FeatureSummary
pydantic-model
¤
Bases: BaseModel
Encapsulate view_scores summary rendering.
Suggestions for improving the chart
- switch selection from raw z-score cutoff to rank-based or feature-importance ranking
- split positive and negative features into separate views instead of mixing both directions
- use a dot/lollipop plot rather than bars to reduce visual clutter when many values tie
- annotate only the most distinctive features and omit low-variance ties
- collapse ties into grouped rank buckets when many values are identical
Config:
arbitrary_types_allowed:Truevalidate_assignment:True
Fields:
-
frequencies(DataFrame) -
target_text(str) -
top(int)
Source code in lexos/cluster/seetrees/zscores.py
frequencies: pd.DataFrame
pydantic-field
¤
Term frequency table.
target_text: str = ''
pydantic-field
¤
Label for the target text.
top: int = 20
pydantic-field
¤
Number of features to display.
to_dataframe() -> pd.DataFrame
¤
Convert the top distinctive features and their z-scores into a DataFrame.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing the top features and their z-scores. |
Source code in lexos/cluster/seetrees/zscores.py
render_bar_chart() -> plt.Figure
¤
Render a horizontal bar chart of the top distinctive features for the target text.
Returns:
| Type | Description |
|---|---|
Figure
|
plt.Figure: Matplotlib figure containing the bar chart. |
Source code in lexos/cluster/seetrees/zscores.py
members: true