1.すぐに利用したい方へ(as soon as)
「Mastering Machine Learning with R 」By Cory Lesmeister
http://shop.oreilly.com/product/9781787287471.do
docker
dockerを導入し、Windows, Macではdockerを起動しておいてください。
Windowsでは、BiosでIntel Virtualizationをenableにしないとdockerが起動しない場合があります。
また、セキュリティの警告などが出ることがあります。
docker pull and run
$ docker pull kaizenjapan/r-master
$ docker run -it kaizenjapan/r-master /bin/bash
以下のshell sessionでは
(base) root@473fc1bb505d:/#は入力促進記号(comman prompt)です。実際には数字の部分が違うかもしれません。この行の#の右側を入力してください。
それ以外の行は出力です。出力にエラー、違いがあれば、コメント欄などでご連絡くださると幸いです。
それぞれの章のフォルダに移動します。
dockerの中と、dockerを起動したOSのシェルとが表示が似ている場合には、どちらで捜査しているか間違えることがあります。dockerの入力促進記号(comman prompt)に気をつけてください。
ファイル共有または複写
dockerとdockerを起動したOSでは、ファイル共有をするか、ファイル複写するかして、生成したファイルをブラウザ等表示させてください。参考文献欄にやり方のURLを記載しています。
複写の場合は、dockerを起動したOS側コマンドを実行しました。お使いのdockerの番号で置き換えてください。複写したファイルをブラウザで表示し内容確認しました。
Chapter02
a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition# cd Chapter02
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter02# ls
code2.R
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter02# r code2.R
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
In addition: Warning message:
In data(anscombe) : data set ‘anscombe’ not found
Chapter03
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter03# r code3.R
Loading required package: grDevices
Loading required package: graphics
Loading required package: stats
Loading required package: utils
'data.frame': 699 obs. of 11 variables:
$ ID : chr "1000025" "1002945" "1015425" "1016277" ...
$ V1 : int 5 5 3 6 4 8 1 2 2 4 ...
$ V2 : int 1 4 1 8 1 10 1 1 1 2 ...
$ V3 : int 1 4 1 8 1 10 1 2 1 1 ...
$ V4 : int 1 5 1 1 3 8 1 1 1 1 ...
$ V5 : int 2 7 2 3 2 7 2 2 2 2 ...
$ V6 : int 1 10 2 4 1 10 10 1 1 1 ...
$ V7 : int 3 3 3 3 3 9 3 3 1 2 ...
$ V8 : int 1 2 1 7 1 7 1 1 1 1 ...
$ V9 : int 1 1 1 1 1 1 1 1 5 1 ...
$ class: Factor w/ 2 levels "benign","malignant": 1 1 1 1 1 2 1 1 1 1 ...
Error in library(corrplot) : there is no package called ‘corrplot’
Errors
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter05# r code5.R
Loading required package: stats
Loading required package: utils
Error in library(kknn) : there is no package called ‘kknn’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter06# r code6.R
Loading required package: graphics
Loading required package: stats
Loading required package: grDevices
Error in library(partykit) : there is no package called ‘partykit’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter07# r code7.R
Error in (function (file, local = FALSE, echo = verbose, print.eval = echo, :
code7.R:153:10: unexpected '='
152: validation_frame =
153: hidden =
^
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter08# r codeCluster.R
Error in library(compareGroups) :
there is no package called ‘compareGroups’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter09# r code9.R
Error in library(psych) : there is no package called ‘psych’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter10# r code10.R
Error in library(arules) : there is no package called ‘arules’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter11# r code11.R
Loading required package: grDevices
Loading required package: graphics
Loading required package: stats
Loading required package: utils
Error in library(caret) : there is no package called ‘caret’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter12# r code12_timeseries.R
Error in library(ggfortify) : there is no package called ‘ggfortify’
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter13# r code13.R
Error in library(tm) : there is no package called ‘tm’
add a line to the source.
install.packages("slam")
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter13# r code13.R
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Error in contrib.url(repos, type) :
trying to use CRAN without setting a mirror
chapter12, add a line like this
install.packages("weatherData",repos = "http://cran.us.r-project.org")
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter12# r code12_timeseries.R
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘crayon’, ‘fansi’, ‘utf8’, ‘bindr’, ‘cli’, ‘pillar’, ‘assertthat’, ‘bindrcpp’, ‘glue’, ‘pkgconfig’, ‘R6’, ‘Rcpp’, ‘rlang’, ‘tibble’, ‘tidyselect’, ‘BH’, ‘plogr’, ‘purrr’, ‘dplyr’, ‘tidyr’
trying URL 'http://cran.us.r-project.org/src/contrib/crayon_1.3.4.tar.gz'
Warning in download.file(url, destfile, method, mode = "wb", ...) :
"internal" method cannot handle https redirection to: 'https://cran.cnr.berkeley.edu/src/contrib/crayon_1.3.4.tar.gz'
switching to method = "libcurl" because of redirection to https
trying URL 'http://cran.us.r-project.org/src/contrib/crayon_1.3.4.tar.gz'
Content type 'application/x-gzip' length 658694 bytes (643 KB)
==================================================
downloaded 643 KB
(中略)
** R
** data
*** moving datasets to lazyload DB
** demo
** inst
** preparing package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (tidyr)
* installing *source* package ‘ggfortify’ ...
** package ‘ggfortify’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (ggfortify)
The downloaded source packages are in
‘/tmp/downloaded_packages’
Loading required package: methods
Loading required package: ggplot2
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file 'climate.csv': No such file or directory
ライブラリのコンパイルしはじめた。で、最後はエラー。
climate.csvは、../data-master/のしたにある。
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter12# cp ../data-master/climate.csv .
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter12# r code12_timeseries.R
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
trying URL 'http://cran.us.r-project.org/src/contrib/ggfortify_0.4.5.tar.gz'
Warning in download.file(url, destfile, method, mode = "wb", ...) :
"internal" method cannot handle https redirection to: 'https://cran.cnr.berkeley.edu/src/contrib/ggfortify_0.4.5.tar.gz'
switching to method = "libcurl" because of redirection to https
trying URL 'http://cran.us.r-project.org/src/contrib/ggfortify_0.4.5.tar.gz'
Content type 'application/x-gzip' length 2706609 bytes (2.6 MB)
==================================================
downloaded 2.6 MB
* installing *source* package ‘ggfortify’ ...
** package ‘ggfortify’ successfully unpacked and MD5 sums checked
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (ggfortify)
The downloaded source packages are in
‘/tmp/downloaded_packages’
Loading required package: methods
Loading required package: ggplot2
'data.frame': 95 obs. of 3 variables:
$ Year: int 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 ...
$ CO2 : int 806 932 803 845 970 963 975 983 1062 1065 ...
$ Temp: num -0.272 -0.241 -0.187 -0.301 -0.272 -0.292 -0.214 -0.105 -0.208 -0.206 ...
Error in library(forecast) : there is no package called ‘forecast’
install.packages("forecast",repos = "http://cran.us.r-project.org")
install.packages("tseries",repos = "http://cran.us.r-project.org")
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (lmtest)
ERROR: dependency ‘curl’ is not available for package ‘TTR’
* removing ‘/usr/local/lib/R/site-library/TTR’
ERROR: dependencies ‘TTR’, ‘curl’ are not available for package ‘quantmod’
* removing ‘/usr/local/lib/R/site-library/quantmod’
ERROR: dependency ‘quantmod’ is not available for package ‘tseries’
* removing ‘/usr/local/lib/R/site-library/tseries’
ERROR: dependency ‘tseries’ is not available for package ‘forecast’
* removing ‘/usr/local/lib/R/site-library/forecast’
(中略)
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libcurl was not found. Try installing:
* deb: libcurl4-openssl-dev (Debian, Ubuntu, etc)
* rpm: libcurl-devel (Fedora, CentOS, RHEL)
* csw: libcurl_dev (Solaris)
If libcurl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libcurl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘curl’
* removing ‘/usr/local/lib/R/site-library/curl’
ERROR: dependency ‘curl’ is not available for package ‘TTR’
* removing ‘/usr/local/lib/R/site-library/TTR’
ERROR: dependencies ‘TTR’, ‘curl’ are not available for package ‘quantmod’
* removing ‘/usr/local/lib/R/site-library/quantmod’
ERROR: dependency ‘quantmod’ is not available for package ‘tseries’
* removing ‘/usr/local/lib/R/site-library/tseries’
The downloaded source packages are in
‘/tmp/downloaded_packages’
Loading required package: methods
Loading required package: ggplot2
'data.frame': 95 obs. of 3 variables:
$ Year: int 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 ...
$ CO2 : int 806 932 803 845 970 963 975 983 1062 1065 ...
$ Temp: num -0.272 -0.241 -0.187 -0.301 -0.272 -0.292 -0.214 -0.105 -0.208 -0.206 ...
Error in library(forecast) : there is no package called ‘forecast’
In addition: Warning messages:
1: In install.packages("forecast", repos = "http://cran.us.r-project.org") :
installation of package ‘curl’ had non-zero exit status
2: In install.packages("forecast", repos = "http://cran.us.r-project.org") :
installation of package ‘TTR’ had non-zero exit status
3: In install.packages("forecast", repos = "http://cran.us.r-project.org") :
installation of package ‘quantmod’ had non-zero exit status
4: In install.packages("forecast", repos = "http://cran.us.r-project.org") :
installation of package ‘tseries’ had non-zero exit status
5: In install.packages("forecast", repos = "http://cran.us.r-project.org") :
installation of package ‘forecast’ had non-zero exit status
6: In install.packages("tseries", repos = "http://cran.us.r-project.org") :
installation of package ‘curl’ had non-zero exit status
7: In install.packages("tseries", repos = "http://cran.us.r-project.org") :
installation of package ‘TTR’ had non-zero exit status
8: In install.packages("tseries", repos = "http://cran.us.r-project.org") :
installation of package ‘quantmod’ had non-zero exit status
9: In install.packages("tseries", repos = "http://cran.us.r-project.org") :
installation of package ‘tseries’ had non-zero exit status
2. dockerを自力で構築する方へ
ここから下は、上記のpullしていただいたdockerをどういう方針で、どういう手順で作ったかを記録します。
上記のdockerを利用する上での参考資料です。本の続きを実行する上では必要ありません。
自力でdocker/anacondaを構築する場合の手順になります。
dockerfileを作る方法ではありません。ごめんなさい。
docker
ubuntu, debianなどのLinuxを、linux, windows, mac osから共通に利用できる仕組み。
利用するOSの設定を変更せずに利用できるのがよい。
同じ仕様で、大量の人が利用することができる。
ソフトウェアの開発元が公式に対応しているものと、利用者が便利に仕立てたものの両方が利用可能である。今回は、公式に配布しているものを、自分で仕立てて、他の人にも利用できるようにする。
docker pull
docker公式配布の利用は、URLからpullすることで実現する。
apt
(base) root@473fc1bb505d:/# apt update
(base) root@473fc1bb505d:/# apt install -y vim apt-utils sudo props
(base) root@817a98f4a315:/# apt install -y r-base
(base) root@817a98f4a315:/# apt install -y r-cran-hmisc
(base) root@817a98f4a315:/# r --version
r ('littler') version 0.3.0
using GNU R Version 3.3.1 (2016-06-21)
Copyright (C) 2006 - 2016 Jeffrey Horner and Dirk Eddelbuettel
r is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License. For more information about
these matters, see http://www.gnu.org/copyleft/gpl.html.
(base) root@817a98f4a315:/Mastering-Machine-Learning-with-R-Second-Edition/Chapter13# apt-get install r-cran-slam
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
r-cran-slam
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 92.1 kB of archives.
After this operation, 162 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian stretch/main amd64 r-cran-slam amd64 0.1-40-1 [92.1 kB]
Fetched 92.1 kB in 1s (66.4 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package r-cran-slam.
(Reading database ... 32035 files and directories currently installed.)
Preparing to unpack .../r-cran-slam_0.1-40-1_amd64.deb ...
Unpacking r-cran-slam (0.1-40-1) ...
Setting up r-cran-slam (0.1-40-1) ...
git
(base) root@9239fd07cbe8:/# git clone https://github.com/PacktPublishing/Mastering-Machine-Learning-with-R-Second-Edition
または
https://resources.oreilly.com/examples/9781787287471/
からダウンロード
docker hubへの登録
IDは、ご自身のをお使いください。kaizenjapanのところをご自身のIDで入力すれば大丈夫かも。
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
817a98f4a315 kaizenjapan/r-ml "/usr/bin/tini -- /b…" 15 hours ago Up 15 hours 0.0.0.0:8888->8888/tcp elastic_khorana
$ docker commit 817a98f4a315 kaizenjapan/r-master
$ docker push kaizenjapan/r-master
The push refers to repository [docker.io/kaizenjapan/r-master]
7cea25194405: Pushing [====> ] 28.19MB/307.1MB
9dad70eade1b: Mounted from kaizenjapan/r-ml
513109f92bd0: Mounted from kaizenjapan/anaconda3-wei
443496790d0d: Mounted from kaizenjapan/anaconda3-wei
64e142099cde: Mounted from kaizenjapan/anaconda3-wei
b28ef0b6fef8: Mounted from kaizenjapan/anaconda2-spark
anacondaの2と3から作っている。不具合があれば、どちらかだけから作るとよいかも。
参考文献(reference)
R ScriptやR Markdownからinstall.packages()を呼び出す場合はレポジトリを指定しないとエラーになる
https://qiita.com/maech/items/03b9566fb0fe940e1736
Rでtrying to use CRAN without setting a mirrorと言われたら
https://qiita.com/manabuishiirb/items/88fb9d5207e6802da4b7
文書履歴(document history)
ver. 0.10 初稿 20181028
ver. 0.11 エラー追記 20181029 午前
ver. 0.12 docker push 加筆 20181029 昼
最後までおよみいただきありがとうございました。
いいね 💚、フォローをお願いします。
Thank you very much for reading to the last sentence.
Please press the like icon 💚 and follow me for your happy life.