PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchYou can build a handwritten-digit classifier with Keras by loading its built-in MNIST dataset, scaling the images, adding a channel dimension, and training a small convolutional neural network. The tutorial below follows Keras’ documented approach; “30 minutes” is a goal, not a guaranteed completion time, since setup and training speed depend on your environment.
What you’ll build
The model will classify an image as one of ten digits, from 0 through 9. MNIST contains 60,000 training images and 10,000 test images. Each is a 28-by-28 grayscale image, and its label is an integer from 0 to 9. Keras’ MNIST dataset documentation describes the dataset and its loading API.
Keras 3 supports TensorFlow, JAX, and PyTorch backends; the example uses the Keras API without prescribing a backend. See Keras’ introduction for engineers for broader background.
Load MNIST and inspect its shapes
Start by importing Keras and loading the dataset. The image arrays initially contain unsigned 8-bit pixel values, and the labels are one-dimensional integer arrays.
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
import keras
import numpy as np
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)
print(x_train.dtype, x_train.min(), x_train.max())
print(y_train[:10])
Before preprocessing, the expected shapes are (60000, 28, 28) and (60000,) for training images and labels, and (10000, 28, 28) and (10000,) for test images and labels. The pixel values range from 0 to 255.
Optionally view a training example
This small check can help connect the arrays to the task. Matplotlib is an optional plotting dependency; it is not needed to train the model.
import matplotlib.pyplot as plt
plt.imshow(x_train[0], cmap="gray")
plt.title(f"Label: {y_train[0]}")
plt.axis("off")
plt.show()
Preprocess images and labels
Convert the images to floating-point values and divide by 255 so pixel intensities fall between 0 and 1. A convolutional layer expects a channel dimension as well as height and width. These images are grayscale, so that final dimension is 1: a single image becomes (28, 28, 1).
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
The model below uses categorical cross-entropy, which expects one-hot encoded labels. For example, the label 3 becomes a vector with a 1 in the fourth position and 0s elsewhere.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
x_train = x_train.astype("float32") / 255
x_test = x_test.astype("float32") / 255
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)
y_train = keras.utils.to_categorical(y_train, 10)
y_test = keras.utils.to_categorical(y_test, 10)
print(x_train.shape, y_train.shape)
print(x_test.shape, y_test.shape)
After these transformations, the image shapes are (60000, 28, 28, 1) and (10000, 28, 28, 1); the label shapes are (60000, 10) and (10000, 10).
Build a compact convolutional neural network
A convolution layer learns local visual patterns such as strokes and curves. Pooling reduces the spatial dimensions as information moves through the network. Flatten turns the resulting feature maps into a vector; the final dense layer produces ten class scores, and softmax converts those scores into a distribution across the digit classes.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
This is a linear stack of layers, which is the kind of model Keras’ Sequential guide says is appropriate for a Sequential model. For multiple inputs or outputs, shared layers, or non-linear model paths, use a different model-building pattern such as the Functional API or subclassing.
model = keras.Sequential([
keras.Input(shape=(28, 28, 1)),
keras.layers.Conv2D(32, kernel_size=(3, 3), activation="relu"),
keras.layers.MaxPooling2D(pool_size=(2, 2)),
keras.layers.Conv2D(64, kernel_size=(3, 3), activation="relu"),
keras.layers.MaxPooling2D(pool_size=(2, 2)),
keras.layers.Flatten(),
keras.layers.Dropout(0.5),
keras.layers.Dense(10, activation="softmax"),
])
Compile and train the model
Compilation configures how the model learns and what Keras reports. Categorical cross-entropy measures the difference between the one-hot target and predicted class distribution. Adam is the optimizer that updates model weights, while accuracy is a human-readable metric.
The settings here match Keras’ documented simple MNIST ConvNet example: batches of 128, up to 15 epochs, and 10% of the training data reserved for validation. They are example settings, not requirements for every machine or experiment. The validation split helps track performance during training; it does not replace the held-out test set.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
model.compile(
loss="categorical_crossentropy",
optimizer="adam",
metrics=["accuracy"],
)
history = model.fit(
x_train,
y_train,
batch_size=128,
epochs=15,
validation_split=0.1,
)
An epoch is one pass through the training portion used by fit. Training output reports training metrics and validation metrics separately. Do not treat validation accuracy as test accuracy.
Evaluate on the held-out test data
Once training is complete, evaluate the model on the test set that was not used for fitting or validation. This produces a test loss and test accuracy for this particular run.
test_loss, test_accuracy = model.evaluate(x_test, y_test, verbose=0)
print(f"Test accuracy: {test_accuracy:.4f}")
Keras describes its Simple MNIST convnet as achieving approximately 99% test accuracy. That is the example page’s stated performance, not a guarantee or an independently reproduced result here; your result can vary with the code, backend, and run. The example page also shows training and validation metrics, which are distinct from evaluation on the held-out test set.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Classify one image
To inspect a prediction, pass one preprocessed test image to the model. The output contains ten probabilities; argmax selects the index with the highest score.
probabilities = model.predict(x_test[:1], verbose=0)[0]
predicted_digit = int(np.argmax(probabilities))
print("Predicted digit:", predicted_digit)
print("Actual digit:", int(np.argmax(y_test[0])))
What this result does—and doesn’t—show
MNIST is a useful learning task because it provides small, centered grayscale digit images with established labels. Success on this dataset alone does not establish how the model will perform on phone photographs, differently styled handwriting, images with cluttered backgrounds, or a deployed recognition product. Those settings differ from the dataset and require suitable data and evaluation of their own.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

