How to Create a Matplotlib Time Series Scatter Plot

How to Create a Matplotlib Time Series Scatter Plot

Visualizing data over time is a task I perform almost daily as a developer. While line charts are the standard, there are many times when a scatter plot is actually the better choice. In my experience, scatter plots are perfect for identifying outliers in time-based data or showing specific events that don’t necessarily have a … Read more >>

How to Set Y-Axis Range in Matplotlib Bar Charts

Set Y-Axis Range in Matplotlib Bar Charts

In my years of building data dashboards for US-based financial firms, I’ve realized that Matplotlib’s default scaling isn’t always perfect. Sometimes, the auto-scaling feature hides the small differences between data points that actually matter for your analysis. In this tutorial, I will show you exactly how to take control of your Y-axis limits to make … Read more >>

Matplotlib Set Y Axis to Log Scale (base, symlog and zeros)

Matplotlib set y axis log scale: a linear plot beside the same data on a logarithmic y axis

To set a Matplotlib y axis to a log scale, call set_yscale on the axes or plt.yscale on the current figure: Two things catch people out. The argument is base, not basey, and any zero or negative value is dropped without a warning. Both are demonstrated below, on Python 3.12.5, Matplotlib 3.11.2. Setting the y … Read more >>

Enhance Keras ConvNets with Aggregated Attention Mechanisms

Enhance ConvNets with Aggregated Attention Mechanisms in Keras

I have spent the last four years building deep learning models, and if there is one thing I have learned, it is that standard Convolutional Neural Networks (ConvNets) sometimes miss the “big picture.” While convolutions are great at picking up local patterns, they often struggle to understand which parts of an image are truly important … Read more >>

Implement Class Attention Image Transformers (CaiT) with LayerScale in Keras

Implement Class Attention Image Transformers (CaiT) with LayerScale in Keras

I’ve found that scaling Vision Transformers (ViT) often leads to significant training instability. Standard ViT architectures tend to saturate or diverge when you add too many layers, which can be quite frustrating during model development. Recently, I started using Class Attention Image Transformers (CaiT), which introduces LayerScale to handle these deep architectural challenges effectively. In … Read more >>

Fix the Train-Test Resolution Discrepancy in Keras

Fix the Train Test Resolution Discrepancy in Keras 1

I have often noticed a frustrating drop in accuracy when deploying models. You train a model on $224 \times 224$ images, but the real-world performance only peaks when you feed it larger images during inference. This phenomenon is known as the train-test resolution discrepancy, and it occurs because the statistics of the data change when … Read more >>

Knowledge Distillation in Keras

Knowledge Distillation in Keras

I have spent a significant amount of time building complex deep learning models that perform brilliantly but are far too heavy for mobile devices. In my experience, Knowledge Distillation is the most effective way to shrink a massive “Teacher” model into a compact “Student” model while keeping the accuracy high. In this tutorial, I will … Read more >>

Image Tokenization in Vision Transformers with Keras

Keras Image Tokenization in Vision Transformers

In my four years of working with Keras, I’ve realized that moving from traditional CNNs to Vision Transformers (ViT) is a massive shift. The most confusing part for many developers I mentor is how we actually turn a standard image into a sequence of tokens that a Transformer can understand. In this tutorial, I will … Read more >>

Deep Learning Stability with Gradient Centralization in Python Keras

Deep Learning Stability with Gradient Centralization in Python Keras

In my years of working with deep learning, I have often hit a wall where my models just wouldn’t converge fast enough. I used to spend hours tweaking learning rates, only to find that the weight gradients were becoming unstable during backpropagation. Then I discovered Gradient Centralization (GC), a simple yet powerful technique that operates … Read more >>

Create an Empty Array in Python: [], array and NumPy

Python empty array: Command Prompt showing the empty 2D list multiplication trap and the list comprehension fix

An empty array in Python is almost always just an empty list: prices = []. Python has no built-in array type you have to declare first, so a pair of square brackets is the whole answer for most code: When you need typed numbers or math on whole arrays, the array module and NumPy step … Read more >>