Kaggle Notebook Usage
Kaggle Notebooks provide an excellent cloud-based environment for data science and machine learning projects. This guide covers essential features, including GPU acceleration, data uploads, generating zip files, and downloading outputs via IPython.display.FileLink.
Setting Up a Kaggle Notebook
To start a new Kaggle Notebook:
Go to Kaggle
Click on New Notebook
Choose the Notebook Settings (CPU/GPU/TPU as needed)
Click Create
Enabling GPU/TPU
Kaggle provides free access to GPUs and TPUs. To enable GPU/TPU in your notebook:
Click on Settings (gear icon on the right panel)
Under Accelerator, choose GPU or TPU (If you creating a new account then you must verify phone number to access).
Restart the notebook for changes to take effect
To check GPU availability in your notebook, run:
import torch
print(torch.cuda.is_available())
Uploading Data to Kaggle Notebook
You can upload custom datasets by:
Clicking on Add Data (right panel)
Uploading files from your local system
Accessing the uploaded files in /kaggle/input/
To check uploaded files:
import os
os.listdir("/kaggle/input/")
Creating a ZIP File from Output
If your notebook generates multiple files, you might want to compress them into a ZIP file for easy downloading.
Run the following command to create a ZIP file:
import shutil
shutil.make_archive("output", "zip", "/kaggle/working/")
This will create output.zip
inside /kaggle/working/
.
Downloading the ZIP File
Kaggle does not provide a direct file download button, but you can use IPython.display.FileLink to generate a downloadable link.
from IPython.display import FileLink
FileLink("output.zip")
Click on the generated link to download your ZIP file.