{0..10}の10を他のコマンドから取得する方法
shell でディレクトリの階層分の for 文を回す時、for i in {0..$(hogehoge)}; do echo $i; done
すると、{0..10}
とかがechoされて意図と異なる挙動をした。
ので、メモ。
for i in $(seq 0 $(find . -type d -printf '%d\n' | sort -rn | head -1)); do echo $i ; done
https://www.linux.com/tutorials/all-about-curly-braces-bash/
傾向スコアのATTについて
傾向スコアについて、IPWのATTの計算式について詳しく書いていたので、抜粋。
ATTのときの、 ATT = E[Y_1 | Z=1] - E[Y_0 | Z=1]
は公式に入れるとき、Z=1
のみに限定されていない。ATEの公式と見比べるとわかる。
https://waidai-csc.jp/updata/2018/08/seminar-igaku-20180126.pdf
seaborn : barplot の xticks の調整が難しかった
seaborn の barplot を使っている時、1990~2020 年までのデータに不足があったので、間がとびとびのbarplotになっていた。
xticks(np.arange(1990, 2020))
とかで調整しようとすると、barが消えたりする。
不足分を補うことで、対応した。やむなし。idnex は list の product を使用することで、なんとかした。
# new_index = pd.Index(np.arange(1993,2020,1), name="年") new_index = pd.MultiIndex.from_product( [np.arange(1993,2020,1), [1, 0]], names=['年', 'フラグ'], ) tmp = df[ ['年', 'フラグ', '代表契約IDグループ'] ].groupby(by=['年', 'フラグ'], observed=True).size().reindex(new_index).fillna(0).reset_index().rename( columns={ 0: '件数', } )
2つ以上の histgram の bins の幅がいい感じにならなかったので
これでいい感じに揃えられた。
sns.set(font='IPAPGothic') plt.figure(figsize=(12, 4)) try: bins=np.histogram(np.hstack((tmp_0[col],tmp_1[col])), bins=50)[1] #get the bin edges except Exception as e: print(e) continue sns.distplot( tmp_0[col], bins=bins, kde=False, hist_kws={'log':True}, ) sns.distplot( tmp_1[col], bins=bins, kde=False, hist_kws={'log':True}, ) plt.ylabel('件数') plt.legend() plt.show()