いつものHML分析
d = access_features['count'].sort_values().reset_index() d.columns = ['base_index', 'count'] d = d.reset_index() from sklearn.cluster import KMeans from matplotlib import cm kmeans = KMeans(n_clusters=3) kmeans.fit(d[['count']]) d.loc[:, 'cluster'] = kmeans.labels_ fig, ax = plt.subplots() colors = cm.Accent.colors for i in range(3): target = d[d['cluster'] == i] ax.scatter(x=target['index'], y=target['count'], c=colors[i]
pandasで日時周り
df
にtime
カラムがあることを想定
文字列 -> datetime型
time
が2017-01-01
とかの文字列だったとき
pd.to_datatime(df['time'])
でだいたいよしなにparseしてくれる
unixtime -> datetime型
time
がunixtimeだったとき
pd.to_datatime(df['time'], unit='s')
一部情報を取り出す(日付、月、時間等)
datetime = pd.to_datatime(df['time']) datetime.dt.hour
数百字のテキストを分類/クラスタリングしてみる with Keras
参考文献メモ。
分類
- ベース: Sequence Classification with LSTM Recurrent Neural Networks in Python with Keras - Machine Learning Mastery
- python - Keras LSTM multiclass classification - Stack Overflow
短文ならLSTM, 長文ならRNNが良いという噂。
クラスタリングするなら
- 【ICML読み会】Unsupervised Deep Embedding for Clustering Analysis - SSSSLIDE
- Unsupervised Deep Embedding for Clustering Analysis
色々
Recursive AutoEncoder
LSTMを理解する
KerasでLSTM AutoEncoder
PyCharmでRoot以外にもPythonPathを追加したい時
PyCharm: 2017.1バージョン
Preference > Project:
postgresqlでcsvファイルから一括upsert
全部1行ずつupsertしてたら100万件で数時間かかったので、 他の解決策を考える。
1時テーブルを作成しupdate + insert
PostgreSQL CSV 取り込み upsert | odekakeshimasyo.me
- copy from => tmp table
- tmp tableからUpdate
- tmp tableからUpdateした分を削除してInsert
PostgreSQLメモ
Activeで何クエリが走ってるか
select pid, query from pg_stat_activity where state = 'active';
クエリジョブのkill
select pg_cancel_backend(pid);
Pythonのdocstringの書き方について
3つの書き方
google style:
numpy style:
reST:
自分の基本的な書き方
基本的にはreSTの書き方しているつもり。
''' 1行関数・クラス説明 複数行説明... :param type param-name: param-description :return: return-description :rtype: return-type '''