機械学習の勉強(Kaggle)#1
いろいろと調べたことや気になったことを残していきます。
今回は機械学習を身につけていこう、です。今回はKaggleで調べたことをメモして行きます。Kaggleとは、投稿されたデータの最適モデルを競いあう分析手法関連のプラットフォーム及びその運営会社(from Wikipedia)です。最近Googleに買収されたことでも有名になりました。
はじめに次のnotebookを参考にしました。このnotebookでは、これらデータを見ようとした時に、そもそもどんなデータなのかを調べる流れと手順がまとめてあります。Pythonを使って理解する流れを、手順な具体的で、コマンドベースで説明してくれていて大変わかりやすいです。
Comprehensive data exploration with Python | Kaggle
どんなデータなのかを調べる流れは以下の通りです。
- 問題を理解する
- 単変量解析(univariable)データを理解する(この項目は何か)
- 多変量解析(multivariable)各変数は依存しているか独立しているか相関を把握
- 基本的なクリーニング
- テスト
具体的な手順を次に説明する。コマンドはリンク先を参照してほしい。
1、変数を把握する前に次のような列を持つ表を用意しておく(Excelとかで)
- 変数名
- 数字は数値かカテゴリ値か
- 各項目のセグメント
- 高・中・低のカテゴリを出すなど期待する出力
- コメント
2、目的変数を把握する。
- 平均(mean)
- 標準偏差(std)
- Skewness(歪度)
- Kurtosis(尖度)、通常は3の値をとる。
私は、歪度、尖度はよくわからなかったので以下HatenaBlogを見て把握しました。
目的変数が数値データとの相関があるのかを確認。
x軸、y軸のプロットで確認する。
目的変数がカテゴリカルデータと相関があるかを確認する。
箱ひげ図で確認する。
3、分析
超外観を把握する。
線形関係なのか?強い線形関係なのか?
- 相関図(heatmapで全部?)
- 目的変数に特化した相関図
- シュガー?からの移動が心配
4、欠損値のあつかいを考える
説明変数間の相関を確認する。
- ヒートマップ(heatmap)
- 箱ひげ図(boxplot)
外れ値を確認
- Unvariate(単変量)で分析して外れ値を除外する。
- Bivariate(二変量相関)で分析して外れ値を除外する。
5、さらにモデル
想定される分布
- Normality(正規性)
- Homoscedasticity(等分散性)
- Linearity(線形性)
- Absence of correlated errors
正規性なのかを確認、等分散性なのかの確認
最悪はダミー値にする
A study on Regression applied to the Ames dataset | Kaggle
- 線形回帰
- 目的変数と説明変数のグラフにして外れ値を確認
- NAをダミー値で埋める
- 数値からカテゴリ値に変換
- corr(相関係数)で寄与度を確認
- 数値の特徴量の個数、カテゴリの特徴量の個数を確認
- 数値の特徴量に含まれるNAの個数を確認
- skewedな数値の特徴量はlogを取る
- カテゴリ値の特徴量に含まれるNAの個数を確認
2、モデリング
- 正規化無しの線形回帰
- Ridge回帰付きの線形回帰
- Lasso回帰付きの線形回帰
- ElasticNet回帰付きの線形回帰
Stacked Regressions : Top 4% on LeaderBoard | Kaggle
- xgboost
- Box Cox Transformation of (highly) skewed features
- Stacking models
- Ensembling
機械学習を使うこと
いろいろと調べたことや気づいたことをメモしていこう。
機械学習を使って何かしたい、と思ってもいろいろと未知語ばかり出てきてうんざりしてしまう。私はうんざりです。調べたことを記録しておこうと思います。
次元圧縮
GPLVM
ロジスティック回帰
教師ありの分類
テキストの分類
weight、biasesの初期化
畳み込み(conv2d)、プーリング(max_pool)
最適化関数
ReLU
ステップ関数
http://kaeken.hatenablog.com/entry/2016/11/03/232414
Stanford University CS231n: Convolutional Neural Networks for Visual Recognition
TensorBoard
TensorBoardを起動してみた。
(tensorflow) gocha124noMacBook-Air:~ cha124$ tensorboard -logdir=/Users/cha124/log/tensorboard
Traceback (most recent call last):
File "/Users/cha124/anaconda/bin/tensorboard", line 11, in <module>
sys.exit(main())
File "/Users/cha124/anaconda/lib/python3.6/site-packages/tensorflow/tensorboard/tensorboard.py", line 203, in main
tb = create_tb_app(plugins)
File "/Users/cha124/anaconda/lib/python3.6/site-packages/tensorflow/tensorboard/tensorboard.py", line 105, in create_tb_app
raise ValueError('A logdir must be specified. Run `tensorboard --help` for '
ValueError: A logdir must be specified. Run `tensorboard --help` for details and examples.
(tensorflow) gocha124noMacBook-Air:~ cha124$ tensorboard --logdir=./log/tensorboard
Starting TensorBoard b'54' at http://gocha124noMacBook-Air.local:6006
(Press CTRL+C to quit)
できた。でも起動しただけで「No scalar data was found.」が表示される。
続けてMNISTの分類の結果サマリ表示をやってみる。
tensorflow/tensorflow/examples/tutorials/mnist/mnist_with_summaries.py
サマリ付きのMNISTを実行する。
gocha124noMacBook-Air:mnist cha124$ pwd
/Users/cha124/Downloads/tensorflow-1.2.0/tensorflow/examples/tutorials/mnist
gocha124noMacBook-Air:mnist cha124$ python mnist_with_summaries.py
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
2017-06-27 21:37:00.740000: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 21:37:00.740032: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 21:37:00.740040: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
2017-06-27 21:37:00.740046: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Accuracy at step 0: 0.1334
Accuracy at step 10: 0.7607
Accuracy at step 20: 0.8301
Accuracy at step 30: 0.8548
Accuracy at step 40: 0.8846
Accuracy at step 50: 0.894
Accuracy at step 60: 0.9004
Accuracy at step 70: 0.9016
Accuracy at step 80: 0.9077
Accuracy at step 90: 0.9089
Adding run metadata for 99
Accuracy at step 100: 0.9187
Accuracy at step 110: 0.9186
Accuracy at step 120: 0.9216
Accuracy at step 130: 0.9244
Accuracy at step 140: 0.9269
Accuracy at step 150: 0.928
Accuracy at step 160: 0.931
Accuracy at step 170: 0.9303
Accuracy at step 180: 0.9301
Accuracy at step 190: 0.9304
Adding run metadata for 199
Accuracy at step 200: 0.9321
Accuracy at step 210: 0.9335
Accuracy at step 220: 0.9351
Accuracy at step 230: 0.9356
Accuracy at step 240: 0.9398
Accuracy at step 250: 0.9378
Accuracy at step 260: 0.941
Accuracy at step 270: 0.9437
Accuracy at step 280: 0.9411
Accuracy at step 290: 0.9412
Adding run metadata for 299
Accuracy at step 300: 0.9438
Accuracy at step 310: 0.9461
Accuracy at step 320: 0.9453
Accuracy at step 330: 0.9466
Accuracy at step 340: 0.9443
Accuracy at step 350: 0.9452
Accuracy at step 360: 0.9459
Accuracy at step 370: 0.947
Accuracy at step 380: 0.95
Accuracy at step 390: 0.95
Adding run metadata for 399
Accuracy at step 400: 0.9474
Accuracy at step 410: 0.9483
Accuracy at step 420: 0.9494
Accuracy at step 430: 0.9536
Accuracy at step 440: 0.9522
Accuracy at step 450: 0.9531
Accuracy at step 460: 0.9531
Accuracy at step 470: 0.9552
Accuracy at step 480: 0.9536
Accuracy at step 490: 0.9544
Adding run metadata for 499
Accuracy at step 500: 0.9551
Accuracy at step 510: 0.9546
Accuracy at step 520: 0.9557
Accuracy at step 530: 0.9586
Accuracy at step 540: 0.9575
Accuracy at step 550: 0.9577
Accuracy at step 560: 0.9586
Accuracy at step 570: 0.9577
Accuracy at step 580: 0.957
Accuracy at step 590: 0.959
Adding run metadata for 599
Accuracy at step 600: 0.9576
Accuracy at step 610: 0.9593
Accuracy at step 620: 0.9596
Accuracy at step 630: 0.959
Accuracy at step 640: 0.96
Accuracy at step 650: 0.9599
Accuracy at step 660: 0.9611
Accuracy at step 670: 0.9604
Accuracy at step 680: 0.9626
Accuracy at step 690: 0.9624
Adding run metadata for 699
Accuracy at step 700: 0.9637
Accuracy at step 710: 0.9619
Accuracy at step 720: 0.9643
Accuracy at step 730: 0.9611
Accuracy at step 740: 0.9633
Accuracy at step 750: 0.9643
Accuracy at step 760: 0.9634
Accuracy at step 770: 0.9601
Accuracy at step 780: 0.9616
Accuracy at step 790: 0.9622
Adding run metadata for 799
Accuracy at step 800: 0.9647
Accuracy at step 810: 0.964
Accuracy at step 820: 0.9637
Accuracy at step 830: 0.9643
Accuracy at step 840: 0.964
Accuracy at step 850: 0.9659
Accuracy at step 860: 0.9669
Accuracy at step 870: 0.9663
Accuracy at step 880: 0.9657
Accuracy at step 890: 0.9644
Adding run metadata for 899
Accuracy at step 900: 0.9624
Accuracy at step 910: 0.965
Accuracy at step 920: 0.9664
Accuracy at step 930: 0.9674
Accuracy at step 940: 0.9654
Accuracy at step 950: 0.9671
Accuracy at step 960: 0.9666
Accuracy at step 970: 0.9683
Accuracy at step 980: 0.9659
Accuracy at step 990: 0.9669
Adding run metadata for 999
gocha124noMacBook-Air:mnist cha124$
引数なしで実行する。/tmp/tensorflow/mnistディレクトリに以下出力される。
出力先ディレクトリを指定してTensorBoardを起動する。
tensorboard --logdir=/tmp/tensorflow/mnist
(tensorflow) gocha124noMacBook-Air:~ cha124$ tensorboard --logdir=/tmp/tensorflow/mnist
Starting TensorBoard b'54' at http://gocha124noMacBook-Air.local:6006
(Press CTRL+C to quit)
サマリ表示ができた。何を意味しているのかを調べてみる。
単語 | 調べた意味 |
SCALARS | |
GRAPHS | |
accuracy | 精度 |
cross entropy | 交差エントロピー。よくわかんない |
dropout | 過学習を防ぐディープラーニングのテクニック。一定の確率でランダムにニューロンを無視して学習を進める正則化 |
biases | 偏り。線形モデルを例にするとなんとなくわかる。「y = W * x + b」の表現の b に相当するのかな。 |
weights | 重み。線形モデルを例にするとなんとなくわかる。「y = W * x + b」の表現の W に相当するのかな。 |
さらにGraphを表示してみる。TensorBoardの上部タブのGRAPHSをクリックする。
ニューラルネットの構成が図示される。
できた。