Skip to content

Add function to download dataset to a specific location. #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 139 additions & 12 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,7 +43,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -53,7 +53,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -72,16 +72,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(#20) [contradictory-my-dear-watson,gan-getting-started,store-sales-time-series-forecasting,tpu-getting-started,digit-recognizer,titanic,house-prices-advanced-regression-techniques,connectx,nlp-getting-started,spaceship-titanic...]"
"(#16) [https://www.kaggle.com/competitions/arc-prize-2024,https://www.kaggle.com/competitions/eedi-mining-misconceptions-in-mathematics,https://www.kaggle.com/competitions/rsna-2024-lumbar-spine-degenerative-classification,https://www.kaggle.com/competitions/ariel-data-challenge-2024,https://www.kaggle.com/competitions/um-game-playing-strength-of-mcts-variants,https://www.kaggle.com/competitions/playground-series-s4e9,https://www.kaggle.com/competitions/titanic,https://www.kaggle.com/competitions/house-prices-advanced-regression-techniques,https://www.kaggle.com/competitions/spaceship-titanic,https://www.kaggle.com/competitions/digit-recognizer...]"
]
},
"execution_count": null,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -93,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -116,16 +116,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading titanic.zip to C:\\Users\\iarun\\OneDrive\\Desktop\\Skills\\01_Computer_Sci\\03_AI\\10_Kaggle\\fastkaggle\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 34.1k/34.1k [00:00<00:00, 237kB/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/plain": [
"Path('titanic')"
]
},
"execution_count": null,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -134,6 +162,93 @@
"setup_comp('titanic')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"def setup_comp_directory(competition, path_to_download, install=''):\n",
" \"\"\"\n",
" Setup the environment for a Kaggle competition by downloading competition data and optionally installing packages.\n",
" \n",
" Inputs:\n",
" - competition (str): The name of the Kaggle competition (e.g., 'titanic'). This is used to fetch the relevant dataset.\n",
" - path_to_download (str): The directory path where competition data should be downloaded. \n",
" The function will create the directory if it does not already exist.\n",
" - install (str, optional): Optional package to install via pip (e.g., 'fastai') if running in a Kaggle environment. Default is '' (no installation).\n",
"\n",
" Outputs:\n",
" - path (Path object): The directory path where the competition data is located. \n",
" This will be the directory containing the unzipped data files.\n",
" \"\"\"\n",
" # Specify the desired directory to download files\n",
" custom_dir = Path(path_to_download) # Replace with your desired path\n",
" custom_dir.mkdir(parents=True, exist_ok=True) # Create the directory if it doesn't exist\n",
" \"Get a path to data for `competition`, downloading it if needed\"\n",
" if iskaggle:\n",
" if install:\n",
" os.system(f'pip install -Uqq {install}')\n",
" return Path('../input')/competition\n",
" else:\n",
" path = custom_dir / Path(competition)\n",
" api = import_kaggle()\n",
" if not path.exists():\n",
" import zipfile\n",
" api.competition_download_cli(competition, path=str(custom_dir)) # Download to custom directory\n",
" zipfile.ZipFile(f'{custom_dir}/{competition}.zip').extractall(path) # Extract files in custom directory\n",
" return path"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading titanic.zip to New_Folder\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 34.1k/34.1k [00:00<00:00, 223kB/s]"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n"
]
},
{
"data": {
"text/plain": [
"Path('New_Folder/titanic')"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"setup_comp_directory('titanic','New_Folder')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -520,7 +635,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -543,6 +658,18 @@
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.19"
}
},
"nbformat": 4,
Expand Down
60 changes: 17 additions & 43 deletions fastkaggle/_modidx.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,22 @@
# Autogenerated by nbdev

d = { 'settings': { 'allowed_cell_metadata_keys': '',
'allowed_metadata_keys': '',
'audience': 'Developers',
'author': 'Jeremy Howard',
'author_email': 'info@fast.ai',
'black_formatting': 'False',
'branch': 'master',
'clean_ids': 'True',
'copyright': 'Jeremy Howard, 2022 onwards',
'custom_sidebar': 'False',
'description': 'Kaggling for fast kagglers!',
d = { 'settings': { 'branch': 'master',
'doc_baseurl': '/fastkaggle/',
'doc_host': 'https://fastai.github.io',
'doc_path': 'docs',
'git_url': 'https://github.com/fastai/fastkaggle/tree/master/',
'host': 'github',
'jupyter_hooks': 'True',
'keywords': 'machine-learning kaggle fastai nbdev',
'language': 'English',
'lib_name': 'fastkaggle',
'lib_path': 'fastkaggle',
'license': 'apache2',
'min_python': '3.7',
'nbs_path': '.',
'readme_nb': 'index.ipynb',
'recursive': 'False',
'requirements': 'fastcore>=1.4.5 kaggle',
'status': '2',
'title': 'fastkaggle',
'tst_flags': 'notest',
'user': 'fastai',
'version': '0.0.8'},
'syms': { 'fastkaggle.core': { 'fastkaggle.core.check_ds_exists': 'https://fastai.github.io/fastkaggle/core.html#check_ds_exists',
'fastkaggle.core.create_libs_datasets': 'https://fastai.github.io/fastkaggle/core.html#create_libs_datasets',
'fastkaggle.core.create_requirements_dataset': 'https://fastai.github.io/fastkaggle/core.html#create_requirements_dataset',
'fastkaggle.core.get_dataset': 'https://fastai.github.io/fastkaggle/core.html#get_dataset',
'fastkaggle.core.get_local_ds_ver': 'https://fastai.github.io/fastkaggle/core.html#get_local_ds_ver',
'fastkaggle.core.get_pip_libraries': 'https://fastai.github.io/fastkaggle/core.html#get_pip_libraries',
'fastkaggle.core.get_pip_library': 'https://fastai.github.io/fastkaggle/core.html#get_pip_library',
'fastkaggle.core.import_kaggle': 'https://fastai.github.io/fastkaggle/core.html#import_kaggle',
'fastkaggle.core.iskaggle': 'https://fastai.github.io/fastkaggle/core.html#iskaggle',
'fastkaggle.core.mk_dataset': 'https://fastai.github.io/fastkaggle/core.html#mk_dataset',
'fastkaggle.core.nb_meta': 'https://fastai.github.io/fastkaggle/core.html#nb_meta',
'fastkaggle.core.push_dataset': 'https://fastai.github.io/fastkaggle/core.html#push_dataset',
'fastkaggle.core.push_notebook': 'https://fastai.github.io/fastkaggle/core.html#push_notebook',
'fastkaggle.core.setup_comp': 'https://fastai.github.io/fastkaggle/core.html#setup_comp'}}}
'lib_path': 'fastkaggle'},
'syms': { 'fastkaggle.core': { 'fastkaggle.core.check_ds_exists': ('core.html#check_ds_exists', 'fastkaggle/core.py'),
'fastkaggle.core.create_libs_datasets': ('core.html#create_libs_datasets', 'fastkaggle/core.py'),
'fastkaggle.core.create_requirements_dataset': ( 'core.html#create_requirements_dataset',
'fastkaggle/core.py'),
'fastkaggle.core.get_dataset': ('core.html#get_dataset', 'fastkaggle/core.py'),
'fastkaggle.core.get_local_ds_ver': ('core.html#get_local_ds_ver', 'fastkaggle/core.py'),
'fastkaggle.core.get_pip_libraries': ('core.html#get_pip_libraries', 'fastkaggle/core.py'),
'fastkaggle.core.get_pip_library': ('core.html#get_pip_library', 'fastkaggle/core.py'),
'fastkaggle.core.import_kaggle': ('core.html#import_kaggle', 'fastkaggle/core.py'),
'fastkaggle.core.mk_dataset': ('core.html#mk_dataset', 'fastkaggle/core.py'),
'fastkaggle.core.nb_meta': ('core.html#nb_meta', 'fastkaggle/core.py'),
'fastkaggle.core.push_dataset': ('core.html#push_dataset', 'fastkaggle/core.py'),
'fastkaggle.core.push_notebook': ('core.html#push_notebook', 'fastkaggle/core.py'),
'fastkaggle.core.setup_comp': ('core.html#setup_comp', 'fastkaggle/core.py'),
'fastkaggle.core.setup_comp_directory': ('core.html#setup_comp_directory', 'fastkaggle/core.py')}}}
Loading