2017年3月31日 星期五

向金石堂買 Python 書籍一本

金石堂電子禮券還有一張使用期限 4/6 日截止, 但是該買啥書好呢? 因為金石堂的書比博客來少, 常有想買的書剛好沒有的情形. 所幸找到這本我目前正在學習的 Python 科學計算的書 :

王者歸來:Python在大數據科學計算上的最佳實作 860 元 79 折 679 元




【uni】三菱0.38超細中性筆-黑(UM-151) 55 折27 元

860+49=909 636/909=0.699 約七折左右






2017年3月30日 星期四

向金石堂購買人工智慧書籍兩本

最近收到金石堂寄來兩張面額 70 元的電子禮券, 其中一張使用期限為 4/1 日, 趁還記得趕快用掉, 免得發現時已過期徒呼負負. 這禮券限制需消費 700 元以上方可使用, 我找到下面這兩本很感興趣的書, 原 79 折優惠價合計 323+387=710, 扣掉 70 元禮券只要付 649 元, 約定價 420+490=910 的 71 折左右. 真巧, 剛好越過門檻, 這樣折扣感最大.

[中文書]超級智能時代:智慧革命中,前2%的人掌握世界,其餘98%將被淘汰 79 折 323 元
[中文書]人腦電腦黃金交叉:人工智慧終將一統世界 79 折 387 元



金石堂如果每個月都寄禮券給我的話, 我看我會受不了誘惑而持續買書.


2017年3月27日 星期一

2017 年第 12 周記事

由於水某週四~週日去新加坡開會, 所以本周就沒回鄉下. 週末就花了點時間整理高雄的書櫃, 把菁菁已沒在看的地球公民 365 給收起來裝箱運回鄉下, 跟其他繪本一樣, 我要給人家她說那是她的童年記憶.

週六下午去母校圖書館還書, 借回一本預約的大陸簡體書 :

# 機器學習算法原理與編程實戰 (鄭捷, 電子工業出版社, 2015)


回家與之前在金石堂買的 "今天不學機器學習, 明天就被機器取代-從 Python 入手+演算法 (佳魁, 2016)" 這本比對, 發現根本就是同一本書的繁體中文版, 差別是簡體原版前面有 8 頁彩圖而已. 既然內容一樣, 借的書就可以還了, 雖然讀簡體字對我不是問題 (以前讀語言學時要看一堆簡體參考書), 但是在我眼裡, 簡體字是一種殘障, 可說是 "殘體字", 優美的文字被摧殘成這樣, 我想老祖宗大概會很感嘆吧!

借書回來路上繞到新莊仔路的農會花卉中心, 買了三個長型盆栽與一袋培養土, 其中一個替換陽台已朽壞的一個盆栽, 打算栽種下列幾項 :
  1. 辣椒
  2. 韭菜
  3. 魚腥草
前陣子有在評估陽台的自動澆水系統, 但遲遲未有決策, 那就等盆栽擺放位置就緒後再來琢磨也不遲.

2017年3月24日 星期五

樹莓派安裝 Python2 scikit-learn 函式庫

前幾天在 Python3 環境下完成機器學習套件 scikit-learn 的安裝後, 看到有一本書是使用 Python 2.7 版的 scikit-learn, 作者提到有許多機器學習演算法還使用 Python 2 語法, 所以建議使用 2 版的較保險. 所以我又在樹莓派再安裝一次 Python2 版的 scikit-learn, 其指令與 Python3 版不同, 用 python 取代 python3 即可 :
  1. sudo apt-get install python-numpy
  2. sudo apt-get install python-scipy
  3. sudo apt-get install python-matplotlib
  4. sudo apt-get install python-pandas
  5. sudo pip install scikit-learn -U
  6. sudo apt-get install ipython (不一定要安裝)
  7. sudo apt-get install ipython-notebook (不一定要安裝)
其中 ipython 與 ipython-notebook 是 Python 網頁互動式開發工具, 不是機器學習必要之套件, 有要用到 notebook 時再安裝, 參考 :

樹莓派安裝 Python3 scikit-learn 函式庫

過程紀錄如下 :

1. 安裝 numpy :

pi@raspberrypi:~ $ sudo apt-get install python-numpy
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-numpy is already the newest version.
python-numpy set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 7 not upgraded.

2. 安裝 scipy :

pi@raspberrypi:~ $ sudo apt-get install python-scipy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libpython-dev libpython2.7-dev python-decorator python-dev python-imaging python2.7-dev
The following NEW packages will be installed:
  libpython-dev libpython2.7-dev python-decorator python-dev python-imaging python-scipy python2.7-dev
0 upgraded, 7 newly installed, 0 to remove and 7 not upgraded.
Need to get 25.6 MB of archives.
After this operation, 54.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpython2.7-dev armhf 2.7.9-2+deb8u1 [17.9 MB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-dev armhf 2.7.9-1 [1,188 B]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpython-dev armhf 2.7.9-1 [19.6 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-decorator all 3.4.0-2 [22.3 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main python2.7-dev armhf 2.7.9-2+deb8u1 [287 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-imaging all 2.6.1-2+deb8u3 [9,846 B]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-scipy armhf 0.14.0-2 [7,345 kB]
Fetched 25.6 MB in 18s (1,369 kB/s)
Selecting previously unselected package libpython2.7-dev:armhf.
(Reading database ... 124087 files and directories currently installed.)
Preparing to unpack .../libpython2.7-dev_2.7.9-2+deb8u1_armhf.deb ...
Unpacking libpython2.7-dev:armhf (2.7.9-2+deb8u1) ...
Selecting previously unselected package libpython-dev:armhf.
Preparing to unpack .../libpython-dev_2.7.9-1_armhf.deb ...
Unpacking libpython-dev:armhf (2.7.9-1) ...
Selecting previously unselected package python-decorator.
Preparing to unpack .../python-decorator_3.4.0-2_all.deb ...
Unpacking python-decorator (3.4.0-2) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../python2.7-dev_2.7.9-2+deb8u1_armhf.deb ...
Unpacking python2.7-dev (2.7.9-2+deb8u1) ...
Selecting previously unselected package python-dev.
Preparing to unpack .../python-dev_2.7.9-1_armhf.deb ...
Unpacking python-dev (2.7.9-1) ...
Selecting previously unselected package python-imaging.
Preparing to unpack .../python-imaging_2.6.1-2+deb8u3_all.deb ...
Unpacking python-imaging (2.6.1-2+deb8u3) ...
Selecting previously unselected package python-scipy.
Preparing to unpack .../python-scipy_0.14.0-2_armhf.deb ...
Unpacking python-scipy (0.14.0-2) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libpython2.7-dev:armhf (2.7.9-2+deb8u1) ...
Setting up libpython-dev:armhf (2.7.9-1) ...
Setting up python-decorator (3.4.0-2) ...
Setting up python2.7-dev (2.7.9-2+deb8u1) ...
Setting up python-dev (2.7.9-1) ...
Setting up python-imaging (2.6.1-2+deb8u3) ...
Setting up python-scipy (0.14.0-2) ...

3. 安裝 matplotlib :

pi@raspberrypi~ $ sudo apt-get install python-matplotlib

Reading package lists... 0%

Reading package lists... 100%

Reading package lists... Done

Building dependency tree... 0%

Building dependency tree... 0%

Building dependency tree... 50%

Building dependency tree... 50%

Building dependency tree... 55%

Building dependency tree... 70%

Building dependency tree... 85%

Building dependency tree... 100%

Building dependency tree      

Reading state information... 0%

Reading state information... 0%

Reading state information... Done

The following extra packages will be installed:
  fonts-lyx libglade2-0 libjs-jquery-ui python-dateutil python-glade2 python-matplotlib-data python-mock python-nose python-pyparsing python-tz
Suggested packages:
  libjs-jquery-ui-docs python-gtk2-doc dvipng ghostscript inkscape ipython python-cairocffi python-configobj python-excelerator python-matplotlib-doc
  python-qt4 python-sip python-tornado python-traits python-wxgtk3.0 texlive-extra-utils texlive-latex-extra ttf-staypuft python-mock-doc python-coverage
  python-nose-doc
The following NEW packages will be installed:
  fonts-lyx libglade2-0 libjs-jquery-ui python-dateutil python-glade2 python-matplotlib python-matplotlib-data python-mock python-nose python-pyparsing
  python-tz
0 upgraded, 11 newly installed, 0 to remove and 7 not upgraded.
Need to get 7,803 kB of archives.
After this operation, 22.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

0% [Working]
         
0% [Connecting to mirrordirector.raspbian.org (93.93.128.193)]
                                                           
0% [Waiting for headers]
                     
0% [Working]
         
0% [Waiting for headers]
                     
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libglade2-0 armhf 1:2.6.4-2 [76.2 kB]

                     
0% [1 libglade2-0 0 B/76.2 kB 0%] [Waiting for headers]
                                                     
1% [Waiting for headers]
                     
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-lyx all 2.1.2-2 [176 kB]

                     
1% [2 fonts-lyx 0 B/176 kB 0%] [Waiting for headers]
                                                 
3% [Waiting for headers]
3% [Waiting for headers]
                     
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-jquery-ui all 1.10.1+dfsg-1 [499 kB]

                     
3% [3 libjs-jquery-ui 0 B/499 kB 0%] [Waiting for headers]
                                                       
7% [3 libjs-jquery-ui 256 kB/499 kB 51%]
                                     
10% [Waiting for headers]
                       
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-dateutil all 2.2-2 [51.3 kB]
                     
10% [4 python-dateutil 0 B/51.3 kB 0%] [Waiting for headers]
                                                         
10% [Waiting for headers]
10% [Waiting for headers]
                       
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-glade2 armhf 2.24.0-4 [42.1 kB]
                   
10% [5 python-glade2 0 B/42.1 kB 0%] [Waiting for headers]
                                                       
11% [Waiting for headers]
11% [Waiting for headers]
                       
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-matplotlib-data all 1.4.2-3.1 [3,041 kB]
                     
11% [6 python-matplotlib-data 0 B/3,041 kB 0%] [Waiting for headers]
                                                                 
17% [6 python-matplotlib-data 496 kB/3,041 kB 16%]
                                               
24% [6 python-matplotlib-data 1,048 kB/3,041 kB 34%]
33% [6 python-matplotlib-data 1,699 kB/3,041 kB 56%]
39% [6 python-matplotlib-data 2,236 kB/3,041 kB 74%]
45% [6 python-matplotlib-data 2,664 kB/3,041 kB 88%]
                                                 
50% [Working]
           
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pyparsing all 2.0.3+dfsg1-1 [64.0 kB]
         
50% [7 python-pyparsing 0 B/64.0 kB 0%]
                                     
51% [Working]
           
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tz all 2012c+dfsg-0.1 [31.9 kB]
         
51% [8 python-tz 0 B/31.9 kB 0%]
                             
51% [Working]
           
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-mock all 1.0.1-3 [33.2 kB]
         
51% [9 python-mock 0 B/33.2 kB 0%]
                               
51% [Working]
           
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-nose all 1.3.4-1 [134 kB]
         
51% [10 python-nose 0 B/134 kB 0%]
                               
53% [Working]
           
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-matplotlib armhf 1.4.2-3.1 [3,654 kB]
         
53% [11 python-matplotlib 0 B/3,654 kB 0%]
                                       
63% [11 python-matplotlib 751 kB/3,654 kB 21%]                                                                                                   772 kB/s 3s
73% [11 python-matplotlib 1,562 kB/3,654 kB 43%]                                                                                                 772 kB/s 2s
83% [11 python-matplotlib 2,337 kB/3,654 kB 64%]                                                                                                 772 kB/s 1s
93% [11 python-matplotlib 3,134 kB/3,654 kB 86%]                                                                                                 772 kB/s 0s
100% [Working]                                                                                                                                   772 kB/s 0s
                                                                                                                                                         
Fetched 7,803 kB in 8s (952 kB/s)
Selecting previously unselected package libglade2-0:armhf.
(Reading database ...
(Reading database ... 5%
(Reading database ... 10%
(Reading database ... 15%
(Reading database ... 20%
(Reading database ... 25%
(Reading database ... 30%
(Reading database ... 35%
(Reading database ... 40%
(Reading database ... 45%
(Reading database ... 50%
(Reading database ... 55%
(Reading database ... 60%
(Reading database ... 65%
(Reading database ... 70%
(Reading database ... 75%
(Reading database ... 80%
(Reading database ... 85%
(Reading database ... 90%
(Reading database ... 95%
(Reading database ... 100%
(Reading database ... 125300 files and directories currently installed.)
Preparing to unpack .../libglade2-0_1%3a2.6.4-2_armhf.deb ...
Unpacking libglade2-0:armhf (1:2.6.4-2) ...
Selecting previously unselected package fonts-lyx.
Preparing to unpack .../fonts-lyx_2.1.2-2_all.deb ...
Unpacking fonts-lyx (2.1.2-2) ...
Selecting previously unselected package libjs-jquery-ui.
Preparing to unpack .../libjs-jquery-ui_1.10.1+dfsg-1_all.deb ...
Unpacking libjs-jquery-ui (1.10.1+dfsg-1) ...
Selecting previously unselected package python-dateutil.
Preparing to unpack .../python-dateutil_2.2-2_all.deb ...
Unpacking python-dateutil (2.2-2) ...
Selecting previously unselected package python-glade2.
Preparing to unpack .../python-glade2_2.24.0-4_armhf.deb ...
Unpacking python-glade2 (2.24.0-4) ...
Selecting previously unselected package python-matplotlib-data.
Preparing to unpack .../python-matplotlib-data_1.4.2-3.1_all.deb ...
Unpacking python-matplotlib-data (1.4.2-3.1) ...
Selecting previously unselected package python-pyparsing.
Preparing to unpack .../python-pyparsing_2.0.3+dfsg1-1_all.deb ...
Unpacking python-pyparsing (2.0.3+dfsg1-1) ...
Selecting previously unselected package python-tz.
Preparing to unpack .../python-tz_2012c+dfsg-0.1_all.deb ...
Unpacking python-tz (2012c+dfsg-0.1) ...
Selecting previously unselected package python-mock.
Preparing to unpack .../python-mock_1.0.1-3_all.deb ...
Unpacking python-mock (1.0.1-3) ...
Selecting previously unselected package python-nose.
Preparing to unpack .../python-nose_1.3.4-1_all.deb ...
Unpacking python-nose (1.3.4-1) ...
Selecting previously unselected package python-matplotlib.
Preparing to unpack .../python-matplotlib_1.4.2-3.1_armhf.deb ...
Unpacking python-matplotlib (1.4.2-3.1) ...
Processing triggers for fontconfig (2.11.0-6.3+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libglade2-0:armhf (1:2.6.4-2) ...
Setting up fonts-lyx (2.1.2-2) ...
Setting up libjs-jquery-ui (1.10.1+dfsg-1) ...
Setting up python-dateutil (2.2-2) ...
Setting up python-glade2 (2.24.0-4) ...
Setting up python-matplotlib-data (1.4.2-3.1) ...
Setting up python-pyparsing (2.0.3+dfsg1-1) ...
Setting up python-tz (2012c+dfsg-0.1) ...
Setting up python-mock (1.0.1-3) ...
Setting up python-nose (1.3.4-1) ...
Setting up python-matplotlib (1.4.2-3.1) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...

4. 安裝 pandas :

pi@raspberrypi:~ $ sudo apt-get install python-pandas
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libhdf5-8 liblz4-1 libsnappy1 python-antlr python-bs4 python-joblib python-numexpr python-openpyxl python-pandas-lib
  python-simplejson python-statsmodels python-statsmodels-lib python-tables python-tables-data python-tables-lib python-xlrd
  python-xlwt
Suggested packages:
  python-pandas-doc python-tables-doc python-netcdf vitables
The following NEW packages will be installed:
  libhdf5-8 liblz4-1 libsnappy1 python-antlr python-bs4 python-joblib python-numexpr python-openpyxl python-pandas python-pandas-lib
  python-simplejson python-statsmodels python-statsmodels-lib python-tables python-tables-data python-tables-lib python-xlrd
  python-xlwt
0 upgraded, 18 newly installed, 0 to remove and 18 not upgraded.
Need to get 7,369 kB of archives.
After this operation, 38.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libhdf5-8 armhf 1.8.13+docs-15+deb8u1 [975 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main liblz4-1 armhf 0.0~r122-2 [14.8 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-antlr all 2.7.7+dfsg-6 [25.8 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-bs4 all 4.3.2-2 [77.7 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-joblib all 0.8.3-1 [63.9 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-numexpr armhf 2.4-1 [150 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-openpyxl all 1.7.0+ds1-1 [75.7 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pandas-lib armhf 0.14.1-2 [1,209 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pandas all 0.14.1-2 [1,252 kB]
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-simplejson armhf 3.6.5-1 [65.0 kB]
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main libsnappy1 armhf 1.1.2-3 [39.8 kB]
Get:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tables-lib armhf 3.1.1-3+b1 [313 kB]
Get:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tables-data all 3.1.1-3 [48.5 kB]
Get:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tables all 3.1.1-3 [337 kB]
Get:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-xlrd all 0.9.2-1 [143 kB]
Get:16 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-xlwt all 0.7.5+debian1-1 [85.1 kB]
Get:17 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-statsmodels-lib armhf 0.4.2-1.2 [46.2 kB]
Get:18 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-statsmodels all 0.4.2-1.2 [2,448 kB]
Fetched 7,369 kB in 11s (624 kB/s)
Selecting previously unselected package libhdf5-8:armhf.
(Reading database ... 138178 files and directories currently installed.)
Preparing to unpack .../libhdf5-8_1.8.13+docs-15+deb8u1_armhf.deb ...
Unpacking libhdf5-8:armhf (1.8.13+docs-15+deb8u1) ...
Selecting previously unselected package liblz4-1:armhf.
Preparing to unpack .../liblz4-1_0.0~r122-2_armhf.deb ...
Unpacking liblz4-1:armhf (0.0~r122-2) ...
Selecting previously unselected package python-antlr.
Preparing to unpack .../python-antlr_2.7.7+dfsg-6_all.deb ...
Unpacking python-antlr (2.7.7+dfsg-6) ...
Selecting previously unselected package python-bs4.
Preparing to unpack .../python-bs4_4.3.2-2_all.deb ...
Unpacking python-bs4 (4.3.2-2) ...
Selecting previously unselected package python-joblib.
Preparing to unpack .../python-joblib_0.8.3-1_all.deb ...
Unpacking python-joblib (0.8.3-1) ...
Selecting previously unselected package python-numexpr.
Preparing to unpack .../python-numexpr_2.4-1_armhf.deb ...
Unpacking python-numexpr (2.4-1) ...
Selecting previously unselected package python-openpyxl.
Preparing to unpack .../python-openpyxl_1.7.0+ds1-1_all.deb ...
Unpacking python-openpyxl (1.7.0+ds1-1) ...
Selecting previously unselected package python-pandas-lib.
Preparing to unpack .../python-pandas-lib_0.14.1-2_armhf.deb ...
Unpacking python-pandas-lib (0.14.1-2) ...
Selecting previously unselected package python-pandas.
Preparing to unpack .../python-pandas_0.14.1-2_all.deb ...
Unpacking python-pandas (0.14.1-2) ...
Selecting previously unselected package python-simplejson.
Preparing to unpack .../python-simplejson_3.6.5-1_armhf.deb ...
Unpacking python-simplejson (3.6.5-1) ...
Selecting previously unselected package libsnappy1.
Preparing to unpack .../libsnappy1_1.1.2-3_armhf.deb ...
Unpacking libsnappy1 (1.1.2-3) ...
Selecting previously unselected package python-tables-lib.
Preparing to unpack .../python-tables-lib_3.1.1-3+b1_armhf.deb ...
Unpacking python-tables-lib (3.1.1-3+b1) ...
Selecting previously unselected package python-tables-data.
Preparing to unpack .../python-tables-data_3.1.1-3_all.deb ...
Unpacking python-tables-data (3.1.1-3) ...
Selecting previously unselected package python-tables.
Preparing to unpack .../python-tables_3.1.1-3_all.deb ...
Unpacking python-tables (3.1.1-3) ...
Selecting previously unselected package python-xlrd.
Preparing to unpack .../python-xlrd_0.9.2-1_all.deb ...
Unpacking python-xlrd (0.9.2-1) ...
Selecting previously unselected package python-xlwt.
Preparing to unpack .../python-xlwt_0.7.5+debian1-1_all.deb ...
Unpacking python-xlwt (0.7.5+debian1-1) ...
Selecting previously unselected package python-statsmodels-lib.
Preparing to unpack .../python-statsmodels-lib_0.4.2-1.2_armhf.deb ...
Unpacking python-statsmodels-lib (0.4.2-1.2) ...
Selecting previously unselected package python-statsmodels.
Preparing to unpack .../python-statsmodels_0.4.2-1.2_all.deb ...
Unpacking python-statsmodels (0.4.2-1.2) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libhdf5-8:armhf (1.8.13+docs-15+deb8u1) ...
Setting up liblz4-1:armhf (0.0~r122-2) ...
Setting up python-antlr (2.7.7+dfsg-6) ...
Setting up python-bs4 (4.3.2-2) ...
Setting up python-joblib (0.8.3-1) ...
Setting up python-numexpr (2.4-1) ...
Setting up python-openpyxl (1.7.0+ds1-1) ...
Setting up python-pandas-lib (0.14.1-2) ...
Setting up python-pandas (0.14.1-2) ...
Setting up python-simplejson (3.6.5-1) ...
Setting up libsnappy1 (1.1.2-3) ...
Setting up python-tables-lib (3.1.1-3+b1) ...
Setting up python-tables-data (3.1.1-3) ...
Setting up python-tables (3.1.1-3) ...
Setting up python-xlrd (0.9.2-1) ...
Setting up python-xlwt (0.7.5+debian1-1) ...
Setting up python-statsmodels-lib (0.4.2-1.2) ...
Setting up python-statsmodels (0.4.2-1.2) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...
Processing triggers for python-support (1.0.15) ...

5. 安裝 scikit-learn :  (加 -U 表示 Upgrade)

pi@raspberrypi:~ $ sudo pip install scikit-learn -U
Downloading/unpacking scikit-learn
  Downloading scikit-learn-0.18.1.tar.gz (8.9MB): 8.9MB downloaded
  Running setup.py (path:/tmp/pip-build-A9tWvA/scikit-learn/setup.py) egg_info for package scikit-learn
    Partial import of sklearn during the build process.

Installing collected packages: scikit-learn
  Running setup.py install for scikit-learn
    Partial import of sklearn during the build process.
    blas_opt_info:
    blas_mkl_info:
      libraries mkl,vml,guide not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    openblas_info:
      libraries  not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    /usr/lib/python2.7/dist-packages/numpy/distutils/system_info.py:1521: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    blas_info:
      FOUND:
        libraries = ['blas']
        library_dirs = ['/usr/lib']
        language = f77

      FOUND:
        libraries = ['blas']
        library_dirs = ['/usr/lib']
        define_macros = [('NO_ATLAS_INFO', 1)]
        language = f77

    sklearn/setup.py:72: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      warnings.warn(BlasNotFoundError.__doc__)
    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    build_src
    building library "libsvm-skl" sources
    building library "cblas" sources
    building extension "sklearn.__check_build._check_build" sources
    building extension "sklearn.cluster._dbscan_inner" sources
    building extension "sklearn.cluster._hierarchical" sources
    building extension "sklearn.cluster._k_means_elkan" sources
    building extension "sklearn.cluster._k_means" sources
    building extension "sklearn.datasets._svmlight_format" sources
    building extension "sklearn.decomposition._online_lda" sources
    building extension "sklearn.decomposition.cdnmf_fast" sources
    building extension "sklearn.ensemble._gradient_boosting" sources
    building extension "sklearn.feature_extraction._hashing" sources
    building extension "sklearn.manifold._utils" sources
    building extension "sklearn.manifold._barnes_hut_tsne" sources
    building extension "sklearn.metrics.pairwise_fast" sources
    building extension "sklearn.metrics/cluster.expected_mutual_info_fast" sources
    building extension "sklearn.neighbors.ball_tree" sources
    building extension "sklearn.neighbors.kd_tree" sources
    building extension "sklearn.neighbors.dist_metrics" sources
    building extension "sklearn.neighbors.typedefs" sources
    building extension "sklearn.tree._tree" sources
    building extension "sklearn.tree._splitter" sources
    building extension "sklearn.tree._criterion" sources
    building extension "sklearn.tree._utils" sources
    building extension "sklearn.svm.libsvm" sources
    building extension "sklearn.svm.liblinear" sources
    building extension "sklearn.svm.libsvm_sparse" sources
    building extension "sklearn._isotonic" sources
    building extension "sklearn.linear_model.cd_fast" sources
    building extension "sklearn.linear_model.sgd_fast" sources
    building extension "sklearn.linear_model.sag_fast" sources
    building extension "sklearn.utils.sparsetools._traversal" sources
    building extension "sklearn.utils.sparsetools._graph_tools" sources
    building extension "sklearn.utils.sparsefuncs_fast" sources
    building extension "sklearn.utils.arrayfuncs" sources
    building extension "sklearn.utils.murmurhash" sources
    building extension "sklearn.utils.lgamma" sources
    building extension "sklearn.utils.graph_shortest_path" sources
    building extension "sklearn.utils.fast_dict" sources
    building extension "sklearn.utils.seq_dataset" sources
    building extension "sklearn.utils.weight_vector" sources
    building extension "sklearn.utils._random" sources
    building extension "sklearn.utils._logistic_sigmoid" sources
    building data_files sources
    build_src: building npy-pkg config files
    customize UnixCCompiler
    customize UnixCCompiler using build_clib
    building 'libsvm-skl' library
    compiling C++ sources
    C compiler: c++ -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC

    compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -c'
    c++: sklearn/svm/src/libsvm/libsvm_template.cpp
    arm-linux-gnueabihf-gcc-ar: adding 1 object files to build/temp.linux-armv6l-2.7/liblibsvm-skl.a
    building 'cblas' library
    compiling C sources
    C compiler: arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC

    compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -c'
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefasum.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_dcopy.c
    sklearn/src/cblas/cblas_dcopy.c: In function ‘cblas_dcopy’:
    sklearn/src/cblas/cblas_dcopy.c:46:10: warning: implicit declaration of function ‘ATL_drefcopy’ [-Wimplicit-function-declaration]
              if (incY < 0) ATL_dcopy(N, X, -incX, Y, -incY);
              ^
    In file included from sklearn/src/cblas/cblas_dcopy.c:32:0:
    sklearn/src/cblas/cblas_dcopy.c: At top level:
    sklearn/src/cblas/atlas_misc.h:393:12: warning: ‘ATL_AlignOffset’ defined but not used [-Wunused-function]
     static int ATL_AlignOffset
                ^
    sklearn/src/cblas/atlas_misc.h:409:14: warning: ‘ATL_Align2Ptr’ defined but not used [-Wunused-function]
     static void *ATL_Align2Ptr(const void *pu, const void *pA)
                  ^
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_srot.c
    In file included from sklearn/src/cblas/cblas_srot.c:32:0:
    sklearn/src/cblas/atlas_misc.h:393:12: warning: ‘ATL_AlignOffset’ defined but not used [-Wunused-function]
     static int ATL_AlignOffset
                ^
    sklearn/src/cblas/atlas_misc.h:409:14: warning: ‘ATL_Align2Ptr’ defined but not used [-Wunused-function]
     static void *ATL_Align2Ptr(const void *pu, const void *pA)
                  ^
......
......
(還有很多 warning)
......
......
......
    In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
                     from sklearn/utils/_logistic_sigmoid.c:294:
    /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: _import_umath defined but not used [-Wunused-function]
     _import_umath(void)
     ^
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv6l-2.7/sklearn/utils/_logistic_sigmoid.o -Lbuild/temp.linux-armv6l-2.7 -lm -o build/lib.linux-armv6l-2.7/sklearn/utils/_logistic_sigmoid.so

Successfully installed scikit-learn
Cleaning up...

呼! 好久, 但終於成功了.

5.安裝 ipython ipython-notebook :  

pi@raspberrypi:~ $ sudo apt-get install ipython  
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  python-pexpect python-simplegeneric
Suggested packages:
  ipython-doc ipython-notebook ipython-qtconsole python-zmq python-pexpect-doc
The following NEW packages will be installed:
  ipython python-pexpect python-simplegeneric
0 upgraded, 3 newly installed, 0 to remove and 7 not upgraded.
Need to get 667 kB of archives.
After this operation, 3,390 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pexpect all 3.2-1 [38.4 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-simplegeneric all 0.8.1-1 [11.9 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython all 2.3.0-2 [616 kB]
Fetched 667 kB in 7s (88.9 kB/s)
Selecting previously unselected package python-pexpect.
(Reading database ... 126268 files and directories currently installed.)
Preparing to unpack .../python-pexpect_3.2-1_all.deb ...
Unpacking python-pexpect (3.2-1) ...
Selecting previously unselected package python-simplegeneric.
Preparing to unpack .../python-simplegeneric_0.8.1-1_all.deb ...
Unpacking python-simplegeneric (0.8.1-1) ...
Selecting previously unselected package ipython.
Preparing to unpack .../ipython_2.3.0-2_all.deb ...
Unpacking ipython (2.3.0-2) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up python-pexpect (3.2-1) ...
Setting up python-simplegeneric (0.8.1-1) ...
Setting up ipython (2.3.0-2) ...

6.安裝 ipython-notebook :

pi@raspberrypi:~ $ sudo apt-get install ipython-notebook
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  fonts-font-awesome fonts-mathjax ipython-notebook-common libjs-highlight libjs-highlight.js libjs-marked libjs-mathjax
  libjs-underscore libpgm-5.1-0 libsodium13 libzmq3 python-jinja2 python-markupsafe python-mysqldb python-pycurl python-tornado
  python-zmq
Suggested packages:
  python-pygments pandoc pgf fonts-stix fonts-mathjax-extras libjs-mathjax-doc python-jinja2-doc python-egenix-mxdatetime
  python-mysqldb-dbg libcurl4-gnutls-dev python-pycurl-dbg python-pycurl-doc
The following NEW packages will be installed:
  fonts-font-awesome fonts-mathjax ipython-notebook ipython-notebook-common libjs-highlight libjs-highlight.js libjs-marked
  libjs-mathjax libjs-underscore libpgm-5.1-0 libsodium13 libzmq3 python-jinja2 python-markupsafe python-mysqldb python-pycurl
  python-tornado python-zmq
0 upgraded, 18 newly installed, 0 to remove and 18 not upgraded.
Need to get 9,068 kB of archives.
After this operation, 52.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libsodium13 armhf 1.0.0-1 [143 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpgm-5.1-0 armhf 5.1.118-1~dfsg-1 [153 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libzmq3 armhf 4.0.5+dfsg-2+deb8u1 [418 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-font-awesome all 4.2.0~dfsg-1 [346 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-mathjax all 2.4-2 [960 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-highlight.js all 8.2+ds-4 [165 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-highlight all 8.2+ds-4 [22.3 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-marked all 0.3.2+dfsg-1 [12.6 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-mathjax all 2.4-2 [5,333 kB]
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-underscore all 1.7.0~dfsg-1 [49.9 kB]
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython-notebook-common all 2.3.0-2 [724 kB]
Get:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-markupsafe armhf 0.23-1 [15.7 kB]
Get:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-jinja2 all 2.7.3-1 [170 kB]
Get:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pycurl armhf 7.19.5-3 [48.7 kB]
Get:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tornado armhf 3.2.2-1.1 [227 kB]
Get:16 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-zmq armhf 14.4.0-1 [173 kB]
Get:17 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython-notebook all 2.3.0-2 [48.1 kB]
Get:18 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-mysqldb armhf 1.2.3-2.1 [59.2 kB]
Fetched 9,068 kB in 32s (279 kB/s)
Selecting previously unselected package libsodium13:armhf.
(Reading database ... 139736 files and directories currently installed.)
Preparing to unpack .../libsodium13_1.0.0-1_armhf.deb ...
Unpacking libsodium13:armhf (1.0.0-1) ...
Selecting previously unselected package libpgm-5.1-0.
Preparing to unpack .../libpgm-5.1-0_5.1.118-1~dfsg-1_armhf.deb ...
Unpacking libpgm-5.1-0 (5.1.118-1~dfsg-1) ...
Selecting previously unselected package libzmq3:armhf.
Preparing to unpack .../libzmq3_4.0.5+dfsg-2+deb8u1_armhf.deb ...
Unpacking libzmq3:armhf (4.0.5+dfsg-2+deb8u1) ...
Selecting previously unselected package fonts-font-awesome.
Preparing to unpack .../fonts-font-awesome_4.2.0~dfsg-1_all.deb ...
Unpacking fonts-font-awesome (4.2.0~dfsg-1) ...
Selecting previously unselected package fonts-mathjax.
Preparing to unpack .../fonts-mathjax_2.4-2_all.deb ...
Unpacking fonts-mathjax (2.4-2) ...
Selecting previously unselected package libjs-highlight.js.
Preparing to unpack .../libjs-highlight.js_8.2+ds-4_all.deb ...
Unpacking libjs-highlight.js (8.2+ds-4) ...
Selecting previously unselected package libjs-highlight.
Preparing to unpack .../libjs-highlight_8.2+ds-4_all.deb ...
Unpacking libjs-highlight (8.2+ds-4) ...
Selecting previously unselected package libjs-marked.
Preparing to unpack .../libjs-marked_0.3.2+dfsg-1_all.deb ...
Unpacking libjs-marked (0.3.2+dfsg-1) ...
Selecting previously unselected package libjs-mathjax.
Preparing to unpack .../libjs-mathjax_2.4-2_all.deb ...
Unpacking libjs-mathjax (2.4-2) ...
Selecting previously unselected package libjs-underscore.
Preparing to unpack .../libjs-underscore_1.7.0~dfsg-1_all.deb ...
Unpacking libjs-underscore (1.7.0~dfsg-1) ...
Selecting previously unselected package ipython-notebook-common.
Preparing to unpack .../ipython-notebook-common_2.3.0-2_all.deb ...
Unpacking ipython-notebook-common (2.3.0-2) ...
Selecting previously unselected package python-markupsafe.
Preparing to unpack .../python-markupsafe_0.23-1_armhf.deb ...
Unpacking python-markupsafe (0.23-1) ...
Selecting previously unselected package python-jinja2.
Preparing to unpack .../python-jinja2_2.7.3-1_all.deb ...
Unpacking python-jinja2 (2.7.3-1) ...
Selecting previously unselected package python-pycurl.
Preparing to unpack .../python-pycurl_7.19.5-3_armhf.deb ...
Unpacking python-pycurl (7.19.5-3) ...
Selecting previously unselected package python-tornado.
Preparing to unpack .../python-tornado_3.2.2-1.1_armhf.deb ...
Unpacking python-tornado (3.2.2-1.1) ...
Selecting previously unselected package python-zmq.
Preparing to unpack .../python-zmq_14.4.0-1_armhf.deb ...
Unpacking python-zmq (14.4.0-1) ...
Selecting previously unselected package ipython-notebook.
Preparing to unpack .../ipython-notebook_2.3.0-2_all.deb ...
Unpacking ipython-notebook (2.3.0-2) ...
Selecting previously unselected package python-mysqldb.
Preparing to unpack .../python-mysqldb_1.2.3-2.1_armhf.deb ...
Unpacking python-mysqldb (1.2.3-2.1) ...
Processing triggers for fontconfig (2.11.0-6.3+deb8u1) ...
Setting up libsodium13:armhf (1.0.0-1) ...
Setting up libpgm-5.1-0 (5.1.118-1~dfsg-1) ...
Setting up libzmq3:armhf (4.0.5+dfsg-2+deb8u1) ...
Setting up fonts-font-awesome (4.2.0~dfsg-1) ...
Setting up fonts-mathjax (2.4-2) ...
Setting up libjs-highlight.js (8.2+ds-4) ...
Setting up libjs-highlight (8.2+ds-4) ...
Setting up libjs-marked (0.3.2+dfsg-1) ...
Setting up libjs-mathjax (2.4-2) ...
Setting up libjs-underscore (1.7.0~dfsg-1) ...
Setting up ipython-notebook-common (2.3.0-2) ...
Setting up python-markupsafe (0.23-1) ...
Setting up python-jinja2 (2.7.3-1) ...
Setting up python-pycurl (7.19.5-3) ...
Setting up python-tornado (3.2.2-1.1) ...
Setting up python-zmq (14.4.0-1) ...
Setting up ipython-notebook (2.3.0-2) ...
Setting up python-mysqldb (1.2.3-2.1) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...

最後用 pip list 查看已安裝的套件 :

pi@raspberrypi:~ $ pip list
argparse (1.2.1)
beautifulsoup4 (4.3.2)
chardet (2.3.0)
colorama (0.3.2)
decorator (3.4.0)
gpiozero (1.3.2)
html5lib (0.999)
ipython (2.3.0)
joblib (0.8.3)
lxkeymap (0.1)
matplotlib (1.4.2)
mcpi (0.1.1)
mock (1.0.1)
ndg-httpsclient (0.3.2)
nose (1.3.4)
numexpr (2.4)
numpy (1.8.2)
openpyxl (1.7.0)
pandas (0.14.1)
pexpect (3.2)
picamera (1.13)
pifacecommon (4.2.1)
pifacedigitalio (3.1.0)
Pillow (2.6.1)
pip (1.5.6)
pyasn1 (0.1.7)
pygame (1.9.2a0)
pygobject (3.14.0)
pyOpenSSL (0.13.1)
pyparsing (2.0.3)
pyserial (2.6)
python-dateutil (2.2)
pytz (2012c)
requests (2.4.3)
RPi.GPIO (0.6.3)
RTIMULib (7.2.1)
scikit-learn (0.18.1)
scipy (0.14.0)
sense-hat (2.2.0)
setuptools (5.5.1)
simplegeneric (0.8.1)
simplejson (3.6.5)
six (1.8.0)
spidev (3.0)
statsmodels (0.4.2)
tables (3.1.1)
urllib3 (1.9.1)
wheel (0.24.0)
wsgiref (0.1.2)
xlrd (0.9.2)
xlwt (0.7.5)

現在我的樹莓派上不管是 Python2 或 Python3 環境都有 scikit-learn 與相關套件了. 完成後又重新做一次映像檔.


2017年3月23日 星期四

購買樹莓派 Pi 3 與 Pi Zero W

很久沒上露天瞎拚了, 今天只是去看看 Pi 3 有無便宜貨, 還真的剛好找到賣家 tokoma22 庫存出清的英國 RS 公司貨, 出清價 1000 元, 大約比市價便宜 300 元左右, 考慮到若要測試機器學習演算法以及作為智慧家庭伺服主機, 運算效能不能太差, 而手上的五塊樹莓派 (Pi*1, B+*1, A+*1, Zero v1.3*2) 都只有 512MB 記憶體 (A+ 僅 256MB), CPU 速度 700MHz, 跑 Apache 伺服器只是堪用, 所以就決定買兩塊 Pi 3 (高雄與鄉下各一塊) :

# Raspberry Pi 3 Model B 樹莓派開發板 低價出清 $1000 *2=2000

Pi 3 規格參考 :

https://www.raspberrypi.org/products/raspberry-pi-3-model-b/
RASPBERRY PI 3 IS OUT NOW! SPECS, BENCHMARKS & MORE

CPU 採用博通 BCM2837 (1.2Hz ARMv8 Cortex-A53 四核心, 900MHz 1GB DDR2 RAM), 重點是內建 802.11n WiFi 與低功率藍芽 4.1.

為了這兩塊板子, 還向賣家 mogachi 購買兩個外殼 (165*2=330 元含運)  :

# 鎰盛(庫存店-賣完就沒有)-樹莓派主機透明外殼 Raspberry Pi 3B/2B/B+ Case 免運費 $165

另外發現一個代購賣家 a83927b 販售 Pi Zero W, 咦? 怎會有個 W? 原來這是繼 1.3 版增加 Camera 介面後, Zero 推出的第三款新板子, 這個 W 是指 Wireless 之意, 即板上內建 WiFi 與藍芽, 這不就像是精簡版的 Pi 3 (採用相同的 WiFi 晶片) 嗎? 參考 :


賣家說代購一片 Pi Zero W 價格為 795 元但要先匯款給他, 貨品由英國代銷商 Pimoroni 直接寄貨. 這價格比我之前買 Pi Zero v1.3 的 650 貴了 150 元, 但多了無線功能還是很值得的, 參考 :


我上 Pimoroni 查詢, 發現一片 (一次限購一片) 價格為 8 英鎊, 加最便宜的運費 5.5 英鎊總共是 13.5 英鎊, 以今天匯率 38.3 元計算, 折合台幣約 517 元, 所以代購賣家的跑腿費大約是 280 元左右. 我自己 Go 一遍覺得自己買也很方便 (如果有信用卡的話), 流程如下 :


只買 Pi Zero W 一片 (購物車顯示 9.6 英鎊)

不含運費一片 9.6 英鎊

結帳先填寫收件資訊

選擇交運方式 (奇怪變成 8 英鎊了)

總費用 13.5 英鎊 (約台幣 517 元)

選擇付款方式 (輸入信用卡號)

選擇付款地址

按 Complete Order 即可.

不過我實際上還多買了一個 Zero 專用的 PiCam 排線 (4 英鎊, 比我上回露天買的 250 元便宜近一半), 所以總價是 16.83 英鎊 (約台幣 644 元) :



以信用卡付款後, 會寄送一封確認信到郵箱, 貨品則大概要 5-7 天才會寄到. 注意到了嗎? 放到購物車時還是 9.6 英鎊, 結帳時卻突然變成 8 英鎊, 真奇怪. 

2017-03-31 補充 :

昨天 3/30 收到貨品了, 剛好是七天到貨, 透過英國皇家郵政空運 :


跟之前買的 Pi Zero v1.3 (前面) 相比, 主要是多了一顆 WiFi+BT 的小晶片 (黃色方框) :



2017年3月22日 星期三

樹莓派安裝 Python3 scikit-learn 函式庫

最近在樹莓派運算平台的使用上日漸上手之後開始研究機器學習, 這是人工智慧最重要的分支, 相關的工具與技術已日趨成熟 (但仍在高速發展中), 也早已實作於例如資訊安全, 資料採礦, 機器人, 自駕車, 無人機, 智慧家居, 語音識別, 影像識別, 甚至財務工程等許多大數據應用中. 因為這門資料科學牽涉機率與統計, 微積分, 線性代數等數學, 而我的數學底子淺, 沒辦法從理論著手, 所以只能從實作切入後再徐圖之.

目前機器學習主流的程式工具是 Python 與 R 語言, 現在是 R 語言佔上風, 但我覺得 Python 潛力較大, 因為它的應用範圍比 R 要廣多了. 由於樹莓派是可 24 小時開機的低功耗 (約 1.5W, Pi 3 約 3W, A+ 最低僅 0.85W) 嵌入式運算器, 很適合作為不眠不休的資料採礦機器, 所以我選擇樹莓派 Type B 跑 Raspbian 作業系統作為測試環境, 除了之前已安裝的 R 語言外, 還需要安裝 Python 的機器學習函式庫 Scikit-learn. 我的最終目的是要以樹莓派作為物聯網的運算平台, 利用機器學習為物聯網設備裝上智慧的大腦.

Python 部分我主要參考下面這幾本書 :

Python Machine Learning (Sebastian Raschka, 2015)
# Introduction to Machine Learning with Python (Andreas C. Müller & Sarah Guido, 2016)
Learning scikit-learn Machine Learning in Python (Raúl Garreta; Guillermo Moncecchi, PACKT 2013 )

Python 的機器學習函式庫 scikit-learn 是建立在 numpy 與 scipy 這兩個函式庫上, 因此必須先安裝這兩個函式庫後才能安裝 scikit-learn. 其次為了要將資料視覺化 (Visualization) 以繪製各種統計圖形, 也需要安裝 matplotlib 函式庫; 另外還要安裝可處理 Table 的 Pandas 函式庫. 書裡面也建議安裝 Jupyter (又稱為 IPython Notebook) 互動式執行環境來取代 Python IDLE, 但我的樹莓派 Type B 跑瀏覽器效能差強人意, 所以不一定要裝 (若是 Pi 2 或 Pi 3 應該沒問題). 以上與 scikit-learn 套件相關的函式庫表列如下 :

 函式庫 用途說明
 numpy Python 基本科學計算套件 (線性代數, 多維矩陣, 傅立葉轉換, 偽隨機數產生等)
 scipy Python 科學計算套件集 (高等線性代數, 函數優化, 信號處理, 統計分布等)
 matplotlib Python 科學繪圖套件 (各式統計圖表)
 Jupyter Python 網頁式互動執行環境 (IPython Notebook)
 pandas Python 資料角力套件 (處理 Table 資料)

以下紀錄這兩天安裝上列函式庫的過程, 並參考 "Introduction to Machine Learning with Python" 這本書第一章的範例程式測試所安裝的函式庫是否正常運作. 上列函式庫都使用 apt-get 指令安裝, 唯有 scikit-learn 是使用 Python 3 版的 pip3 安裝 :
  1. sudo apt-get install python3-numpy
  2. sudo apt-get install python3-scipy
  3. sudo apt-get install python3-matplotlib
  4. sudo apt-get install python3-pandas
  5. sudo pip3 install scikit-learn -U
1. 安裝 numpy :

pi@raspberrypi:~ $ sudo apt-get install python3-numpy
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-numpy is already the newest version.
The following packages were automatically installed and are no longer required:
  libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
  libkrb5-26-heimdal libroken18-heimdal libwind0-heimdal libxfce4ui-1-0 xfce-keyboard-shortcuts
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.

因為此 Raspbian 為 2017 年 Jessie(pixel), 已經內建最新的 Numpy, 所以不用再安裝.

測試程式 : numpy_test.py
import numpy as np
x = np.array([[1, 2, 3], [4, 5, 6]])
print("x:\n{}".format(x))

執行結果 :

$ numpy_test.py
x:
[[1 2 3]
 [4 5 6]]


2. 安裝 scipy :

pi@raspberrypi:~ $ sudo apt-get install python3-scipy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
  libkrb5-26-heimdal libroken18-heimdal libwind0-heimdal libxfce4ui-1-0 xfce-keyboard-shortcuts
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  python3-decorator
The following NEW packages will be installed:
  python3-decorator python3-scipy
0 upgraded, 2 newly installed, 0 to remove and 17 not upgraded.
Need to get 7,014 kB of archives.
After this operation, 24.6 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
  python3-decorator python3-scipy
Install these packages without verification? [y/N] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-decorator all 3.4.0-2 [22.5 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-scipy armhf 0.14.0-2 [6,992 kB]
Fetched 7,014 kB in 34s (202 kB/s)
Selecting previously unselected package python3-decorator.
(Reading database ... 134211 files and directories currently installed.)
Preparing to unpack .../python3-decorator_3.4.0-2_all.deb ...
Unpacking python3-decorator (3.4.0-2) ...
Selecting previously unselected package python3-scipy.
Preparing to unpack .../python3-scipy_0.14.0-2_armhf.deb ...
Unpacking python3-scipy (0.14.0-2) ...
Setting up python3-decorator (3.4.0-2) ...
Setting up python3-scipy (0.14.0-2) ...

測試程式 : scipy_test.py
import numpy as np
from scipy import sparse
# Create a 2D NumPy array with a diagonal of ones, and zeros everywhere else
eye = np.eye(4)
print("NumPy array:\n{}".format(eye))

執行結果 :
$python scipy_test.py
NumPy array:
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]]

3. 安裝 matplotlib : 

pi@raspberrypi:~ $ sudo apt-get install python3-matplotlib
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
  libkrb5-26-heimdal libroken18-heimdal libwind0-heimdal libxfce4ui-1-0 xfce-keyboard-shortcuts
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  fonts-lyx libjs-jquery-ui python-matplotlib-data python3-dateutil python3-nose python3-pyparsing python3-tz
Suggested packages:
  libjs-jquery-ui-docs dvipng ghostscript inkscape ipython3 python-matplotlib-doc python3-cairocffi python3-gi python3-gi-cairo
  python3-gobject python3-pyqt4 python3-sip python3-tornado texlive-extra-utils texlive-latex-extra ttf-staypuft python-nose-doc
The following NEW packages will be installed:
  fonts-lyx libjs-jquery-ui python-matplotlib-data python3-dateutil python3-matplotlib python3-nose python3-pyparsing python3-tz
0 upgraded, 8 newly installed, 0 to remove and 17 not upgraded.
Need to get 7,601 kB of archives.
After this operation, 22.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
  fonts-lyx libjs-jquery-ui python-matplotlib-data python3-dateutil python3-pyparsing python3-tz python3-nose python3-matplotlib
Install these packages without verification? [y/N] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-lyx all 2.1.2-2 [176 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-jquery-ui all 1.10.1+dfsg-1 [499 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-matplotlib-data all 1.4.2-3.1 [3,041 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-dateutil all 2.2-2 [33.2 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-pyparsing all 2.0.3+dfsg1-1 [64.1 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-tz all 2012c+dfsg-0.1 [25.4 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-nose all 1.3.4-1 [131 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-matplotlib armhf 1.4.2-3.1 [3,631 kB]
Fetched 7,601 kB in 15s (500 kB/s)
Selecting previously unselected package fonts-lyx.
(Reading database ... 135005 files and directories currently installed.)
Preparing to unpack .../fonts-lyx_2.1.2-2_all.deb ...
Unpacking fonts-lyx (2.1.2-2) ...
Selecting previously unselected package libjs-jquery-ui.
Preparing to unpack .../libjs-jquery-ui_1.10.1+dfsg-1_all.deb ...
Unpacking libjs-jquery-ui (1.10.1+dfsg-1) ...
Selecting previously unselected package python-matplotlib-data.
Preparing to unpack .../python-matplotlib-data_1.4.2-3.1_all.deb ...
Unpacking python-matplotlib-data (1.4.2-3.1) ...
Selecting previously unselected package python3-dateutil.
Preparing to unpack .../python3-dateutil_2.2-2_all.deb ...
Unpacking python3-dateutil (2.2-2) ...
Selecting previously unselected package python3-pyparsing.
Preparing to unpack .../python3-pyparsing_2.0.3+dfsg1-1_all.deb ...
Unpacking python3-pyparsing (2.0.3+dfsg1-1) ...
Selecting previously unselected package python3-tz.
Preparing to unpack .../python3-tz_2012c+dfsg-0.1_all.deb ...
Unpacking python3-tz (2012c+dfsg-0.1) ...
Selecting previously unselected package python3-nose.
Preparing to unpack .../python3-nose_1.3.4-1_all.deb ...
Unpacking python3-nose (1.3.4-1) ...
Selecting previously unselected package python3-matplotlib.
Preparing to unpack .../python3-matplotlib_1.4.2-3.1_armhf.deb ...
Unpacking python3-matplotlib (1.4.2-3.1) ...
Processing triggers for fontconfig (2.11.0-6.3+deb8u1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up fonts-lyx (2.1.2-2) ...
Setting up libjs-jquery-ui (1.10.1+dfsg-1) ...
Setting up python-matplotlib-data (1.4.2-3.1) ...
Setting up python3-dateutil (2.2-2) ...
Setting up python3-pyparsing (2.0.3+dfsg1-1) ...
Setting up python3-tz (2012c+dfsg-0.1) ...
Setting up python3-nose (1.3.4-1) ...
Setting up python3-matplotlib (1.4.2-3.1) ...

測試程式 : matplotlib_test.py
import numpy as np
import matplotlib.pyplot as plt
# Generate a sequence of numbers from -10 to 10 with 100 steps in between
x = np.linspace(-10, 10, 100)
# Create a second array using sine
y = np.sin(x)
# The plot function makes a line chart of one array against another
plt.plot(x, y, marker="x")
plt.show()

$python3 matplotlib_test.py


注意, matplotlib 一定要在桌面開啟 LXTerminal, 然後執行 python3 matplotlib_test.py 才會顯示, 若用 Putty 以 SSH 遠端存取執行不會顯示結果, 因為 Putty 是文字模式. 我是利用 VNC 遠端桌面執行. 另外, 最後一行要加上 plt.show() 才會在螢幕上顯示圖形, 原書中無此指令, 結果執行後也是沒有動靜.


4. 安裝 pandas : 

pi@raspberrypi:~ $ sudo apt-get install python3-pandas
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  python3-bs4 python3-lxml python3-numexpr python3-pandas-lib python3-tables python3-tables-lib
Suggested packages:
  python3-lxml-dbg python-pandas-doc python-tables-doc python-netcdf vitables
The following NEW packages will be installed:
  python3-bs4 python3-lxml python3-numexpr python3-pandas python3-pandas-lib python3-tables python3-tables-lib
0 upgraded, 7 newly installed, 0 to remove and 18 not upgraded.
Need to get 3,960 kB of archives.
After this operation, 21.0 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-bs4 all 4.3.2-2 [77.6 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-lxml armhf 3.4.0-1 [680 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-numexpr armhf 2.4-1 [143 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-pandas-lib armhf 0.14.1-2 [1,176 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-pandas all 0.14.1-2 [1,249 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-tables-lib armhf 3.1.1-3+b1 [305 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main python3-tables all 3.1.1-3 [329 kB]
Fetched 3,960 kB in 9s (407 kB/s)
Selecting previously unselected package python3-bs4.
(Reading database ... 144728 files and directories currently installed.)
Preparing to unpack .../python3-bs4_4.3.2-2_all.deb ...
Unpacking python3-bs4 (4.3.2-2) ...
Selecting previously unselected package python3-lxml.
Preparing to unpack .../python3-lxml_3.4.0-1_armhf.deb ...
Unpacking python3-lxml (3.4.0-1) ...
Selecting previously unselected package python3-numexpr.
Preparing to unpack .../python3-numexpr_2.4-1_armhf.deb ...
Unpacking python3-numexpr (2.4-1) ...
Selecting previously unselected package python3-pandas-lib.
Preparing to unpack .../python3-pandas-lib_0.14.1-2_armhf.deb ...
Unpacking python3-pandas-lib (0.14.1-2) ...
Selecting previously unselected package python3-pandas.
Preparing to unpack .../python3-pandas_0.14.1-2_all.deb ...
Unpacking python3-pandas (0.14.1-2) ...
Selecting previously unselected package python3-tables-lib.
Preparing to unpack .../python3-tables-lib_3.1.1-3+b1_armhf.deb ...
Unpacking python3-tables-lib (3.1.1-3+b1) ...
Selecting previously unselected package python3-tables.
Preparing to unpack .../python3-tables_3.1.1-3_all.deb ...
Unpacking python3-tables (3.1.1-3) ...
Setting up python3-bs4 (4.3.2-2) ...
Setting up python3-lxml (3.4.0-1) ...
Setting up python3-numexpr (2.4-1) ...
Setting up python3-pandas-lib (0.14.1-2) ...
Setting up python3-pandas (0.14.1-2) ...
Setting up python3-tables-lib (3.1.1-3+b1) ...
Setting up python3-tables (3.1.1-3) ...

測試程式 : pandas_test.py
import pandas as pd
# create a simple dataset of people
data = {'Name': ["John", "Anna", "Peter", "Linda"],
'Location' : ["New York", "Paris", "Berlin", "London"],
'Age' : [24, 13, 53, 33]
}
data_pandas = pd.DataFrame(data)
# IPython.display allows "pretty printing" of dataframes
# in the Jupyter notebook
display(data_pandas)

輸出 :

pi@raspberrypi:~ $ python pandas_test.py
Traceback (most recent call last):
  File "pandas_test.py", line 10, in
    display(data_pandas)
NameError: name 'display' is not defined

不知為何 display() 有問題. 


5. 安裝 scikit-learn :

pi@raspberrypi:~ $ sudo pip3 install scikit-learn -U
Downloading/unpacking scikit-learn
  Downloading scikit-learn-0.18.1.tar.gz (8.9MB): 8.9MB downloaded
  Running setup.py (path:/tmp/pip-build-y7_c22sq/scikit-learn/setup.py) egg_info for package scikit-learn
    Partial import of sklearn during the build process.

Installing collected packages: scikit-learn
  Running setup.py install for scikit-learn
    blas_opt_info:
    blas_mkl_info:
      libraries mkl,vml,guide not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    openblas_info:
      libraries  not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    atlas_blas_threads_info:
    Setting PTATLAS=ATLAS
      libraries ptf77blas,ptcblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    atlas_blas_info:
      libraries f77blas,cblas,atlas not found in ['/usr/local/lib', '/usr/lib', '/usr/lib/arm-linux-gnueabihf']
      NOT AVAILABLE

    blas_info:
      FOUND:
        language = f77
        library_dirs = ['/usr/lib']
        libraries = ['blas']

      FOUND:
        define_macros = [('NO_ATLAS_INFO', 1)]
        language = f77
        library_dirs = ['/usr/lib']
        libraries = ['blas']

    unifing config_cc, config, build_clib, build_ext, build commands --compiler options
    unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
    build_src
    building library "libsvm-skl" sources
    building library "cblas" sources
    building extension "sklearn.__check_build._check_build" sources
    building extension "sklearn.cluster._dbscan_inner" sources
    building extension "sklearn.cluster._hierarchical" sources
    building extension "sklearn.cluster._k_means_elkan" sources
    building extension "sklearn.cluster._k_means" sources
    building extension "sklearn.datasets._svmlight_format" sources
    building extension "sklearn.decomposition._online_lda" sources
    building extension "sklearn.decomposition.cdnmf_fast" sources
    building extension "sklearn.ensemble._gradient_boosting" sources
    building extension "sklearn.feature_extraction._hashing" sources
    building extension "sklearn.manifold._utils" sources
    building extension "sklearn.manifold._barnes_hut_tsne" sources
    building extension "sklearn.metrics.pairwise_fast" sources
    building extension "sklearn.metrics/cluster.expected_mutual_info_fast" sources
    building extension "sklearn.neighbors.ball_tree" sources
    building extension "sklearn.neighbors.kd_tree" sources
    building extension "sklearn.neighbors.dist_metrics" sources
    building extension "sklearn.neighbors.typedefs" sources
    building extension "sklearn.tree._tree" sources
    building extension "sklearn.tree._splitter" sources
    building extension "sklearn.tree._criterion" sources
    building extension "sklearn.tree._utils" sources
    building extension "sklearn.svm.libsvm" sources
    building extension "sklearn.svm.liblinear" sources
    building extension "sklearn.svm.libsvm_sparse" sources
    building extension "sklearn._isotonic" sources
    building extension "sklearn.linear_model.cd_fast" sources
    building extension "sklearn.linear_model.sgd_fast" sources
    building extension "sklearn.linear_model.sag_fast" sources
    building extension "sklearn.utils.sparsetools._traversal" sources
    building extension "sklearn.utils.sparsetools._graph_tools" sources
    building extension "sklearn.utils.sparsefuncs_fast" sources
    building extension "sklearn.utils.arrayfuncs" sources
    building extension "sklearn.utils.murmurhash" sources
    building extension "sklearn.utils.lgamma" sources
    building extension "sklearn.utils.graph_shortest_path" sources
    building extension "sklearn.utils.fast_dict" sources
    building extension "sklearn.utils.seq_dataset" sources
    building extension "sklearn.utils.weight_vector" sources
    building extension "sklearn.utils._random" sources
    building extension "sklearn.utils._logistic_sigmoid" sources
    building data_files sources
    build_src: building npy-pkg config files
    customize UnixCCompiler
    customize UnixCCompiler using build_clib
    building 'libsvm-skl' library
    compiling C++ sources
    C compiler: arm-linux-gnueabihf-g++ -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC

    compile options: '-I/usr/lib/python3/dist-packages/numpy/core/include -c'
    arm-linux-gnueabihf-g++: sklearn/svm/src/libsvm/libsvm_template.cpp
    arm-linux-gnueabihf-gcc-ar: adding 1 object files to build/temp.linux-armv6l-3.4/liblibsvm-skl.a
    building 'cblas' library
    compiling C sources
    C compiler: arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC

    compile options: '-I/usr/lib/python3/dist-packages/numpy/core/include -c'
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_daxpy.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefasum.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_srefrotg.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_ddot.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefcopy.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_errprn.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_srefrot.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefrotg.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_srot.c
    In file included from sklearn/src/cblas/cblas_srot.c:32:0:
    sklearn/src/cblas/atlas_misc.h:393:12: warning: ‘ATL_AlignOffset’ defined but not used [-Wunused-function]
     static int ATL_AlignOffset
                ^
    sklearn/src/cblas/atlas_misc.h:409:14: warning: ‘ATL_Align2Ptr’ defined but not used [-Wunused-function]
     static void *ATL_Align2Ptr(const void *pu, const void *pA)
                  ^
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefgemvT.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_drefrot.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_xerbla.c
    sklearn/src/cblas/cblas_xerbla.c: In function ‘cblas_xerbla’:
    sklearn/src/cblas/cblas_xerbla.c:52:4: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
        exit(-1);
        ^
    sklearn/src/cblas/cblas_xerbla.c:52:4: warning: incompatible implicit declaration of built-in function ‘exit’
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_srefcopy.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/ATL_dsrefdot.c
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_dger.c
    sklearn/src/cblas/cblas_dger.c: In function ‘cblas_dger’:
    sklearn/src/cblas/cblas_dger.c:73:7: warning: implicit declaration of function ‘cblas_xerbla’ [-Wimplicit-function-declaration]
           cblas_xerbla(info, "cblas_dger", "");
           ^
    In file included from sklearn/src/cblas/cblas_dger.c:32:0:
    sklearn/src/cblas/cblas_dger.c: At top level:
    sklearn/src/cblas/atlas_misc.h:393:12: warning: ‘ATL_AlignOffset’ defined but not used [-Wunused-function]
     static int ATL_AlignOffset
                ^
    sklearn/src/cblas/atlas_misc.h:409:14: warning: ‘ATL_Align2Ptr’ defined but not used [-Wunused-function]
     static void *ATL_Align2Ptr(const void *pu, const void *pA)
                  ^
    arm-linux-gnueabihf-gcc: sklearn/src/cblas/cblas_sasum.c
    In file included from sklearn/src/cblas/cblas_sasum.c:32:0:
    sklearn/src/cblas/atlas_misc.h:393:12: warning: ‘ATL_AlignOffset’ defined but not used [-Wunused-function]
     static int ATL_AlignOffset
                ^
......
(很多 warning)
......

    /usr/lib/python3/dist-packages/numpy/core/include/numpy/__multiarray_api.h:1629:1: warning: ‘_import_array’ defined but not used [-Wunused-function]
     _import_array(void)
     ^
    In file included from /usr/lib/python3/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
                     from sklearn/utils/_logistic_sigmoid.c:294:
    /usr/lib/python3/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: ‘_import_umath’ defined but not used [-Wunused-function]
     _import_umath(void)
     ^
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-armv6l-3.4/sklearn/utils/_logistic_sigmoid.o -Lbuild/temp.linux-armv6l-3.4 -lm -o build/lib.linux-armv6l-3.4/sklearn/utils/_logistic_sigmoid.cpython-34m.so

    Partial import of sklearn during the build process.
    /usr/lib/python3/dist-packages/numpy/distutils/system_info.py:1521: UserWarning:
        Atlas (http://math-atlas.sourceforge.net/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [atlas]) or by setting
        the ATLAS environment variable.
      warnings.warn(AtlasNotFoundError.__doc__)
    sklearn/setup.py:72: UserWarning:
        Blas (http://www.netlib.org/blas/) libraries not found.
        Directories to search for the libraries can be specified in the
        numpy/distutils/site.cfg file (section [blas]) or by setting
        the BLAS environment variable.
      warnings.warn(BlasNotFoundError.__doc__)
Successfully installed scikit-learn
Cleaning up...

安裝了好久 (在 Type B 大約跑了 2 小時) 終於完成了. 

測試程式 : scikit_learn_test.py
from sklearn.datasets import load_iris
iris_dataset = load_iris()
print("Keys of iris_dataset: \n{}".format(iris_dataset.keys()))

輸出 :

Keys of iris_dataset:
['target_names', 'data', 'target', 'DESCR', 'feature_names']

6. 安裝 ipython3 :

pi@raspberrypi:~ $ sudo apt-get install ipython3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libasn1-8-heimdal libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
  libkrb5-26-heimdal libroken18-heimdal libwind0-heimdal libxfce4ui-1-0 xfce-keyboard-shortcuts
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  python-decorator python-pexpect python-simplegeneric
Suggested packages:
  ipython-doc ipython-notebook ipython-qtconsole python-matplotlib python-zmq python-pexpect-doc
The following NEW packages will be installed:
  ipython python-decorator python-pexpect python-simplegeneric
0 upgraded, 4 newly installed, 0 to remove and 17 not upgraded.
Need to get 689 kB of archives.
After this operation, 3,499 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
WARNING: The following packages cannot be authenticated!
  python-decorator python-pexpect python-simplegeneric ipython
Install these packages without verification? [y/N] y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-decorator all 3.4.0-2 [22.3 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pexpect all 3.2-1 [38.4 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-simplegeneric all 0.8.1-1 [11.9 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython all 2.3.0-2 [616 kB]
Fetched 689 kB in 3s (185 kB/s)
Selecting previously unselected package python-decorator.
(Reading database ... 135931 files and directories currently installed.)
Preparing to unpack .../python-decorator_3.4.0-2_all.deb ...
Unpacking python-decorator (3.4.0-2) ...
Selecting previously unselected package python-pexpect.
Preparing to unpack .../python-pexpect_3.2-1_all.deb ...
Unpacking python-pexpect (3.2-1) ...
Selecting previously unselected package python-simplegeneric.
Preparing to unpack .../python-simplegeneric_0.8.1-1_all.deb ...
Unpacking python-simplegeneric (0.8.1-1) ...
Selecting previously unselected package ipython.
Preparing to unpack .../ipython_2.3.0-2_all.deb ...
Unpacking ipython (2.3.0-2) ...
Processing triggers for gnome-menus (3.13.3-6) ...
Processing triggers for desktop-file-utils (0.22-1) ...
Processing triggers for mime-support (3.58) ...
Processing triggers for hicolor-icon-theme (0.13-1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up python-decorator (3.4.0-2) ...
Setting up python-pexpect (3.2-1) ...
Setting up python-simplegeneric (0.8.1-1) ...
Setting up ipython (2.3.0-2) ...

7. 安裝 ipython3-notebook :

pi@raspberrypi:~ $ sudo apt-get install ipython3-notebook
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  fonts-font-awesome fonts-mathjax ipython-notebook-common libjs-highlight libjs-highlight.js libjs-marked libjs-mathjax
  libjs-underscore libpgm-5.1-0 libsodium13 libzmq3 python-jinja2 python-markupsafe python-mysqldb python-pycurl python-tornado
  python-zmq
Suggested packages:
  python-pygments pandoc pgf fonts-stix fonts-mathjax-extras libjs-mathjax-doc python-jinja2-doc python-egenix-mxdatetime
  python-mysqldb-dbg libcurl4-gnutls-dev python-pycurl-dbg python-pycurl-doc
The following NEW packages will be installed:
  fonts-font-awesome fonts-mathjax ipython-notebook ipython-notebook-common libjs-highlight libjs-highlight.js libjs-marked
  libjs-mathjax libjs-underscore libpgm-5.1-0 libsodium13 libzmq3 python-jinja2 python-markupsafe python-mysqldb python-pycurl
  python-tornado python-zmq
0 upgraded, 18 newly installed, 0 to remove and 18 not upgraded.
Need to get 9,068 kB of archives.
After this operation, 52.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main libsodium13 armhf 1.0.0-1 [143 kB]
Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main libpgm-5.1-0 armhf 5.1.118-1~dfsg-1 [153 kB]
Get:3 http://mirrordirector.raspbian.org/raspbian/ jessie/main libzmq3 armhf 4.0.5+dfsg-2+deb8u1 [418 kB]
Get:4 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-font-awesome all 4.2.0~dfsg-1 [346 kB]
Get:5 http://mirrordirector.raspbian.org/raspbian/ jessie/main fonts-mathjax all 2.4-2 [960 kB]
Get:6 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-highlight.js all 8.2+ds-4 [165 kB]
Get:7 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-highlight all 8.2+ds-4 [22.3 kB]
Get:8 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-marked all 0.3.2+dfsg-1 [12.6 kB]
Get:9 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-mathjax all 2.4-2 [5,333 kB]
Get:10 http://mirrordirector.raspbian.org/raspbian/ jessie/main libjs-underscore all 1.7.0~dfsg-1 [49.9 kB]
Get:11 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython-notebook-common all 2.3.0-2 [724 kB]
Get:12 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-markupsafe armhf 0.23-1 [15.7 kB]
Get:13 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-jinja2 all 2.7.3-1 [170 kB]
Get:14 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-pycurl armhf 7.19.5-3 [48.7 kB]
Get:15 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-tornado armhf 3.2.2-1.1 [227 kB]
Get:16 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-zmq armhf 14.4.0-1 [173 kB]
Get:17 http://mirrordirector.raspbian.org/raspbian/ jessie/main ipython-notebook all 2.3.0-2 [48.1 kB]
Get:18 http://mirrordirector.raspbian.org/raspbian/ jessie/main python-mysqldb armhf 1.2.3-2.1 [59.2 kB]
Fetched 9,068 kB in 32s (279 kB/s)
Selecting previously unselected package libsodium13:armhf.
(Reading database ... 139736 files and directories currently installed.)
Preparing to unpack .../libsodium13_1.0.0-1_armhf.deb ...
Unpacking libsodium13:armhf (1.0.0-1) ...
Selecting previously unselected package libpgm-5.1-0.
Preparing to unpack .../libpgm-5.1-0_5.1.118-1~dfsg-1_armhf.deb ...
Unpacking libpgm-5.1-0 (5.1.118-1~dfsg-1) ...
Selecting previously unselected package libzmq3:armhf.
Preparing to unpack .../libzmq3_4.0.5+dfsg-2+deb8u1_armhf.deb ...
Unpacking libzmq3:armhf (4.0.5+dfsg-2+deb8u1) ...
Selecting previously unselected package fonts-font-awesome.
Preparing to unpack .../fonts-font-awesome_4.2.0~dfsg-1_all.deb ...
Unpacking fonts-font-awesome (4.2.0~dfsg-1) ...
Selecting previously unselected package fonts-mathjax.
Preparing to unpack .../fonts-mathjax_2.4-2_all.deb ...
Unpacking fonts-mathjax (2.4-2) ...
Selecting previously unselected package libjs-highlight.js.
Preparing to unpack .../libjs-highlight.js_8.2+ds-4_all.deb ...
Unpacking libjs-highlight.js (8.2+ds-4) ...
Selecting previously unselected package libjs-highlight.
Preparing to unpack .../libjs-highlight_8.2+ds-4_all.deb ...
Unpacking libjs-highlight (8.2+ds-4) ...
Selecting previously unselected package libjs-marked.
Preparing to unpack .../libjs-marked_0.3.2+dfsg-1_all.deb ...
Unpacking libjs-marked (0.3.2+dfsg-1) ...
Selecting previously unselected package libjs-mathjax.
Preparing to unpack .../libjs-mathjax_2.4-2_all.deb ...
Unpacking libjs-mathjax (2.4-2) ...
Selecting previously unselected package libjs-underscore.
Preparing to unpack .../libjs-underscore_1.7.0~dfsg-1_all.deb ...
Unpacking libjs-underscore (1.7.0~dfsg-1) ...
Selecting previously unselected package ipython-notebook-common.
Preparing to unpack .../ipython-notebook-common_2.3.0-2_all.deb ...
Unpacking ipython-notebook-common (2.3.0-2) ...
Selecting previously unselected package python-markupsafe.
Preparing to unpack .../python-markupsafe_0.23-1_armhf.deb ...
Unpacking python-markupsafe (0.23-1) ...
Selecting previously unselected package python-jinja2.
Preparing to unpack .../python-jinja2_2.7.3-1_all.deb ...
Unpacking python-jinja2 (2.7.3-1) ...
Selecting previously unselected package python-pycurl.
Preparing to unpack .../python-pycurl_7.19.5-3_armhf.deb ...
Unpacking python-pycurl (7.19.5-3) ...
Selecting previously unselected package python-tornado.
Preparing to unpack .../python-tornado_3.2.2-1.1_armhf.deb ...
Unpacking python-tornado (3.2.2-1.1) ...
Selecting previously unselected package python-zmq.
Preparing to unpack .../python-zmq_14.4.0-1_armhf.deb ...
Unpacking python-zmq (14.4.0-1) ...
Selecting previously unselected package ipython-notebook.
Preparing to unpack .../ipython-notebook_2.3.0-2_all.deb ...
Unpacking ipython-notebook (2.3.0-2) ...
Selecting previously unselected package python-mysqldb.
Preparing to unpack .../python-mysqldb_1.2.3-2.1_armhf.deb ...
Unpacking python-mysqldb (1.2.3-2.1) ...
Processing triggers for fontconfig (2.11.0-6.3+deb8u1) ...
Setting up libsodium13:armhf (1.0.0-1) ...
Setting up libpgm-5.1-0 (5.1.118-1~dfsg-1) ...
Setting up libzmq3:armhf (4.0.5+dfsg-2+deb8u1) ...
Setting up fonts-font-awesome (4.2.0~dfsg-1) ...
Setting up fonts-mathjax (2.4-2) ...
Setting up libjs-highlight.js (8.2+ds-4) ...
Setting up libjs-highlight (8.2+ds-4) ...
Setting up libjs-marked (0.3.2+dfsg-1) ...
Setting up libjs-mathjax (2.4-2) ...
Setting up libjs-underscore (1.7.0~dfsg-1) ...
Setting up ipython-notebook-common (2.3.0-2) ...
Setting up python-markupsafe (0.23-1) ...
Setting up python-jinja2 (2.7.3-1) ...
Setting up python-pycurl (7.19.5-3) ...
Setting up python-tornado (3.2.2-1.1) ...
Setting up python-zmq (14.4.0-1) ...
Setting up ipython-notebook (2.3.0-2) ...
Setting up python-mysqldb (1.2.3-2.1) ...
Processing triggers for libc-bin (2.19-18+deb8u7) ...

這樣終於完成 scikit-learn 機器學習相關套件的安裝了.

值得一提的是, 由於我的樹莓派同時安裝了 python 2 與 3 版, 位置分別在 /usr/bin/python2 與 /usr/bin/python3, 要如何切換實際執行的 Python 解譯器版本呢? 這可以用 alias 或 link 來切換 :

pi@raspberrypi:~ $ python --version
Python 2.7.9
pi@raspberrypi:~ $ alias python='/usr/bin/python3'
pi@raspberrypi:~ $ python --version
Python 3.4.2
pi@raspberrypi:~ $ alias python='/usr/bin/python2'
pi@raspberrypi:~ $ python --version
Python 2.7.9

或者使用下列指令也可以 :

pi@raspberrypi:~ $ ln -s python /usr/bin/python3
pi@raspberrypi:~ $ ln -s python /usr/bin/python2

如上所述, 由於我不打算在樹莓派中使用 IPython, 所以我只安裝到 scikit-learn 而已, 馬上用 Win32DiskImager 製作映像檔, 免得萬一系統崩潰又要花很多時間重來一遍.

參考 :

# How can I run python scikit-learn on Raspberry Pi?
# What is the difference between installing a package using pip vs. apt-get?
# apt-get install vs pip install
Linux下切换Python2和Python3的4种方法
IPython :一個交互式計算和開發環境
# IPython Notebook 初探
# Copy current SD image to larger SD card
# Installing Scipy
# scikit-learn的安装和基本使用教程
different ways to get scikit-learn installed
# IPython Notebook 初探
# Install numpy on python3.3 - Install pip for python3
# How to install numpy on windows using pip install?