Tell us what works and what could be better. We read every submission.
@alvinthai·10 public vizzes
This example demonstrates a dual-logging setup for Python applications, sending console output and file logs to separate destinations with distinct severity levels and formatting. The code defines a `LogFormatter` class that applies ANSI color codes to console messages based on log level, while writing plain, uncolored records to the log file. It uses the standard `logging` module with `StreamHandler` for stdout and `FileHandler` for file output, configuring the root logger to handle debug through critical messages. A template controls the output format, including timestamps, thread names, and log levels.
This example presents an animated SVG visualization built with the D3-based alamode library, which wraps NVD3 chart components. The code applies custom colors, opacity, and dashed line styles across multiple chart types, including bars, lines, scatter plots, areas, and pie slices, using CSS selectors to target series and elements. It also converts table cells into hyperlinks by mapping column names to URL templates and substituting row values from the loaded dataset. The visualization supports interactive tooltips and hover-based styling updates, with dynamic color assignment driven by a periodic interval.
This example compares survival random forest and gradient boosting models for predicting patient outcomes in an AIDS clinical trial. It shows survival curves for individual patients over time, then evaluates classification performance at a fixed time point using ROC curves for each model and a blended ensemble. The code uses the `ranger` package for survival forests, `gbm` for boosting, and `pROC` for ROC analysis, with data loaded from the ACTG320 dataset. It also demonstrates data splitting and survival probability extraction at a chosen time period.
The visualization plots the expected F1-score against the threshold k for a binary classification problem, comparing predictions that include a "None" label versus those without it. It uses a dynamic programming algorithm to compute expectations, then marks the optimal k with a black dot and annotation. The code generates the plot with pandas DataFrame plotting and matplotlib's pyplot, using the ggplot style, and also includes a separate benchmark chart showing quadratic runtime scaling for the expectation maximization process.
This example shows how to load and parse three CSV files in parallel, then displays the sum of their `number` fields in a large heading. It uses the Fetch API and Promises to request the files, and d3-dsv’s `d3_dsv.csvParse` to convert each response text into an array of objects. After all three fetches complete via `Promise.all`, the code reads the first row’s `number` value from each parsed dataset, adds them together, and updates the page’s result span. The data sources are three local CSV files, each containing a single numeric value.
This visualization demonstrates the classic box-and-whisker plot, summarizing the distribution of data from the Michelson–Morley experiment using five statistics: minimum, lower quartile, median, upper quartile, and maximum. The chart renders as SVG and includes smooth animated transitions, periodically randomizing values to highlight how the box, median line, whiskers, and outliers update. The d3.box reusable chart component draws each distribution’s center line, innerquartile box, median line, whiskers, and outlier points, with support for custom whisker definitions and quartile calculations.
This example demonstrates sending a JSON payload to a Slack Incoming Webhook using the Python `requests` module. The code constructs a `slack_data` dictionary containing the message text, then posts it to the webhook URL with `requests.post`, setting the `Content-Type` header to `application/json`. It checks the response status code and raises a `ValueError` if the request fails, including the error code and response body in the exception. The webhook URL is a placeholder from Slack’s service, and the data source is the hardcoded message string.
This notebook demonstrates how a convolutional neural network learns to recognize handwritten digits from the MNIST database by visualizing its internal representations with t-SNE. It shows the network’s high-level feature layer (h_fc2) projected into two dimensions at various training stages, revealing clusters that correspond to digit classes. The code trains a LeNet-style model using TensorFlow, then applies sklearn.manifold.TSNE to the learned activations. Matplotlib renders the resulting scatter plots, with each point colored by its true label, illustrating how representations become more separable as training progresses.
This example implements a collection of information retrieval ranking metrics in Python. It defines functions for mean reciprocal rank, R-precision, precision at k, average precision, mean average precision, and discounted cumulative gain, each accepting relevance scores in rank order. The code uses NumPy arrays to compute binary relevance and graded relevance calculations, with doctests illustrating expected outputs. The implementation follows standard definitions from academic resources on IR evaluation, such as precision-recall curves and learning-to-rank literature.
This example demonstrates the common subset of Markdown and reStructuredText markup syntax, using both formats to show how text can be written portably across the two lightweight markup languages. The visualization is rendered as two nearly identical documents side-by-side, with font styling applied to display italics, bold, and monospaced text, along with paragraph and heading structure. It visually compares how the same source content appears in Markdown versus reStructuredText, highlighting the shared formatting conventions (like asterisk-based emphasis) and the differences in extensibility, such as tables and automatic table-of-contents generation. The layout makes it easy to see at a glance how each markup language handles identical input, emphasizing the "common denominator" subset approach for painless conversion between the two.