Skip to content

Instantly share code, notes, and snippets.

@tatamiya
tatamiya / pca_image.py
Created March 10, 2019 07:56
PCA decomposition of an image
from PIL import Image
import numpy as np
from sklearn.decomposition import PCA
n_components=10
ncomp_selected = 0 # the index of the PCA component to select (int or list)
# read image
pilimg_pumpkin = Image.open('pumpkin.jpg')
npimg_pumpkin = np.array(pilimg_pumpkin)
def sum_from_one(k):
sum = 0
for i in range(1, k+1):
sum += i
return sum
sum_list = []
for i in range(0, N):
sum_list.append(sum_from_one(i))
def linear_fit(x, y):
N_ = len(x)
X_, y_ = np.vstack([x, np.ones(N_)]).T, np.array(y)
fit_results = np.linalg.lstsq(X_, y_, rcond=None)
a_, b_ = fit_results[0]
r2error_ = fit_results[1][0]
return a_, b_, r2error_
@tatamiya
tatamiya / scikit-leanを用いたホテリング理論による異常検知.ipynb
Last active September 16, 2019 10:41
Anomaly detection based on Hotelling theory with scikit-learn
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tatamiya
tatamiya / 近傍距離ベースの異常検知(井手3.3節).ipynb
Last active October 5, 2019 03:48
Anomaly Detection via LocalOutlierFactor and KernelDensityEstimation
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tatamiya
tatamiya / 画像の特異値分解.ipynb
Created October 5, 2019 03:52
numpyとscikit-learnで画像の特異値分解を試した。
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tatamiya
tatamiya / 時系列の特異値分解.ipynb
Created October 6, 2019 09:52
Singular value decomposition (SVD) of time series data
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tatamiya
tatamiya / LightGBMの学習〜モデル評価のテンプレート.ipynb
Created October 14, 2019 03:11
From model construction to interpretation(LightGBM + Optuna + SHAP)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.