ã¯ããã«
- kaggle APIã¯ãã¼ã«ã«PCã®ã¿ã¼ããã«(ã³ãã³ãããã³ãã)ããshellã³ãã³ãã§kaggleã®ç°å¢ãæä½ãããã¨ãã§ããåªæï¼Pythonã§å®è£ ããã¦ãã
- xonshã¯Pythonã§å®è£ ããã¦ãã(ï¼)shell
- kaggle APIãxonshã§åããã°xonsh人å£ãkaggle API人å£ãå¢ãã¦å¹¸ããªã®ã§ã¯ãªããï¼
ã¨ããããã§kaggle APIãxonshãã使ã£ã¦ã¿ã¾ãããï¼ ãã ï¼1ããæ¸ãã¦ããã¨ã¢ã¬ãªã®ã§ä¸»ã«
ã®é¨åãè¨é²ãã¾ãï¼kaggle APIãxonshã®å°å ¥ã«ã¤ãã¦ã¯ä»¥ä¸ãåç §ãã¦ãã ããï¼ ã¾ãï¼installationã«ã¯æ¥æ¬èªã®è¨äºãããã¾ãã®ã§åç §ãã¦ãã ãã*1
xonsh
æ¥æ¬èªã«ããç´¹ä»è¨äº
kaggle API
æ¥æ¬èªã«ããç´¹ä»è¨äº
åæ
- kaggle APIã¨xonshã¯å°å ¥ã§ãã¤ã¤ãã*2
- ç§ã¯windowsã¨ããä¿å®çãªOSã使ã£ã¦ããä¸ï¼ã»ãã®OSã§ã®åä½æ¤è¨¼ã¯ãã¦ããªãã®ã§ï¼åä½ã®ä¿è¨¼ã¯ã§ãã¾ããï¼
ã¤ãkernelã£ã¦ä½ï¼
kernelã¯ãã©ã¦ã¶ä¸ã§kaggleã®ã³ã³ããã£ã·ã§ã³ã«ä½¿ã£ã¦ããã³ã¼ããå®è¡ã§ããç°å¢ã§ãï¼ å®è¡ã ããããªãã¦ç·¨éãã§ãã¾ãï¼ããããï¼ ãã¼ã«ã«ï¼°ï¼£ã®ã¹ããã¯ã«ä¸å®ã®ãããããï¼è²·ã£ãã°ã£ããã®PCã®ãã¡ã³ãæ²é³´ãä¸ãå§ãããããï¼ ãã·ã³ã¹ããã¯ãkernelã«é ¼ãã°ãã¨ã¯å¥½ãã«Codingãã¦Commitãããï¼
kaggle APIãå°å ¥ãã
詳細ã¯ä¸ã®è¨äºãåèã«ãã¦ããã ãã¤ã¤ï¼ç°¡åã«å°å ¥ããã»ã¹ã確èªãã¾ãï¼
- Pythonã§
pip install kaggle
- kaggleã®ãã¼ã¸ã§APIãã¼ã¯ã³ãåå¾
- ç¹å®ã®ãã©ã«ã(win:
C:\Users\<UserName>\.kaggle
)ã«ä¿å - cmdã§
kaggle -h
ããã§ã¨ã©ã¼ãªããã«ãã£ã½ãæç« ãã§ãã°æåã§ãï¼
xonshãå°å ¥ãã
詳細ã¯ry
- Pythonã§
pip install xonsh
windowsã®å ´åï¼å ¬å¼ããã¥ã¡ã³ãããã¨ä»¥ä¸ã®ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ãã¦ã»ãããã«ãã¦ãã¾ãï¼
conda config --add channels conda-forge conda install xonsh
ç§ã¯ãã£ã¡ã§å®è£ ãã¾ããï¼ç°å¢ã«å¿ãã¦é©å®ï¼
- cmdã«
xonsh
ã¨æã¤ï¼
ããã§ããã£ã½ãç»é¢ãåºããxonshæåã§ãï¼
xonshããkaggle APIãå©ã
åºæ¬çã«xonshã¯PythonãåãShellãªã®ã§ï¼ä¸è¨ã®Installationãæ»ããªãé²ãã°ï¼xonshä¸ã§kaggle -h
ã³ãã³ããæã¤ã¨ã¡ããã¨åãã¦ããã¯ãã§ãï¼
xonshããkaggle APIã使ã£ã¦kernelã«ã³ã¼ããpushãã
ã¨ããããä½ãå¿
è¦ãªã®ãï¼å
¬å¼ããã¥ã¡ã³ãã¨ãã«ããè¦ã¦ã¿ã¾ãããï¼
ã©ãããAPIã¨ãã¦ã¯kernels
ã§ã«ã¼ãã«ãæä½ã§ãããããã§ããï¼
xonshã§kaggle kernel -h
ãæã¤ã¨ãããªæãã®ç»é¢ãï¼
ã¤ã±ã¦ããªï¼
ãããéå»ã«å®è¡ãããã¨ã®ããã³ãã³ãã¨ä¼¼ã¦ããã¨ããåã³ã¬æã¨ãã¨ãã¦ãªãï¼ãã£ã¦ãã£ã¦ããã¾ãï¼
ã¤ã±ã¦ããªï¼
â¦â¦ããã¯ã¨ãããï¼ã¡ãã£ã¨kernelãããã·ã¥ãã¦ã¿ã¾ãããï¼
ä»åã¯ãã¤ãã©ããTitanic
ãã¼ã¿ãã¦ã³ãã¼ã
ãã£ããã ããã£ããã¯ããã¾ãããï¼Titanicã®ãã¼ã¸ã«ããDataã¿ããã¯ãªãã¯ããã¨ï¼ ãä¸å¯§ã«kaggle APIã³ãã³ããããã¾ãï¼ãããã³ãã¼ã§ããï¼ xonshä¸ã§
kaggle competitions download -c titanic
ãæã¤ãï¼xonshã®ã¿ã¼ããã«ä¸ã§å³ã¯ãªãã¯ããã¨ãã¼ã¹ãããã¾ã*3ï¼ ããããã¨xonshã®åãã¦ãããã£ã¬ã¯ããªä¸ã«ãã¼ã¿ãDLããã¦ããã¨æãã¾ãï¼*4
ã¡ã¿ãã¼ã¿ãã¡ã¤ã«ãçæ
kaggleãpushããããã«ã¯ï¼ã©ãããã¡ã¿ãã¼ã¿ãå¿
è¦ãªæ§åã§ãï¼
kaggle kernels init
ã³ãã³ããå®è¡ããã¨ã¡ã¿ãã¼ã¿ã®jsonãã¡ã¤ã«ãçæããã¾ãï¼
jsonãã¡ã¤ã«ãã¨ãã£ã¿ãä½ãã§éãã¦ï¼ãã®ããã¥ã¡ã³ãããã¼ã¹ã«é次æ
å ±ãæ¸ãè¾¼ã¿ï¼ä¿åã¾ãããï¼
pushãããã¹ã¯ãªãããçæ
ä»åã¯ã¨ããããcsvãèªã¿è¾¼ãã§ã¿ã¾ãããï¼ ã¤ãã§ã«æ¨æ¶ããã¨ãã¾ãããï¼
import pandas as pd import numpy as np train_df = pd.read_csv("../input/train.csv") test_df = pd.read_csv("../input/test.csv") train_df.describe() print("hello, kaggler!")
pushæºå
ã³ã¼ããæ¸ããããã£ãä½ã£ãjsonãã¡ã¤ã«ãç·¨éãã¾ãï¼ä¸é¨ã¯äºåã§ãç·¨éã§ãã¾ããï¼ã¾ãé åºã¯ã好ã¿ã§ï¼å³ã¯å¤ããã¾ããï¼
- id: kernelã®ã¢ãã¬ã¹
é常UserName/ããããªkernelã®åå
ãå
¥ããã¨ããã¨æãã¾ãï¼å¿
é ï¼è¨å·ã¯ãã¤ãã³ã®ã¿æå¹ï¼(æªæ¤è¨¼)
- title: kernelã®ã¿ã¤ãã«
idã§æå®ããååã¨åãããã«ããã¨ããã§ãããï¼ - code_file: kernelã«pushããããã¡ã¤ã«
ã³ã¼ãã®ãã¡ã¤ã«åãæå®ãã¾ãï¼ã¡ã¿ãã¼ã¿ã®ãããã©ã«ãããã®ç¸å¯¾ãã¹ã§ããã¾ããä¸å®ãªã絶対ãã¹ã¶ã£ããã§ãåé¡ãªãã§ãï¼
- language: kernelã®è¨èª
pushããããã¡ã¤ã«ãä½ã§æ¸ããã¦ããããæå®ãã¾ãï¼python
ï¼r
ï¼rmarkdown
ãé¸ã¹ã¾ãï¼
- kernel_type
script
ãnotebook
ããé¸ã¹ã¾ãï¼
- is_private
kernelã®å
¬éæ
å ±ãæå®ã§ãã¾ãï¼ããã©ã«ãã¯true
ã§ã
- enable_gpu
kernelã®GPUã使ããã©ãããæå®ã§ãã¾ãï¼
ããããpushã³ãã³ãå®è¡å¾ï¼ã¤ã³ã¿ã¼ãããæ¥ç¶ã確ç«ãç¶ãããã¿ãããªãã¨ã ã¨æãã¾ãï¼
ããã©ã«ãã¯false
ã§ãï¼
- enable_internet
ã¤ã³ã¿ã¼ãããæ¥ç¶äºã
æ
å ±ã§ããï¼è¬ã§ãï¼ããã©ã«ãã¯false
- dataset_sources
ãã¼ã¿ã»ããã®åºå¦ãkaggleã§å ¬éããããã¼ã¿ã»ããã®å ´åï¼ããã«ãã¼ã¿ã»ããåãæ¸ãè¾¼ã¿ã¾ãï¼
- competition_sources
ãã¼ã¿ã»ããã®åºå¦ããkaggleã®ã³ã³ããã£ã·ã§ã³ã®å ´åï¼ããã«ã³ã³ããã£ã·ã§ã³åãæ¸ãã¾ãï¼
- kernel_sources
å¤åä»ã®äººã®kernelãpullããã¨ãã«ï¼kernelåãæå®ãã¾ãï¼
ã¨ããæãã§ãï¼å ¬å¼ããã¥ã¡ã³ãã«ä¸å¯§ã«æ¸ãã¦ãã®ã§ãã¡ããåèã«ï¼ ä»åã®å ´åã¯ãããªæãã«ãªãã¾ã
{ "id": "UserName/my-first-kernel", "title": "My First Kernel", "code_file": "hoge.py", "language": "python", "kernel_type": "script", "is_private": "true", "enable_gpu": "false", "enable_internet": "false", "dataset_sources": [], "competition_sources": ["titanic"], "kernel_sources": [] }
push
ããã¾ã§ã§ãããç°¡åã§ãï¼jsonãã¡ã¤ã«ãä¿åããã¦ããå ´æã§xonshãç«ã¡ä¸ãã¦ï¼kaggle kernels push
ã¨æã£ã¦Enterãé³é«ãé³´ããã¾ãï¼
ããããã¨
Kernel version 1 successfully pushed. Please check progress at https://www.kaggle.com/jsonã®idã§æå®ããã¢ã¬
ã¨ããã¡ãã»ã¼ã¸ãï¼ããã§pushæåã§ãï¼kaggleã®ãã¼ã¸ã«è¡ãã¨kernelã®ç°å¢ä¸ã§å®è¡ãã§ãã¦ãã¾ã
ãããã«
ãªãããªãã¾ãããï¼ãããªæãã§xonshãããã¼ã«ã«ã§çµãã ã³ã¼ããkernelç°å¢ã§å®è¡ãããã¨ãã§ãããã§ãï¼ jsonãã¡ã¤ã«ãã¡ãã£ã¨é¢åã§ããå¤åãã®ã¸ããèªååããè¡ã¯ããã§ãããï¼
ãã£ããã®APIï¼ä½¿ãåãã¦ããã¾ãããï¼
*1:å¤ãã¯ãªãã®ã§ãã®è¨äºãããªãã¨ããã¨ãããããã¾ãï¼ããããæµè¡ããã®ã¨ãã確信ããã£ã¦ãã£ã¦ããã¾ãããï¼
*2:ãã®åæã®æç¹ã§ãã®è¨äºã®ä¾¡å¤ã¯10åã¬ã ãããå®ã
*3:windows10ã®ã³ãã³ãããã³ããã¯Ctrl+C/Vã§ã³ããã§ãããã§ããï¼xonshã¯ãããã§ããªãããã§ãï¼
*4:ãã£ã¬ã¯ããªã移åãããå ´åï¼UNIXã³ãã³ãåæ§cdã³ãã³ãã§ç§»åã§ãã¾ãï¼