You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/tutorials.md
+28-61Lines changed: 28 additions & 61 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ These tutorials illustrate how to use a sequence of Kaggle CLI commands to accom
6
6
7
7
Before starting these tutorials, please make sure you have:
8
8
9
-
1. Installed the Kaggle CLI.
10
-
2.Downloaded your `kaggle.json`API token from your Kaggle account page (e.g., `https://www.kaggle.com/settings`) and placed it in the `~/.kaggle/` directory (or `C:\Users\<Windows-username>\.kaggle\` on Windows).
11
-
3. Logged in to your kaggle.com account in a web browser. This will allow you to easily verify the results of the CLI commands in the "Your Work" section of your Kaggle profile.
9
+
1. Installed the Kaggle CLI, following the instructions [here](https://github.com/Kaggle/kaggle-api/blob/main/documentation/intro.md#installation).
10
+
2.Set up your API credentials, following the instructions [here](https://github.com/Kaggle/kaggle-api/blob/main/documentation/intro.md#api-credentials)
11
+
3. Logged in to Kaggle in a web browser. This will allow you to verify the results of the CLI commands in the [`Your Work`](https://www.kaggle.com/work) section of your Kaggle profile.
12
12
13
13
## Tutorial: Create a Dataset
14
14
@@ -41,24 +41,18 @@ This tutorial walks you through creating a new dataset on Kaggle.
41
41
* Replace `"INSERT_SLUG_HERE"` with a URL-friendly version of your title, e.g., `"my-sample-dataset"`. The URL-friendly version is made by converting the title to lower-case and changing spaces to dashes.
42
42
* You can also add licenses, descriptions, and other relevant information.
43
43
44
-
*Example using `sed` (for Linux/macOS):*
45
-
```bash
46
-
sed -i 's/INSERT_TITLE_HERE/My Sample Dataset/' dataset-metadata.json
47
-
sed -i 's/INSERT_SLUG_HERE/my-sample-dataset/' dataset-metadata.json
48
-
```
49
-
50
44
5. **Create the dataset.** This command uploads your `sample_data.csv` and `dataset-metadata.json` to Kaggle.
51
45
52
46
```bash
53
47
kaggle datasets create -p .
54
48
```
55
49
You can add `--public` to make it public immediately.
56
50
57
-
6. **Verify on Kaggle.com.**Go to your Kaggle profile and check the "Datasets" tab inthe "Your Work" section. You should see "My Sample Dataset".
51
+
6. **Verify on Kaggle.com.**Refresh the [`Datasets` tab in`Your Work`](https://www.kaggle.com/work/datasets). You should see "My Sample Dataset".
58
52
59
-
## Tutorial: Download a Dataset and Prepare for Analysis
53
+
## Tutorial: Find and Download a Dataset
60
54
61
-
This tutorial explains how to find, download, and prepare a Kaggle dataset forlocal analysis using the CLI.
55
+
This tutorial explains how to findand download using the CLI.
62
56
63
57
1. **Search for a Dataset (Optional).**
64
58
* If you know the dataset you want, you can skip this step. Otherwise, you can search for datasets. For example, to search for datasets related to "iris":
@@ -91,30 +85,19 @@ This tutorial explains how to find, download, and prepare a Kaggle dataset for l
91
85
# For uciml/iris, it's iris.zip
92
86
unzip iris.zip
93
87
```
94
-
* After unzipping, you should see the data files (e.g., `Iris.csv`, `database.sqlite`).
88
+
95
89
96
-
5. **Prepare for Analysis.**
97
-
* The dataset is now downloaded and extracted. The primary data file for the Iris dataset is `Iris.csv`.
98
-
* You can now use your preferred tools (e.g., Python with libraries like Pandas and Scikit-learn, R, etc.) to load and analyze the data.
99
-
* For example, in a Python script within the `iris-dataset-analysis` directory, you might load the data using Pandas:
100
-
```python
101
-
import pandas as pd
102
-
df = pd.read_csv('Iris.csv')
103
-
print(df.head())
104
-
print(df.info())
105
-
```
90
+
5. **Verify the results.**
91
+
* After unzipping, you should see the data files (e.g., `Iris.csv`, `database.sqlite`).
106
92
107
-
This completes the process of downloading a dataset and preparing it for analysis using the Kaggle CLI.
108
-
You can adapt these steps for any dataset on Kaggle.
109
93
110
94
## Tutorial: Update a Kernel (Notebook)
111
95
112
96
This tutorial shows how to download an existing kernel, modify it, and push the changes back to Kaggle.
113
97
114
98
1. **Create or identify a kernel on Kaggle.com.**
115
99
* Log in to kaggle.com.
116
-
* Find an existing notebook (or create one). For this tutorial, let's assume its title is "My CLI Test Kernel".
117
-
* If the notebook has not been saved before, make a small change and **save a version** of the notebook on Kaggle.com (e.g., click "Save Version" and choose "Save & Run All (Commit)"). You cannot pull or push a kernel that is only in draft form.
100
+
* Find an existing notebook you own (or create one). For this tutorial, let's assume its title is "My CLI Test Kernel".
118
101
* Note the kernel slug from the browser's address bar. It will be something like `YOUR_USERNAME/my-cli-test-kernel`.
119
102
120
103
2. **Create a new local directory for your kernel.**
@@ -135,15 +118,15 @@ This tutorial shows how to download an existing kernel, modify it, and push the
135
118
4. **Edit the kernel or metadata.**
136
119
* Open the downloaded notebook file (e.g., `my-cli-test-kernel.ipynb`) and make some changes to the code or content.
137
120
* Open `kernel-metadata.json`. Let's add "benchmark" to the keywords. Find the `"keywords": []` line and change it to `"keywords": ["benchmark"]`.
138
-
* *Note: While you can edit keywords here, it's often best to manage them on kaggle.com, as there might be a restricted list of allowed keywords.*
121
+
* *Note: While you can edit keywords here, it's often best to manage them on kaggle.com, as there is a restricted list of allowed keywords.*
139
122
140
123
5. **Push the kernel.** This uploads your changes and the updated metadata, then runs the kernel on Kaggle.
141
124
142
125
```bash
143
126
kaggle kernels push -p .
144
127
```
145
128
146
-
6. **Verify on Kaggle.com.** Refresh the notebook page on kaggle.com. You should see your code changes and the "benchmark" tag added to the kernel settings.
129
+
6. **Verify on Kaggle.com.** Refresh the [`Code` tab in`Your Work`](https://www.kaggle.com/work/code). You should see your code changes and the "benchmark" tag added to the kernel settings.
147
130
148
131
## Tutorial: Create a Model
149
132
@@ -170,21 +153,13 @@ This tutorial guides you through creating a new model on Kaggle.
170
153
* Replace `"INSERT_SLUG_HERE"` with a URL-friendly version of the title (e.g., `"my-awesome-ai-model"`).
171
154
* Fill out the `"description"` field and other relevant sections like `"licenses"`.
172
155
173
-
*Example using `sed` (for Linux/macOS):*
174
-
```bash
175
-
# Replace YOUR_USERNAME with your actual Kaggle username
176
-
sed -i 's/INSERT_OWNER_SLUG_HERE/YOUR_USERNAME/' model-metadata.json
177
-
sed -i 's/INSERT_TITLE_HERE/My Awesome AI Model/' model-metadata.json
178
-
sed -i 's/INSERT_SLUG_HERE/my-awesome-ai-model/' model-metadata.json
179
-
```
180
-
181
156
5. **Create the model.**
182
157
183
158
```bash
184
159
kaggle models create -p .
185
160
```
186
161
187
-
6. **Verify on Kaggle.com.**Go to your Kaggle profile and check the "Models" tab inthe "Your Work" section. You should see "My Awesome AI Model".
162
+
6. **Verify on Kaggle.com.**Refresh the [`Models` tab in`Your Work`](https://www.kaggle.com/work/models). You should see "My Awesome AI Model".
188
163
189
164
## Tutorial: Create a Model Instance
190
165
@@ -213,22 +188,13 @@ This tutorial shows how to create an instance under an existing model. A model i
213
188
* Replace `"INSERT_FRAMEWORK_HERE"` with the model framework (e.g., `"jax"`, `"tensorflow"`, `"pytorch"`, `"sklearn"`).
214
189
* Update the `"instance_size_bytes"` if known, and add a `"description"`.
215
190
216
-
*Example using `sed` (for Linux/macOS):*
217
-
```bash
218
-
# Replace YOUR_USERNAME and my-awesome-ai-model accordingly
219
-
sed -i 's/INSERT_OWNER_SLUG_HERE/YOUR_USERNAME/' model-instance-metadata.json
220
-
sed -i 's/INSERT_EXISTING_MODEL_SLUG_HERE/my-awesome-ai-model/' model-instance-metadata.json
221
-
sed -i 's/INSERT_INSTANCE_SLUG_HERE/jax-implementation/' model-instance-metadata.json
222
-
sed -i 's/INSERT_FRAMEWORK_HERE/jax/' model-instance-metadata.json
223
-
```
224
-
225
191
5. **Create the model instance.** This uploads the files in the current directory (e.g., `flax_model.params`) along with the instance metadata.
226
192
227
193
```bash
228
194
kaggle models instances create -p .
229
195
```
230
196
231
-
6. **Verify on Kaggle.com.** Go to your model's page on Kaggle. You should see a new "jax-implementation" instance listed, and it will have one version containing `flax_model.params`.
197
+
6. **Verify on Kaggle.com.** Go to your model's page on Kaggle by clicking on the model under in the [`Models` tab on `Your Work`](https://www.kaggle.com/work/models). You should see a new "jax-implementation" instance listed, and it will have one version containing `flax_model.params`.
232
198
233
199
## Tutorial: Create a Model Instance Version
234
200
@@ -252,16 +218,16 @@ This tutorial explains how to add a new version to an existing model instance, f
252
218
```
253
219
*Note: The `-p .` means all files in the current directory will be uploaded as part of this new version. If you only want to upload `flax_model_v2.params`, ensure only it (and any other V2 files) are in a directory and point `-p` to that directory, or manage your files carefully.*
254
220
255
-
4. **Verify on Kaggle.com.** Go to your model instance page on Kaggle (e.g., `YOUR_USERNAME/my-awesome-ai-model/jax/jax-implementation`). You should see a new version (e.g., version 2) listed with your notes and the new files.
221
+
4. **Verify on Kaggle.com.** Go to your model instance page on Kaggle (e.g., `YOUR_USERNAME/my-awesome-ai-model/jax/jax-implementation`) by clicking on the [`Models` tab on `Your Work`](https://www.kaggle.com/work/models). You should see a new version (e.g., version 2) listed with your notes and the new files.
256
222
257
223
## Tutorial: How to Submit to a Competition
258
224
259
225
This tutorial walks you through the process of making a submission to a Kaggle competition using the CLI.
260
226
261
227
1. **Find a Competition and Accept Rules.**
262
228
* First, you need to find a competition. You can list active competitions using `kaggle competitions list`.
263
-
* For this tutorial, we'll use the "titanic" competition, which is a common starting point. You can find it at `https://www.kaggle.com/c/titanic`.
264
-
* **Important**: Before you can download data or submit, you *must* accept the competition's rules on the Kaggle website. Navigate to the competition page (e.g., `https://www.kaggle.com/c/titanic/rules`) and accept the terms.
229
+
* For this tutorial, we'll use the "titanic" competition, which is a common starting point. You can find it at [`https://www.kaggle.com/c/titanic`](https://www.kaggle.com/c/titanic).
230
+
* **Important**: Before you can download data or submit, you *must* join the competition and accept the competition's rules on the Kaggle website. Navigate to the competition on kaggle.com to do this.
265
231
266
232
2. **Create a Directory and Download Competition Files.**
267
233
* Create a new directory for your competition files and navigate into it.
@@ -307,22 +273,21 @@ This tutorial walks you through the process of making a submission to a Kaggle c
307
273
308
274
5. **Check Your Submission Status.**
309
275
* After submitting, you'll get a message indicating success or failure.
310
-
* You can check your submission's score and status on the "My Submissions" tab of the competition page on Kaggle.com (e.g., `https://www.kaggle.com/c/titanic/submissions`).
276
+
* You can check your submission's score and status on the "My Submissions" tab of the competition page on Kaggle.com (e.g., [`https://www.kaggle.com/c/titanic/submissions`](https://www.kaggle.com/c/titanic/submissions)).
311
277
* You can also list your recent submissions and their scores via the CLI:
312
278
```bash
313
279
kaggle competitions submissions -c titanic
314
280
```
315
281
* This command will show your submission, its status (e.g., `complete`, `error`), and your public/private scores if available.
316
282
317
-
This completes the process of submitting to a Kaggle competition using the CLI!
318
283
319
284
## Tutorial: How to Submit to a Code Competition
320
285
321
286
This tutorial walks you through the process of submitting to a code competition on Kaggle.
322
287
323
288
1. **Find a Code Competition.**
324
289
325
-
* First, you need to find a code competition to participate in. You can browse the available competitions on the [Kaggle competitions page](https://www.kaggle.com/competitions).
290
+
* First, you need to find a code competition to participate in. You can browse the available competitions on the [Kaggle competitions page](https://www.kaggle.com/competitions). Many Featured Competitions are code competitions.
326
291
327
292
2. **Download the Dataset.**
328
293
@@ -332,24 +297,26 @@ This tutorial walks you through the process of submitting to a code competition
332
297
```
333
298
* Replace `<competition-name>` with the name of the competition you want to participate in.
334
299
335
-
3. **Create a Kernel.**
300
+
3. **Create a Notebook.**
336
301
337
-
* Next, you need to create a kernel to work on your submission. A kernel is a computational environment that you can use to write and run your code. You can create a new kernel on the Kaggle website or by using the `kaggle kernels init` command.
302
+
* Next, you need to create a Kaggle Notebook to work on your submission. A Kaggle Notebook contains the code and environment settings for Kaggle to run and evaluate your submission. Follow the tutorial on [Creating / Updating Notebooks](https://github.com/Kaggle/kaggle-api/blob/main/documentation/tutorials.md#tutorial-update-a-kernel-notebook) if you're not sure how to do this.
338
303
339
304
4. **Write Your Code.**
340
305
341
-
* Now it's time to write your code! You can use any programming language or framework that you are comfortable with. The goal is to create a model that can make predictions on the test set.
306
+
* Now it's time to write your code! You can use any programming language or framework that is supported by Kaggle. The goal is to create a model that can make predictions on the test set.
342
307
343
308
5. **Submit Your Prediction.**
344
309
345
310
* Once you are happy with your model, you can submit your prediction to the competition. You can do this using the `kaggle competitions submit` command:
* Replace `<competition-name>` with the name of the competition, `<submission-file>` with the path to your submission file, and `<message>` with a brief description of your submission.
314
+
* Replace `<competition-name>` with the name of the competition, `<username>/<notebook-slug>` with the identifier of your notebook, and `<message>` with a brief description of your submission.
350
315
351
316
6. **Check Your Score.**
352
317
353
-
* After you have submitted your prediction, you can check your score on the competition leaderboard. The leaderboard shows the scores of all the participants in the competition.
318
+
* After you have submitted your prediction, you can check your score on the competition leaderboard. The leaderboard shows the scores of all the participants in the competition. You can download the leaderboard using the `kaggle competitions leaderboard` command:
0 commit comments