LoginSignup
17
21

More than 5 years have passed since last update.

Pythonで機械学習するための環境を構築してみた(MacOS X)

Last updated at Posted at 2015-02-01

先日のCROSS2015のpythonセッションにて機械学習って面白そうじゃんと思い、とりあえず環境周りを整えてみたので、めもです。

先日のCROSS2015の記事はコチラです。

:black_square_button: 概要

  • pythonで機械学習ができる環境を構築すること
  • 大したことやってないのでQiitaにあげる必要ないかなと思いつつ、個人的に色々ハマったので、一応あげます。

:black_square_button: 前提

  • MacOS X

:black_square_button: もろもろのインストール

  • Python
    
    $ brew update
    $ brew upgrade
    $ brew install python
    

一応、バージョン確認


$ python -V 
Python 2.7.5

pip


$ pip install --upgrade setuptools
$ pip install --upgrade pip

.bash_profileにパスを設定。忘れてた。。
これをやらないと、scikit-learnをインポートする際に下記のエラーが出る。

ImportError: No module named sklearn

っていうことで.bash_profileにパスを追加。


export PATH=/usr/local/bin:$PATH
export PATH=/usr/local/share/python:$PATH

上記を.bash_profileに追加したら、更新。


source ~/.bash_profile
  • もろもろの数学系ライブラリをインストール
    
    $ pip install numpy
    $ pip install scipy
    $ pip install matplotlib
    $ pip install scikit-learn
    $ pip install pandas
    $ pip install pydot
    $ pip install rpy2
    $ pip install ipython
    $ pip install pyzmq
    $ pip install tornado
    $ pip install jinja2
    

rpy2をインストールする際に下記のエラーに出くわした。


$ pip install rpy2
Collecting rpy2
  Using cached rpy2-2.5.5.tar.gz
    Error: Tried to guess R's HOME but no R command in the PATH.
    Complete output from command python setup.py egg_info:
    Error: Tried to guess R's HOME but no R command in the PATH.

    ----------------------------------------
    Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/jl/h7wk98516f1_tj7zg87r08b00000gn/T/pip-build-Cs7fDa/rpy2

Rをインストールしていないからですね。。そりゃそうや。。
MacOSXにRをインストールする方法は下記を参考にしました。ありがたや。ありがたや。
MacOSX に homebrew で R をインストール
けっこうハマった。。

:black_square_button: 雑感

  • pythonが機械学習で注目されている理由がなんとなくわかった気がする
    • 数学・工学・統計学系のライブラリが豊富だから?
    • Rubyとかはこんなにあるのかな?ちゃんと調べていないからなんとも言えないが。。
    • rpy2やpandasでR絡みのライブラリを呼べるのは大きい
    • Scipyやscikit-learnがあるのもPythonの特徴なのかな?
  • これで箱ひげとかヒストグラム、回帰分析、クラスタ分析etcができる環境が整った
  • そういえば学生時代、統計学的なことをやってたなと思い出し、少しノスタルジックな気分になった。。。
  • 上記以外にも、よさげなライブラリがあれば、教えて欲しい次第です。
  • やっぱり、Qiitaにあげるほどの内容でもなかったかな。。

:black_square_button: 参考

17
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
21