validation 参考サイト

3.1. Cross-validation: evaluating estimator performance — scikit-learn 0.20.1 documentation www.chioka.in

syslogとか cronlogとか確認

OOM が出たときとかに syslog を確認 ログファイル名 内容 /var/log/messages 一般的なシステム関連のメッセージ /var/log/secure セキュリティに関するメッセージ /var/log/cron 定期的に実行される処理結果に関するメッセージ /var/log/maillog メールに関…

本番サーバと検証サーバを間違えないように

.bashprofile に以下の設定をすると、色付きになる export PS1="\[\033[31m\]\u@\h\[\033[00m\]:\[\033[01m\]\w\[\033[00m\]\\$ "

pandas の visualization のライブラリ

seaborn: statistical data visualization — seaborn 0.9.0 documentation plot.ly github.com ggplot | Home NetworkX — NetworkX A demo of the Spectral Biclustering algorithm — scikit-learn 0.20.0 documentation

pandas の最初に df を確認する関数

df.dtypes() df.info() df.value_counts() df.isnull() plt.scatter(x1, x2) pd.scatter_matrix(df) df.corr() plt.matshow(...) df.mean()sotr_values().plot(style='.')

Python の文字列ハイライト機能

サジェストのハイライト機能をPython側で実装 import re # 前方一致 def hilight_apply_pre(word, _list): return [re.sub('^{}'.format(re.escape(word)), '<{0}>{1}</{0}>'.format('em', word), l, 1) for l in _list] # 部分一致 def hilight_apply_sub(word, _…

特徴エンジニアリングのおすすめブログ

特徴抽出 4.3. Preprocessing data — scikit-learn 0.20.0 documentation 特徴作成 machinelearningmastery.com What are some best practices in Feature Engineering? - Quora

pecentile で 外れ値 を調整する。

numpy の clip でpercentile の上限下限で外れ値を調整する。 a = [1,2,3,4,1000,5,6,7,5,4] UPPER_BOUND, LOWER_BOUND = np.percentile(a, [1,99]) b = np.clip(a, UPPER_BOUND, LOWER_BOUND) print(b) [ 1.09 2. 3. 4. 910.63 5. 6. 7. 5. 4. ]

data frame のブログとして

機械学習のおすすめブログ Datas-frame tomaugspurger.github.io

AWS スポットインスタンス

AWS

データ分析の際にAWSでスポットインスタンスを立ち上げる。 docs.aws.amazon.com datasciencebowl.com

一つのカラムから、複数カラムへ分割する

date --> [day, month, year] のカラムに変更。 expand=true にして、rename すればいい。 date 02.01.2013 transactions[['day', 'month', 'year']] = transactions.date.str.split( '.', 2, expand=True ).rename(columns = {0:'day', 1:'month', 2:'year'…

機械学習のライブラリ(Python)

Python の機械学習の有名ライブラリのまとめ。 ライブラリ scikit-learn: machine learning in Python — scikit-learn 0.20.0 documentation Overview — H2O 3.22.0.1 documentation www.tensorflow.org github.com github.com github.com github.com サイト…

kibana に index登録

PUT /index { "mappings": { "doc": { "properties": { "id": {"type": "integer"}, "count": {"type": "integer"} } } } } GET /_cat/indices?v $ grep -rF 'pipeline.workers' config/logstash.yml # pipeline.workers: 2 pipeline.workers: 1 csv_pipelin…

コマンド履歴をhistoryに残さない

history のコマンド履歴を消す。 echo 'a' echo 'b' echo 'c' set +o history echo 'd' set -o history history | tail -4 出力結果 685 echo 'b' 686 echo 'c' 687 set +o history 688 history | tail -4

標本平均と不偏標本分散とか信頼区間をpythonでする

train.loc[train.paytype == 1, :].pa.sum() # pa人数 # cash (paytype=1) で払った人 train_iscash = train.paytype == 1 # cash 出払った人の割合の平均値の信頼区間 99% from statsmodels.stats.proportion import proportion_confint proportion_confint…

kibana を公開するには、HTMLにiframeで埋め込めば良さそう

iframe で 埋め込めば対応可能。 あと、chromeでいろいろ確認するには、Elements を直接いじれば良さそう。 www.elastic.co

MySQL の admin user以外で、ログインできなかった話

管理者権限のないuserでログインするとできなかった。 どうやら、MySQL5.7では、plugin を mysql_native_password にしないとパスワードなしログインはできないデフォルトらしい。 $ mysql -uroot ERROR 1698 (28000): Access denied for user 'root'@'local…

spark の 文字取り込み

rdd でちょっとしたお試し。 flatMap は list --> rdd とするっぽい import re from collections import Counter def parse_string(line): try: article_id, text = unicode(line.rstrip()).split('\t', 1) except ValueError as e: return [] text = re.sub…

Solr の jvm のメモリ状況確認

jps でprocess確認して、jstat で統計情報を確認 jps -v | less -SN jstat -gcutil -h3 708 1000 qiita.com docs.oracle.com blog.wackwack.net equj65.net

hadoop のテストするとき

Unit test unix test (cat | mapper | sort | reducer) integration test (stand alone mode: $HADOOP_EMPTY_CONFIG) run test

subplot で、ax の xtick を傾ける

fig,ax_ = plt.subplots(nrows=10, ncols=2, figsize=(14, 20)) ax_ = ax_.ravel() for i in range(20): list_ = M_feature_inverse[i][:3] ax = ax_[i] for l in list_: all_df_tmp = all_df_.loc[all_df_['pk']==l, :].groupby('request_at_dt').size().re…

Solr の debug を見やすくする

debug.explain.structured=true らしい。 http://example.com:8983/solr/item/select?indent=on&q=*:*&wt=json&debug=true&debug.explain.structured=true

House Priceの分析6

大まかな流れを把握 --> 提出まで 読み込み #import some necessary librairies import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) %matplotlib inline import matplotlib.pyplot as plt # Matl…

wc -l のアクセス集計

wc -l のアクセス集計 を pythonで集計した。 wc -l accesslog.* a = ''' 10914 accesslog.20180828010002 8636 accesslog.20180829010001 4742 accesslog.20180830010002 6399 accesslog.20180831010001 6901 accesslog.20180901010001 5503 accesslog.2018…

MySQLのレプリケーションが遅延した場合

レプリケーション遅延 まずは、 show slave statusで Seconds_Behind_Master と Slave*Runningを確認する。 どれくらい遅延しているか確認できる。 slave1 [localhost] {msandbox} ((none)) > show slave status\G *************************** 1. row *****…

House Priceの分析5

前処理 import pandas as pd import numpy as np import seaborn as sns import matplotlib import matplotlib.pyplot as plt from scipy.stats import skew from scipy.stats.stats import pearsonr %config InlineBackend.figure_format = 'retina' #set '…

MySQL から pandas.Dataframe へ読み込む

pandasから、mysqlに読み込む方法 import pandas as pd import MySQLdb def pd_dbread(table, columns_list): """ 接続サンプル """ # 接続する con = MySQLdb.connect( user='aaa', passwd='aaa', host='127.0.0.1', db='aaa', charset='utf8' ) # カーソル…

ramdom でshuffleすると、return Noneになる問題

こうすればいいらしい。 >>> import random >>> x = ['foo', 'bar', 'black', 'sheep'] # O(N) operations・・・shuffle と同じロジック >>> random.sample(x, len(x)) ['bar', 'sheep', 'black', 'foo'] # O(NlogN) operation >>> sorted(x, key=lambda k: …

House Priceの分析4

XGBRegressorっていう、回帰モデルがあるので確認。 そもそも xgboost が結構界隈では有名らしい。 import pandas as pd from sklearn.model_selection import train_test_split from sklearn.preprocessing import Imputer data = pd.read_csv('kaggle/kagg…

House Priceの分析3

回帰分析 ## 平均二乗誤差をルート def error(actual, predicted): actual = np.log(actual) predicted = np.log(predicted) return np.sqrt(np.sum(np.square(actual-predicted))/len(actual)) ## 対数変換 def log_transform(feature): train[feature] = n…