いつもの円グラフ
s.plot.pie(pctdistance=0.6, labeldistance=0.3, textprops={'color': "white", 'weight': "bold", 'fontsize': 12}, wedgeprops={'linewidth': 2,'edgecolor':"white"},)
自分流jupyter notebookの1セル目
import collections import pathlib # データ処理周り import numpy as np import pandas as pd from IPython.core.display import display # 可視化ライブラリ import matplotlib.pyplot as plt from matplotlib import cm # colormap import seaborn as sns %matplotlib inline # pandasのwarningが邪魔なので import warnings warnings.filterwarnings('ignore') # options # pd.set_option('display.max_columns', 50) plt.style.use('ggplot')
いつもの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);