火曜日, 10月 13, 2020

【メモ】How to Win a Data Science Competition: Learn from Top Kagglers 第1週 その3

 ●categorical featureの取り扱い

Label encoding:tree-based modelでは効果を発揮する。

        しかしnon tree-based modelsでは有効に働かない。

        文字列をアルファベット順で数値に置き換えるのも

        label encoding

        sklearn.preprocessing.LabelEncoder

Order of appearance:出現順序

           pandas.factorize

           sort=Trueを指定するとアルファベット順

           (label encodingと等価)

Frequency encoding:Non tree-based modelsでも有効。

           ただし頻度が等しい値が2つあると、

           両者の区別がつかない。


One-hot encoding:Non tree-based modelsで有効。

          最小値が0、最大値が1なので既に正規化されている。

          ユニークな値が多い(各値の出現回数が1に近いものばかり)

          場合にone-hot encodingをするとほとんどが0な列が

          たくさんできるので、疎行列として扱う必要あり。

          XGBoostやLightGBMは疎行列をそのまま扱える

          (CatBoostは不可らしい

          https://cocon-corporation.com/cocontoco/ensemble-methods_sparse-matrix_memory/#index2)

複数のcategorical featureの相互作用を考慮したい

⇒2つの文字列を連結した変数を作ってからone-hot encoding

⇒linear modelやkNNで有効

月曜日, 10月 12, 2020

【メモ】How to Win a Data Science Competition: Learn from Top Kagglers 第1週 その2

 ●preprocessing of numerical features

外れ値への対処:

①クリッピング(パーセンタイルを使ったりする)

min, max = np.percentile(data, [1, 99]) data = np.clip(data, min, max)

②rank transformation(外れ値がある場合はMinMaxScalerよりも良い)

from scipy.stats import rankdata

値の大小の順番を変数として扱う

決定木系以外(特にNeural Network)の性能を上げ得る前処理:

①対数変換

np.log(1 + x)

②平方根変換

np.sqrt(x + 2/3)

【メモ】How to Win a Data Science Competition: Learn from Top Kagglers 第1週 その1

●Linear model

線形モデルは、まばらな高次元データに特に適しています

●Tree-based model

Keep in mind that for Tree-Based Methods, it's hard to capture linear dependencies since it requires a lot of splits. 

ツリーベースのメソッドの場合、多くの分割が必要になるため、線形依存関係をとらえるのは難しいことに注意してください。

●k-NN

k-NN approach heavily relies on how to measure point closeness.

k-NN法は点の近さをどのように測定するかに大きく依存します。

●NN(ニューラルネット)

Feed-forward Neural Nets are harder to interpret but they produce smooth non-linear decision boundary.

フィードフォワード・ニューラルネットは解釈が難しいですが、滑らかな非線形決定境界を生成します。

●Random Forests

Each tree in forest is independent from the others, so two RF with 500 trees is essentially the same as single RF model with 1000 trees.

森の各木は他の木から独立しているので、500本の木を持つ2つのRFは、1000本の木を持つ1つのRFモデルと本質的に同じです。


金曜日, 11月 01, 2019

Ubuntu16.04にpgplotをインストール

sudo apt-get install libx11-dev
してからコンパイル。

月曜日, 10月 28, 2019

Fortranで行数が分からないファイルからデータを読み込む

read(ファイル番号、*,END=999)
のように書いて
ファイルの最後に来た時の処理を
999を付けた行に書く。

水曜日, 10月 16, 2019

OpenCV インストール

pip install opencv-python
pip install opencv-contrib-python




月曜日, 9月 23, 2019

pgplot on Fedora29

yum install libXt-devel-1.1.5-9.fc29.x86_64

gfortranでpgplotをコンパイル

基本的にはここの過去の記事と同じ手順。

ただし/usr/local/src/pgplot/makemake /usr/local/src/pgplot linux gfortran_gcc
を実行してもmakefileが作成されないので、
/usr/local/src/pgplot/makemake /usr/local/src/pgplot linux g77_gcc
を実行して、作成されるmakefile中で
FCOMPL=gfortran
とする。

なおgfortranでコンパイルするのは、g77だと自作した
pgplot用のプログラムのコンパイルが通らないから。

日曜日, 5月 19, 2019

Optunaのインストール

pip install optuna
とすると
TypeError: parse() got an unexpected 
keyword argument 'transport_encoding'
とエラーが出てしまった。

https://qiita.com/waku2011/items/4af412bf1d24eef309a9
を参考に
 C:\Users\Anaconda3\Lib\site-packages\で
$ git clone https://github.com/pfnet/optuna.git
$ cd optuna
$ python setup.py install を実行。 import optuna はうまくいった。

matplotlibのcontour.pyのエラー

raise ValueError("Contour levels must be increasing")
というエラーが出たので、ネットの記事を参考に
numpyとmatplotlibをアンインストールして、
pip install numpy==1.10.2
pip install matplotlib==1.5.0
を実行したところ、エラーが出なくなった。

tkinterを使いたいのに、pyenvだとエラーが出る

import _tkinter # If this fails your Python
may not be configured for Tk
ImportError: No module named '_tkinter'
というエラーが出てしまう。

先にtk-develをインストールしておく
必要があるとのこと。

pyenv uninstall *.*.*
で一旦アンインストールして

sudo dnf install tk-devel
(Fedoraの場合)
を実行してから再度

pyenv install *.*.*
でインストールすれば
エラーが消えました。

Fedoraにpyenvをインストール

http://note.east-eden.net/note/?p=170

$ sudo dnf install gcc gcc-c++ make git openssl-devel bzip2-devel zlib-devel readline-devel sqlite-devel libffi-devel

$ sudo git clone https://github.com/yyuu/pyenv.git /usr/bin/.pyenv
$ cd /usr/bin/.pyenv
$ sudo mkdir shims
$ sudo mkdir versions

########## 追記 ##########
/usr/bin/.pyenv
以下の所有者、グループの設定が
rootのため書き込みできなかった。
そのため、chown, chgrpで
自ユーザーに変更
#########################

$ vi ~/.bashrc
; 下記を追記
export PYENV_ROOT="/usr/bin/.pyenv" if [ -d "${PYENV_ROOT}" ]; then export PATH=${PYENV_ROOT}/bin:$PATH
eval "$(pyenv init -)"
fi ; ここまで
$ source ~/.bashrc

$ pyenv install --list
でインストール可能なpythonのバージョンを確認

pyenv install 2.7.16
(python2を使いたかったので)
pyenv install 3.7.1
(システムの元々のデフォルトバージョン)

$ pyenv global 2.7.16
(バージョン部分は適宜変更)

火曜日, 2月 19, 2019

Windowsにtslearnをインストール

ネットで調べると
pip install tslearn
でインストールできる
という記述が出てくるが、
Visual C++が必要とのエラーが出る
(Visual Studio Communityをインストールすると
解決する)。

githubのtslearnのサイトを見ると一番最初に
conda install -c conda-forge tslearn
と書いてある。実際にこの方法でやれば
さきほどのエラーは出ない
(Anaconda promptを管理者で実行しなかったために
エラーは出たが。。。)

水曜日, 1月 02, 2019

Fedora29へのOpenMPIのインストール

https://www.open-mpi.org/
へ行き、Downloadをクリック。
最新版(今日現在は、v4.0.0)のtar.gzをダウンロード。

解凍し、作成されたディレクトリに移動し

sudo ./configure --prefix=/usr/local/bin
sudo make
sudo make install
 
を実行。

月曜日, 12月 17, 2018

Fedora29でgfortran、gccをインストール

http://www.rivhiro-weather.com/knowledge/?p=806

yum install gcc-gfortran libgfortran

 yum install gcc-c++

Fedora29でC/C++の開発環境をインストールする

https://www.hiroom2.com/2018/12/15/fedora-29-eclipse-cdt-ja/

sudo dnf install -y eclipse-cdt

金曜日, 5月 04, 2018

Fedora24でVisIt

バージョン2.10.3であれば
https://wci.llnl.gov/simulation/computer-codes/visit/executables
からexecutableのファイル(tar.gz)をダウンロードして
解凍して、bin/visitを実行すれば起動する。

ただし、
libpng12.so.0: cannot open shared object file: No such file or directory
というエラーが出る場合は
sudo yum install libpng12
を実行する。

日曜日, 12月 17, 2017

フリーの最適化ソフト DAKOTAをFedora24にインストール

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/dakota /home/.../dakota-6.7.0.src
という感じでインストールを試したところ

CMake Error at CMakeLists.txt:245 (enable_language):
  No CMAKE_CXX_COMPILER could be found.
  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
というエラーが出てうまくいきません。
そこで
sudo yum install gcc-c++
を実行して
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/dakota /home/.../dakota-6.7.0.src -CMAKE_CXX_COMPILER=/usr/bin/g++
を試してみると、今度は
CMake Error at CMakeLists.txt:315 (find_package):
  Could not find a package configuration file provided by "LAPACK" with any
  of the following names:
    LAPACKConfig.cmake
    lapack-config.cmake
  Add the installation prefix of "LAPACK" to CMAKE_PREFIX_PATH or set
  "LAPACK_DIR" to a directory containing one of the above files.  If "LAPACK"
  provides a separate development package or SDK, be sure it has been
  installed.
というエラーが出てしまいます。そこでliblapack.so.3gf(シンボリックリンク)があるのが/usr/lib
なので
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/dakota /home/.../dakota-6.7.0.src -CMAKE_CXX_COMPILER=/usr/bin/g++ -CMAKE_LAPACK_DIR=/usr/lib
を試してみると、だいぶ進みますが
CMake Error at packages/external/teuchos/cmake/tribits/modules/FindPythonInterp.cmake:119 (IF):
  if given arguments:
    "VERSION_LESS" "2.4"
  Unknown arguments specified
というエラーが出ます。
を参考に
dakota-6.7.0.src/ackages/external/teuchos/cmake/tribits/modules/FindPythonInterp.cmake
を修正します。
今度は
CMake Error at packages/external/teuchos/cmake/tribits/package_arch/TribitsTplDeclareLibraries.cmake:342 (MESSAGE):
  Could not find the BLAS Library! Please manually set BLAS_LIBRARY_DIRS
  and/or BLAS_LIBRARY_NAMES or just TPL_BLAS_LIBRARIES to point to the BLAS
  libraries!
というエラーが出ます。

そこで~/.bashrcに
export BLAS_LIBS=/usr/lib
export LAPACK_LIBS=/usr/lib
と記述して
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/dakota /home/hiromitsu/Simulation/dakota-6.7.0.src -CMAKE_CXX_COMPILER=/usr/bin/g++ -CMAKE_LAPACK_DIR=/usr/lib/ -DBLAS_LIBS=/usr/lib/libblas.so.3gf.0 -DLAPACK_LIBS=/usr/lib/liblapack.so.3gf.0
と実行すると、さらに進みますが

CMake Error at packages/external/acro/packages/colin/CMakeLists.txt:11 (message):
   Cannot build colin without Boost.  Please enable USE_BOOST and set Boost_INCLUDE_DIR

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
Boost_INCLUDE_DIR (ADVANCED)
というエラーが出ます。

今日はここまで。。。

フリーの最適化ソフト DAKOTAをFedora24にインストール(事前準備)

http://mogura7.zenno.info/~et/wordpress/ocse/?p=871#more-871
を参考に、事前準備を実施。

Boostは上記サイトにあるようにインストールできるが、
BLAS, LAPACKは
動的ライブラリ(*.so)が必要とのこと。

そこで
https://qiita.com/AnchorBlues/items/69c1744de818b5e045ab
にある手順をベースにしつつも
make.incのgfortranでのコンパイルオプションに
-fPICを追加してコンパイル。

コンパイル後、
BLAS/SRC/で
gfortran -shared -lpthread -lgomp -o libblas.so *.o
sudo ln -s /home/.../lapack-3.8.0/BLAS/SRC/libblas.so /usr/lib/libblas.so.3gf.0

SRC/で
gfortran -shared -lpthread -lgomp -o liblapack.so *.o
sudo ln -s  /home/.../lapack-3.8.0/SRC/liblapack.so /usr/lib/liblapack.so.3gf
を実行
https://qiita.com/_akisato/items/d5de60e38b5a69387bde
を参考にしてみた)。

ただし、まだ正しく*.soが作成できたかは不明。
これからDAKOTAのインストールを試してみる。

Fedora24用 gfortran rpmファイル

事情により再びFedoraで数値計算をする必要が出たが、
gfortranがyumでインストールできないため
下記サイトからrpmファイルをダウンロードして
インストール。

su
(パスワード入力)
rpm -ivh gcc-gfortran-6.3.1-1.fc24.x86_64.rpm
でインストール

http://rpm.pbone.net/index.php3/stat/4/idpl/39452465/dir/fedora_24/com/gcc-gfortran-6.3.1-1.fc24.x86_64.rpm.html

なんで最新版のFedoraではないかというと、既にインストール済で
その環境をそのまま使いたかったから。