HTMLのテーブルからコピペして、Markdown 書式に変換する方法

tmp = '''Variable Description Id A unique identifier associated with an application. Product_Info_1-7 A set of normalized variables relating to the product applied for Ins_Age Normalized age of applicant Ht Normalized height of applicant W…

cohen_kappa_score について

以下のサイトが分かりやすい。他クラスのスコアのとり方で使用できる。 順序ごとに target label が貼られている場合、target をより ground truth より遠く推論したものにペナルティが加わる。 from sklearn.metrics import cohen_kappa_score from sklearn…

HSV空間について

HSV は、「色相(Hue)」「彩度(Saturation)」「明度(Value・Brightness)」の3要素 で、色相は虹みたいな感じ。 www.peko-step.com import PIL from PIL import Image from matplotlib import pyplot as plt import cv2 path = './data/horses.jpg' im = Image…

Yolo v3 での物体検出

Yolo v3 での物体検出を Pytorch で実装している。Kaggle 等で使えそう。 github.com pjreddie.com

Pytorch のコールバック関数

pytorch のcallback が実装されている。 pytorch.org 2年前の更新で止まっているが、便利。 github.com

機械学習・深層学習便利サイト

めちゃくちゃまとまっている。分かりやすい github.com

Kaggle の クジラコンペで参考にした kernel

www.kaggle.com 細かい内容に心折れそう...。結構、詳しく書いてあったので参考に。 参考にした kernel www.kaggle.com www.kaggle.com www.kaggle.com

linear assignment problem について

Hungarian algorithm が有名所。scipy はこのアルゴリズムで実装されている。 >>> cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) >>> from scipy.optimize import linear_sum_assignment >>> row_ind, col_ind = linear_sum_assignment(cost) >>> col…

phash について

phash で画像ファイルを 64bit で表現する。ハミング距離から、画像の類似性を判定できる。 from imagehash import phash from PIL import Image as pil_image img = pil_image.open(path) h = phash(img) h """ array([[ True, False, True, True, True, Tr…

keras の callback関数の指定方法

EarlyStopping: min_delta 以下の improvement しか、見られない時に patience 回しか耐えない。monitor より確認 ReduceLROnPlateau: min_delta 以下の改善しか見られない時に、学習率 (lr) に factor を掛ける。 ModelCheckpoint: model_name で保存する。…

アフィン変換記事

わかりやすい。scipy の matrix は output --> input としているので、T @ vec のアフィン変換をする場合は、matrix=mat_inv(T)と逆行列を指定する必要がある。 from scipy.ndimage import affine_transform from numpy.linalg import inv as mat_inv def ce…

matplotlib の日本語変更

以下のコマンドでフォントがあれば、入れてみる。 print([f.name for f in matplotlib.font_manager.fontManager.ttflist]) 例えば from matplotlib import rcParams rcParams['font.family'] = 'IPAPGothic'

uwisgi の設定はここから確認すればいいっぽい

docker で django のアプリを作ろうとして詰まった。 uwsgi-docs.readthedocs.io qiita.com

機械学習の計算対象が偏っているとき

基本的には、upsampling か downsampling か。大体の母分布がわかっている場合は、平均分散を用いて、augmentation するのもあり。 www.kaggle.com A systematic study of the class imbalance problem in convolutional neural networks from Yuya Soneoka …

pandas の 移動平均とかの計算に便利

# 移動平均。重み付けなし df.rolling(window=3).mean() # 未来永劫平均取る的な。 df.expanding(min_periods=3).mean() # 移動平均。重み付けあり。 df.ewm(com=0.5).mean() com : float, optional Specify decay in terms of center of mass, 𝛼=1/(1+𝑐𝑜𝑚),…

文字列の数値を float 型に変換

str を 数値に変換 Nan を無視できる。 df.num.convert_objects(convert_numeric=True) #=> 0 0 #=> 1 1 #=> 2 NaN #=> 3 3 blog.mwsoft.jp

リーマン距離って

リーマン距離って、正定値行列同士の距離を正確に測る手段なのか... 不明すぎる。 math.stackexchange.com https://hal.archives-ouvertes.fr/hal-01570120/document

直和、直積を毎回わすれるので

以下のサイトでいい感じにまとめていた。 http://chem.ru.dendai.ac.jp/Ruike/ru_i.ke/3_junior3/bunshi/lec_support/lecture_9.pdf

pandas の apply を numpyで実行する場合

# axis = 0 の場合、arr をsumする。 np.apply_along_axis(sum, 0, arr) # np.vectorize とかも使える # one-hot --> label encoding y_val = np.argmax(y_val, axis=1) multiclass の xgboost 実装 from sklearn.multiclass import OneVsRestClassifier imp…

run-length encoding の解凍・圧縮

これめちゃ便利 In order to reduce the submission file size, our metric uses run-length encoding on the pixel values. Instead of submitting an exhaustive list of indices for your segmentation, you will submit pairs of values that contain a …

信号解析のフィルタリング

import scipy as sp print(sp.__version__) >>> 0.19.1 信号の作成 import numpy as np import matplotlib.pyplot as plt from scipy import signal N = 1024 # サンプル数 dt = 0.001 # サンプリング周期 [s] f1, f2, f3 = 10, 60, 300 # 周波数 [Hz] t = n…

バックプロパゲーション 計算は、分解したほうがわかりやすいかも

darden.hatenablog.com

plt のメモリについて

tick で実際のメモリ、ticks_label で表示するメモリについて、制御する。 yticks = 2 ** np.arange(0, 5) plt.yticks(np.log2(yticks)) plt.yticklabels(yticks)

np correlate について

conv と correlate は計算方向が逆になっただけで基本の考え方は一緒。 corr の 基本の計算は、c'_{av}[k] = sum_n a[n] conj(v[n+k]) な感じ。 [1, 2, 3], [0, 1, 0.5] --> 0 padding [0, 0, 1, 2, 3, 0, 0] [0, 0, 0, 1, 0.5, 0, 0] valid: 0 padding しな…

信号分析

フーリエ変換の関数。便利。 from scipy.fftpack import fft def get_fft_values(y_values, T, N, f_s): f_values = np.linspace(0.0, 1.0/(2.0*T), N//2) fft_values_ = fft(y_values) fft_values = 2.0/N * np.abs(fft_values_[0:N//2]) return f_values, …

画像前処理のtutorial

このサイトで進める。 likegeeks.com [https://docs.opencv.org/4.1.0/d7/d1b/groupimgprocmisc.html:embed:cite]

PDF からの文字認識から使えそう

qiita.com

テキスト分類のレポートライブラリについて

よくわからないが、テキストデータの分類のしやすさについてレポートを出してくれる。 github.com gensim.models.KeyedVectors.load_word2vec_forma は、crawl-300d-2M.vec (fasttext) のEmbeded を ロードしてくれる。 glove = '../../glove/glove.840B.300…

pd.DataFrame の groupby の label の指定

groupby の by はリスト指定でラベリングするのもあり。 ppap = pd.DataFrame({'a': [1,3,1,4], 'b': [2,5,2,5]}) ppap['a'].groupby(ppap['b']).sum() b 2 2 5 7 Name: a, dtype: int64

histgram の データを取得する方法

import numpy as np count, division = np.histogram(series) stackoverflow.com ちなみに、shapiro の W は検定統計量らしい。Wikipediaより x = st.norm.rvs(loc=0, scale=1, size=1000) st.shapiro(x) ==> (0.9986046552658081, 0.6241769790649414)