2016-03-01から1ヶ月間の記事一覧

pythonのpandasでデータ解析、カテゴリーごとに和をとる. tapply

groupbyを使う. 2列目を4列目で場合ごとに平均 ll0=df2,4.groupby(4).mean()$ #そのほか ll1=df6,4.groupby(4).mean()$ ll1=df6,4.groupby(4).median()$ ll1=df6,4.groupby(4).describe()$ 参考: pandasにsqlでよくやる処理をやらせてみる http://www.mws…

gensimの導入

python, scipy, numpy のバージョンチェック easy_install --upgrade gensim

pandasで複数ファイルの3列目の同じ値のものをカウントしてマージ

pandasで3列目の同じ値のものをカウントしてマージ $ cat count_station.py import pandas as pd import glob l1=glob.glob('./uniq_data*') (l1) #print l1 start=True for i in l1: i.strip() try: df=pd.read_csv(i,header=None) q1=df[4].value_counts(…

windows7でグループポリシーで禁止されたコンロールパネルを復帰させる

Windows7でグループポリシーで禁止されたコンロールパネルを復帰させる. Windows7でコントロールパネルが表示されない、もしくは、禁止されている場合は 以下の方法で復帰できる場合がある。基本的には、gpedit.msc を利用する.指定されたコントロールパネ…

RstanでMCMCの練習

まずは、ポアソン過程の平均値の推定 $ cat poi.stan data{ int J; // number of data int y[J]; } parameters{ real mu; }model{ y[J] ~ poisson(mu); } 平均30のポアソン分布 ###Poison library("rstan") y data fit iter = 1000,chains = 4) print(fit)…

sklearnで決定木 decision tree

sklearn scikit-learnで決定木 decision tree 出力のpdf化出力のpng化 dot -Kdot -Tpng -Ggpi=300 iris.dot -o iris.png 解像度の変更 http://stackoverflow.com/questions/1286813/how-do-i-set-the-resolution-when-converting-dot-files-graphviz-to-imag…

pythonのpandasで離散化、ビニング、ビンに区切り集計

離散化、ビンに切って、ビニングして、カテゴリごとに集計 xはデータフレーム x[0]で1列目をとりだしている. qcutはデータ数をあわせる分割, cutは均等割り. x[0]として、pd.Seres化することに注意 x0だと、DataFrame。 cats=pd.qcut(x[0],30) print cats…

Rでデータの離散化とビニング(ビンで区切る)

R

x軸で等間隔. discretize関数を使う. library(infotheo) > x<-rnorm(1000) > y<-2*x+0.01*rnorm(1000) > l1<-discretize(x,disc="equalwidth",nbins=15) > tapply(x,l1[[1]],"mean") 1 2 3 4 5 6 -2.87785661 -2.50220873 -2.05626538 -1.63706018 -1.2338…

pandasでInfとnanをで埋める.

pandasでInfとnanを平均で埋める. In [416]: b Out[416]: a c 0 1.000000 3 1 2.000000 4 2 3.000000 NaN 3 inf 5 In [415]: b.replace(np.inf,np.nan).fillna(b.replace(np.inf,np.nan).mean()) Out[415]: a c 0 1 3 1 2 4 2 3 4 3 2 5

Rstanの導入

R

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストール (2)gccのパスをRtoolsのものにする(3)インスト…

Rstanの導入

R

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストール (2)gccのパスをRtoolsのものにする(3)インスト…

scikit-learnでロジスティック回帰

コード $ cat learn_test.py import pandas as pd from sklearn.linear_model import LogisticRegression from sklearn.cross_validation import train_test_split from sklearn.metrics import accuracy_score #df=pd.read_table("test.txt",sep=",",header…

Rstanの導入

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 >R x64 3.2.3 (上のバージョンだと古すぎるので移行) これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストー…

Rstanの導入

R

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストール (2)gccのパスをRtoolsのものにする(3)インスト…

Rstanの導入

R

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストール (2)gccのパスをRtoolsのものにする(3)インスト…

Rstanの導入

R

RのMCMCライブラリのRstanの導入 windows 8 64bit R x64 3.0.2 これに従う. https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started (1)基本の整備 バージョンにあったRtoolsのインストール (2)gccのパスをRtoolsのものにする(3)インスト…