2018年12月2日日曜日

[Python] Seabornのインストール

Pythonにおいて,簡単に可視化,描画できるライブラリとしては Matplotlibがよく用いられます.
Seabornは,Matplotlibのデザイン部分を強化するための可視化ライブラリの一つです(Seabornの公式ドキュメント).また,統計処理を考えて作成されています.

Seabornの特徴

  • 複数の変数間の関係を調べるためのデータセット指向のAPI
  • カテゴリ変数を使用して観測値や集計統計値を表示するための特別なサポート
  • 単変量分布または二変量分布を視覚化し、データのサブセット間でそれらを比較するためのオプション
  • 異なる種類の従属変数に対する線形回帰モデルの自動推定とプロット
  • 複雑なデータセットの全体的な構造に関する便利なビュー
  • 複雑な視覚化を簡単に作成できるマルチプロットグリッドを構成するための高レベルの抽象化
  • いくつかのビルトインテーマでmatplotlibフィギュアスタイリングを簡潔に制御
  • データのパターンを忠実に表示するカラーパレットを選択するためのツール

macOSでのインストール方法は以下のようになります.
pip3経由でインストールを行います.
$ pip3 install seaborn

以下のようにインストールが始まり,Successfully installed seaboard-x.x.xと表示されれば成功です.
Collecting seaborn
  Downloading https://files.pythonhosted.org/packages/a8/76/220ba4420459d9c4c9c9587c6ce607bf56c25b3d3d2de62056efe482dadc/seaborn-0.9.0-py3-none-any.whl (208kB)
     |████████████████████████████████| 215kB 2.3MB/s 
Requirement already satisfied: numpy>=1.9.3 in /usr/local/lib/python3.7/site-packages (from seaborn) (1.16.4)
Requirement already satisfied: pandas>=0.15.2 in /usr/local/lib/python3.7/site-packages (from seaborn) (0.24.2)
Requirement already satisfied: scipy>=0.14.0 in /usr/local/lib/python3.7/site-packages (from seaborn) (1.3.0)
Requirement already satisfied: matplotlib>=1.4.3 in /usr/local/lib/python3.7/site-packages (from seaborn) (3.1.0)
Requirement already satisfied: python-dateutil>=2.5.0 in /usr/local/lib/python3.7/site-packages (from pandas>=0.15.2->seaborn) (2.8.0)
Requirement already satisfied: pytz>=2011k in /usr/local/lib/python3.7/site-packages (from pandas>=0.15.2->seaborn) (2019.1)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/site-packages (from matplotlib>=1.4.3->seaborn) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib>=1.4.3->seaborn) (2.4.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/site-packages (from matplotlib>=1.4.3->seaborn) (1.1.0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/site-packages (from python-dateutil>=2.5.0->pandas>=0.15.2->seaborn) (1.12.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib>=1.4.3->seaborn) (41.6.0)
Installing collected packages: seaborn
Successfully installed seaborn-0.9.0


2018年12月1日土曜日

[PhotoScan] 日本語設定

PhotoScanの設定を日本語に切り替える手順についてのメモです.

起動した後に Tools > Reference を選択します.

General > Language から 'Japanese' を選択するとツールバー等が日本語表示に切り替わります.
 

2018年11月25日日曜日

[macOS] Homebrewのコマンド一覧

macOS用のパッケージマネージャーであるHomebrewのコマンド一覧のメモです.
以下,'formula'にはパッケージ名が相当します.

formulaのインストール
$ brew install formula

formulaのアンインストール
$ brew uninstall formula

Homebrewのアップデート
$ brew update


formulaのアップデート
$ brew upgrade



インストールされたformulaの一覧表示
$ brew list


brewの問題を調べる
$ brew doctor


formulaの情報表示
$ brew info formula

更新されているformulaの検索
$ brew outdated


古いバージョン(outdated)のformulaを削除する
$ brew cleanup
削除されるformulaを見たい時には
$ brew cleanup -n

2018年11月16日金曜日

[Python] Jupyter Note Book で CSVファイル をグラフ描画

Jupyter Note Bookを使って,CSVファイルの読み込み,グラフ作成をやってみた際のメモです.

CSV形式では,1行1レコードで記述されています.1レコードはカンマで区切られて,複数のフィールドを持つことができます.以下のようなCSVファイル(都道府県別の人口一覧データ)があるとします.

prefectures,2000,2005,2010,2015,2016
Tokyo,12064,12577,13159,13515,13624
Kanagawa,8490,8792,9048,9126,9145
Osaka,8805,8817,8865,8839,8833
Aichi,7043,7255,7411,7483,7507
Saitama,6938,7054,7195,7267,7289
Chiba,5926,6056,6216,6223,6236
Hyogo,5551,5591,5588,5535,5520
Hokkaido,5683,5628,5506,5382,5352
Fukuoka,5016,5050,5072,5102,5104
Shizuoka,3767,3792,3765,3700,3688
Ibaraki,2986,2975,2970,2917,2905
Hiroshima,2879,2877,2861,2844,2837
Kyoto,2644,2648,2636,2610,2605
Miyagi,2365,2360,2348,2334,2330
Nigata,2476,2431,2374,2304,2286
Nagano,2215,2196,2152,2099,2088
Gifu,2108,2107,2081,2032,2022
Gunma,2025,2024,2008,1973,1967
Tochigi,2005,2017,2008,1974,1966
Okayama,1951,1957,1945,1922,1915
Fukushima,2127,2091,2029,1914,1901
Mie,1857,1867,1855,1816,1808
Kumamoto,1859,1842,1817,1786,1774
Kagoshima,1786,1753,1706,1648,1637
Okinawa,1318,1362,1393,1434,1439
Shiga,1343,1380,1411,1413,1413
Yamaguchi,1528,1493,1451,1405,1394
Ehime,1493,1468,1431,1385,1375
Nagasaki,1517,1479,1427,1377,1367
Nara,1443,1421,1401,1364,1356
Aomori,1476,1437,1373,1308,1293
Iwate,1416,1385,1330,1280,1268
Ohita,1221,1210,1197,1166,1160
Ishikawa,1181,1174,1170,1154,1151
Yamagata,1244,1216,1169,1124,1113
Miyagi,1170,1153,1135,1104,1096
Toyama,1121,1112,1093,1066,1061
Akita,1189,1146,1086,1023,1010
Kagawa,1023,1012,996,976,972
Wakayama,1070,1036,1002,964,954
Yamanashi,888,885,863,835,830
Saga,877,866,850,833,828
Fukui,829,822,806,787,782
Tokushima,824,810,785,756,750
Kochi,814,796,764,728,721
Shimane,762,742,717,694,690
Tottori,613,607,589,573,570


このCSVファイル(SampleData.csv)を,Jupyter Note Bookで読み込んでみます.
まず,読み込むCSVファイルをJupyterを起動するディレクトリにコピーします.

Jupyter Note Bookを起動して,画面右上の"New"ボタンから"Python3"を選んでクリックします.

以下の二行のプログラムを入力します.

    import pandas as pd
    pd.read_csv("SampleData.csv", encoding="UTF-8")


CSVデータ(SampleData.csv)が表示されています.
SampleData.csvは,人口の多い都道府県順に並んでいます.このデータを2016年度の人口データを元にして,人口の少ない順に並び替え(ソート)を行ってみます.

    import pandas as pd
    df = pd.read_csv("population.csv", encoding="SHIFT_JIS")
    df.sort_values(by=["平成28年"], ascending=True)


Pythonでは,上記のように非常に簡潔に記述できます.
なお,
    ascending=True
の部分を
    ascending=False
と書き換えると、人口の多い順(つまり、降順)に並び替えられます.



続いて,CSVファイルをもとに,棒グラフを描画(2016年をY軸にして棒グラフを描画)してみます.

    %matplotlib inline
    import pandas as pd
    df = pd.read_csv("SampleData.csv", encoding="UTF-8")
    df.plot.bar(y=['2016'])


Jupyter Note Book でグラフ描画するときは
    %matplotlib inline
という一行を記述する必要があります.
また,棒グラフを書くためには plot.barメソッド を呼びだします.
さらに,複数列を持つCSVデータの場合は,どの列をY軸にするかを指定します.
すれば良い。
2つの列を並べたグラフにしたい場合は,以下のようにします(例は2000年,2016年).色分けも自動です.

2018年11月14日水曜日

[macOS] High Sierraをダークモードにする

mac OS High Sierraでダークモードをオンにする方法に関するメモ

ターミナルから
$ defaults write -g NSWindowDarkChocolate -bool TRUE
というコマンドを実行するとダークモードとなります.

ダークモードをオフにするには,ターミナルから
$ defaults delete -g NSWindowDarkChocolate
というコマンドを実行します.

ただし,High Sierraのダークモードはお試し的な感じです....

2018年11月13日火曜日

[macOS] Gitの初期設定

macOS Xには標準でGitがインストールされています.
Gitがインストールされているかどうかを確認するには,ターミナルから以下のコマンドを入力します.
$ git --version
git version 2.15.2 (Apple Git-101.1)

1. ユーザー名とメールアドレスの設定
Gitで使用する「ユーザー名」と「メールアドレス」を設定します.
    git config --global user.name "{ユーザー名}"
    git config --global user.email メールアドレス
$ git config --global user.name "UserName"
$ git config --global user.email xxx@yyy.com

設定した値を確認するには以下のコマンドを実行します.
$ git config --list
credential.helper=osxkeychain
user.name=UserName
user.email=xxx@yyy.com

2. gitフォルダを作成
例としてHomeフォルダに'git'フォルダを作成し,'git'フォルダ内のファイルをGitで管理してみます.

mkdir git と入力し,gitフォルダを作成します.
$ mkdir git

cd git と入力し,gitフォルダに移動します.
ls コマンドでgitフォルダ内のファイルを確認します(今回は作成したばかりなので,空です).

$ cd git

$ ls


試しに,'hello.txt' というファイルを作成してみます.
'hello.txt' というファイルを作成するには,touch hello.txt と入力し,hello.txt ファイルを作成します.

$ touch hello.txt



'hello.txt' が作成されているのかを確認します.

$ ls

hello.txt


基本動作の確認
幾つかの基本コマンドを使って,動作確認をしてみます.
git init コマンドを使用して,Gitの「リポジトリ*」を初期化します.
$ git init
Initialized empty Git repository in /Users/hide/git/.git/

これで,'git' フォルダ内に「リポジトリ」が作成されます.

3. git status でステータスを確認
ここで,git statusコマンドを使用して,ステータスを確認してみます.
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)

hello.txt

nothing added to commit but untracked files present (use "git add" to track)
「hello.txtファイルは追跡されていない」という旨のメッセージが表示されます.

4. git addでファイルの追跡を開始
git add コマンドを使用して,hello.txt ファイルの追跡を開始します.
$ git add hello.txt

 ここで再び git status コマンドを使用して,ステータスを確認してみます.
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

new file:   hello.txt


hello.txtファイルがコミット**できる状態になっています.


git commit で変更内容をリポジトリにコミットする

git commit コマンドを使用して,変更内容をリポジトリにコミットします.

それには,git commit -m "first commit" と入力します.
$ git commit -m "first commit"
[master (root-commit) 54c4f91] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 hello.txt


これで,hello.txtファイルがコミットされました.

ここで,git status コマンドを使用して、ステータスを確認してみます.

$ git status
On branch master
nothing to commit, working tree clean

「作業スペースがクリーンになった」というメッセージが表示されています.

5. git log でコミットの履歴を確認
git log コマンドを使用して,コミットの履歴を確認してみます.

$ git log

commit 54c4f9101e04edfffeb2d56b9a6e99f3f920f688 (HEAD -> master)

Author: HidehikoMURAO <hidehiko.murao@gmail.com>
Date:   Thu Aug 2 23:37:08 2018 +0900

    first commit


以下の3つの情報が表示されています.

  • コミットしたユーザーの情報(名前とメールアドレスは、初期設定で設定した情報)
  • 日付
  • コミットメッセージ
-----
* リポジトリ:ファイルの状態を記録する場所
** コミット:ファイルやディレクトリをリポジトリに登録すること

2018年11月12日月曜日

Jupiter notebook のエラー 'AttributeError: type object ‘IOLoop’ has no attribute ‘initialized’'

ターミナルから jupyter notebook を起動しようとするとエラーが発生することがあります.
エラーメッセージは,以下の通り.

AttributeError: type object 'IOLoop' has no attribute 'initialized'

これは,pyzmqとtornadoのバージョンが競合していることが原因で,pyzmqをアップデートすることで解消できます.

$ conda upgrade pyzmq

参考URL https://github.com/jupyter/notebook/issues/3407