ããã«ã¡ã¯ãæ°è¦åºåéçºé¨æå±ã¨ã³ã¸ãã¢ã®ã¬ãªï¼@lchinï¼ã§ããæ®æ®µã¯åºåé ä¿¡é¢ä¿ã®ã·ã¹ãã ãéçºãã¦ãã¾ãããããæè¿ããã¼ã¿ãµã¤ã¨ã³ã¹ãã«èå³ãæã¡å§ãã¾ãããéã«èª¬æããã¨ããã¼ã¿ãµã¤ã¨ã³ã¹ã¯çµ±è¨å¦ãæ©æ¢°å¦ç¿ãªã©ãç¨ãã¦è«å¤§ã®ãã¼ã¿ãã価å¤ãå¼ã£å¼µãåºãåéã§ããä»åã®techlifeã¯ããã®ãã¼ã¿ãµã¤ã¨ã³ã¹ãå¦ã¶éç¨ã§ç¥ã£ããã¼ã«Jupyter NotebookãRuby on Railsã®éçºã«å½¹ã«ç«ã¤ä½¿ãæ¹ãç´¹ä»ãã¾ãã
Jupyter Notebookã¨ã¯ä½ã
Jupyter Notebook*1ã¯ç§å¦è ã®ãå®é¨ãã¼ããã«ã¤ã³ã¹ãã¤ã¢ãããã¦ã§ãä¸ã®ã¤ã³ã¿ã©ã¯ãã£ãã·ã§ã«ç°å¢ã§ãããã ã®ã¤ã³ã¿ã©ã¯ãã£ãã·ã§ã«ç°å¢ã§ã¯ãªããã½ã¼ã¹ã³ã¼ãããã®å®è¡çµæã解説ããææ¸ãæ°å¼ãç»åãªã©ãã¾ã¨ãã¦1ã¤ã®ããã¼ãããã¯ãããã¥ã¡ã³ãã¨ãã¦æ±ãããã¨ãç¹å¾´ã§ãã
Jupyter Notebookã¯Pythonã§å®è£ ããã¦ãã¾ãããã¦ã§ãã®UIã¨ãã¼ãããã¯ã®ã½ã¼ã¹ã³ã¼ããå®æ³ããç°å¢ãåããã¦ããè¨è¨ã®ãããPython以å¤ã«æ§ã ãªããã°ã©ãã³ã°è¨èªã«å¯¾å¿ãã¦ãã¾ããã½ã¼ã¹ã³ã¼ããå®è¡ããã³ã³ãã¼ãã³ãã¯kernelã¨å¼ã°ãã¦ãã¾ããRubyãå®è¡ããkernelã¯iRubyã§ãã
Jupyterã®è©¦ãæ¹
Jupyterãã¤ã³ã¹ãã¼ã«ããã«è©¦ãæ¹æ³ã¨ãã¦Try Jupyterãããã¾ããRubyã®ãµã³ãã«ãã¼ãããã¯ã¯ãªãã®ã§ãããiRubyãã¤ã³ã¹ãã¼ã«ããã¦ãç°å¢ã§ãã®ã§ãMenuããRubyã使ã£ããã¼ãããã¯ãä½æã§ãã¾ãã
ã¡ãã£ã¨è©¦ãã®ã«ãTry Rubyä¸ã«å ¥ã£ã¦ãGemã調ã¹ã¦ã¿ã¾ãã
local_gems = Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.group_by{ |g| g.name } local_gems.keys.each {|gem_name| puts gem_name }
ä½æãããã¼ãããã¯ã¯nbviewerã使ã£ã¦ãå®è¡çµæãå«ãã¦å ±æã§ãã¾ããä¾ãã°ãä¸è¨ã®RubyãTry Jupyterã«å®è¡ãã¦ã¿ãçµæã¯ä»¥ä¸ã®URLã«é²è¦§ã§ãã¾ãã
Jupyterã¨Rails
ãã¦ãJupyterã使ã£ã¦Ruby on Railsã®éçºã«å½¹ç«ã¤ã«ã¯ãRailsã¢ããªã«æ¥ç¶ããå¿ è¦ãããã¾ããã¾ããJupyterã¨iRubyãæå ã®ç°å¢ã«ç¨æãã¾ãã
Jupyterã¨iRubyãã¤ã³ã¹ãã¼ã«ãã
Pythonã®ããç°å¢ã§ããã°ãpip
ãªã©ã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
pip install jupyter
Pythonã®ãªãç°å¢ã®å ´åãJupyterå ¬å¼ããã¥ã¡ã³ãã®ã¤ã³ã¹ãã¼ã«æé ã«å¾ããAnaconda(Jupyterãå«ããã¼ã¿ãµã¤ã¨ã³ã¹åãPythonç)ãã¤ã³ã¹ãã¼ã«ãã¾ãã
iRubyã¯RubyGemsã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãããç°å¢ã«å¿ãã¦libmzq3ãªã©ä¾åã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ãå¿ è¦ã§ãã
gem install iruby
ããã¦ãJupyterã«irubyãç»é²ãã¦ãjupyterãèµ·åãã¾ãã
ruby register jupyter notebook
Railsã¨ç¹ã
iRuby kernelã使ã£ããã¼ãããã¯ã¯å°ãç¹æ®ãªirbã¿ãããªãã®ã§ããRailsã¨ç¹ãã«ã¯ãrails console
ã¨åãããã«RAILS_ROOT
ã§bootãã¦ç°å¢ãèªã¿ããã°ããã§ãã
FileUtils.cd rails_root require './config/boot' APP_PATH = File.expand_path('config/application') unless defined?(APP_PATH) require APP_PATH Rails.application.require_environment!
Jupyterã®å¿ç¨
Jupyter Notebookã¯ãad-hocãªã½ã¼ã¹ã³ã¼ããå®è¡ãããã®å®è¡çµæãæç« ãªã©ã¨åããã¦ããã¥ã¡ã³ãã«ã¾ã¨ãã¦nbviewerã«å ±æãããã¨ããã¼ã ã§Railsã¢ããªãéçºããæ§ã ãªå ´é¢ã§å½¹ã«ç«ã¡ã¾ãã
- IRB, pryãªã©ã®ä»£ããã®ãããã¿ã¤ãã³ã°ã¨æ¤è¨¼ï¼çµæãæ®ãããåç¾ããããï¼
- æ°æ©è½ããã«ãªã¯ã¨ã¹ãã«ã¾ã¨ããæããã®åä½ãå®è¡çµæãå ±æãã¦ç°¡åãªã§ãã«ãã
- ãããã°ããæã«ããã°ãåç¾ããçµæãã¼ã¿ãåå ã®ä»®èª¬ãªã©ãå¥ã®ãã¡ã¤ã«ã«ã³ããããã«ã1ã¤ã®è³æã«æ®ãããããæéãæãããã°èª¿æ»ãå°ã楽ã«ãªã
- ããã°ã©ã ãã¢ã«ã´ãªãºã ã®æé©åãè¡ãã¨ãããããã®ã³ã°åæ§ã«ãå®é¨ã®ç¹°ãè¿ãã§ãã®ã§ã仮説ãã³ã¼ãããã¼ã¿ããæãã¦ãæ®ãå¿ è¦ã®ããä½æ¥ã§ãã
- ã¾ããRailsã¢ããªã®DBã«å ¥ã£ã¦ããã¼ã¿ãç´æ¥å¼ã£å¼µãã ãã¦ãdaruãstatsampleãªã©SciRubyã®ç§å¦è¨ç®ã©ã¤ãã©ãªãå¿ç¨ãã¦ãã¼ã¿åæãã§ãã
çµããã«
ç§å¦è åæ§ã«ã¨ã³ã¸ãã¢ãç§å¦çæ¹æ³ãå¿ç¨ãããã¨ã«ä¾¡å¤ãããã¨æãã¾ããããã§ãJupyter Notebookã¯å½¹ã«ç«ã¤ãã¼ã«ã§ãããiRubyã¨åãããã¨Ruby on Railsã¢ããªã®éçºéç¨ã§ã便å©ã«ä½¿ãã¾ããæ¯é試ãã¦ã¿ã¦ãã ããã
æå¾ã«ãã¯ãã¯ãããã§ã¯ç§éã¨ä¸ç·ã«ãç§å¦ãããã¨ã³ã¸ãã¢ãç©æ¥µçã«åéãã¦ãã¾ãã®ã§ãæ¯éãå¿åãã ããï¼