Skip to content

Instantly share code, notes, and snippets.

@messefor
messefor / hist_cum_twin_grid.py
Last active April 21, 2020 16:04
Example to show how to plot histogram with accumulate ratio. Plot multiple histograms using seaborn.FacetGrid().
"""Example to show how to plot histogram with accumulate ratio.
Plot multiple histogram using seaborn.FacetGrid()
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
% matplotlib inline
@messefor
messefor / ubcf_for_blog.R
Last active February 27, 2020 09:06
レコメンドつれづれ 1-2 Rによるユーザベース協調フィルタリングの実装例
#----------------------------------------------------------
# Rによる協調フィルタリングの実装例
#
# Brainpad技術ブログ:レコメンドつれづれ 1-2付属コード
#
#----------------------------------------------------------
library(recommenderlab)
#------------------------------------------
#! /bin/bash
env_name=$1
env_dir=venv
python3 -m venv $env_dir
source $env_dir/bin/activate
pip install --upgrade pip
pip install scipy
pip install numpy pandas
@messefor
messefor / subplots_sample.py
Last active April 23, 2018 03:11
Frequency used subplot coding for me to use.
"""Frequency used matplotlib subplot."""
import math
import numpy as np
import matplotlib.pyplot as plt
# Apply plot function into all data in Xs dictionary.
def subplots(Xs, plot_func):
# Set subplots location info
@messefor
messefor / face_detect.py
Created November 25, 2017 09:01
Detect face in image and save cropped.
#! /usr/bin/env python
"""
Detect face and save cropped images.
http://vaaaaaanquish.hatenablog.com/entry/2016/08/15/193636
http://dlib.net/face_detector.py.html
"""
import cv2
import os
import glob
@messefor
messefor / keras_data_flow_splitter.py
Last active February 16, 2018 03:26
Script to split data images for keras data_flow_from method
"""Build keras directory structure for flow_from_dir method"""
import os
import shutil
import numpy as np
from glob import glob
DATA_DIR = 'data/clean'
FILE_EXT_PTN = '*.jpg'
TARGET_DIR = 'data/shrine_temple2'
@messefor
messefor / timer.py
Created December 5, 2017 01:36
Timer class to measure elapsed time
import time
import pickle
from collections import defaultdict
class Timer:
def __init__(self):
self.time_pool = defaultdict(list)
self.start_dict = {}
@messefor
messefor / mpl_bar_exaple_with_ratio.py
Created September 9, 2017 02:11
Example of matplotlib barplot with accumulative ratio on 2nd axis.
"""Example of matplotlib barplot with accumulative ratio on 2nd axis."""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
# Plot with seaborn darkgrid style
% matplotlib inline
sns.set(style="darkgrid", palette="muted", color_codes=True)
@messefor
messefor / hist_cum_twin.py
Created September 5, 2017 12:16
Histogram with cumulative ratio
"""Example to show how to plot histogram with accumulate ratio."""
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# % matplotlib inline
sns.set(style="darkgrid", palette="muted", color_codes=True)
# Toy data
np.random.seed(0)
@messefor
messefor / subplot_with_pandas.ipynb
Created February 11, 2017 10:20
pandas.DataFrame.plotとsubplotを使って、複数グラフを柔軟にプロットする
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.