Skip to content

Instantly share code, notes, and snippets.

@yingminc
yingminc / char_typecheck.py
Last active June 30, 2017 04:56
character type check for japanese text
#encoding: utf-8
import re
import argparse
import os
parser =argparse.ArgumentParser()
parser.add_argument('input_txt', help = 'the string input')
args = parser.parse_args()
@yingminc
yingminc / word2vec_test_jp.py
Last active June 30, 2017 05:09
word2vec for utf-8 text (skip-gram/negative sampling) (cosine similarity/analogy) (t-sne)
#-*- encoding: utf-8 -*-
from __future__ import division
import math
import struct
import numpy as np
from multiprocessing import Pool, Value, Array
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import scipy
@yingminc
yingminc / txt_process.py
Created June 30, 2017 05:29
prepare english/japanese tokens for word2vec (use mecab for japanese segmentation)
#-*- encoding: utf-8 -*-
import MeCab
import sys
import codecs
import argparse
import re, string
parser =argparse.ArgumentParser()
parser.add_argument('input_dict', help = 'the file of input dictionary')
@yingminc
yingminc / qgis_midpoint.py
Last active July 13, 2017 05:18
get the middle points of lines in Qgis
from qgis.core import *
import qgis.utils
def midpair(plist):
'''Iterate over pairs in a list '''
x=[]
y=[]
for c in plist:
x.append(c[0])
@yingminc
yingminc / load_weather.ipynb
Created July 27, 2017 05:55
load weather data from url via pandas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yingminc
yingminc / colormap_test.py
Last active July 31, 2017 08:57
opencv colormap by trackbar
import cv2
import argparse
# COLORMAP_AUTUMN = 0,
# COLORMAP_BONE = 1,
# X COLORMAP_JET = 2,
# COLORMAP_WINTER = 3,
# X COLORMAP_RAINBOW = 4,
# COLORMAP_OCEAN = 5,
# COLORMAP_SUMMER = 6,
@yingminc
yingminc / track_hsvmask.py
Created July 31, 2017 09:10
opencv hsv mask/filter with trackbar
import numpy as np
import cv2
import argparse
parser =argparse.ArgumentParser()
parser.add_argument('input_img', help = 'the input image file')
args = parser.parse_args()
def nothing(x):
pass
@yingminc
yingminc / one_hot_encoding.py
Created August 9, 2017 01:59
general one-hot dictionary and encoding
import numpy as np
def onehot_dict(input):
onehotd = {k:v for v,k in enumerate(set(input))}
return onehotd
def onehot_encoder(input,onehotd):
dim = len(set(input))
n = len(input)
@yingminc
yingminc / holiday_info.ipynb
Created August 9, 2017 02:08
generate holiday information
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yingminc
yingminc / bokeh_widgets_practice.py
Last active November 28, 2017 05:13
visualization practice/ bokeh/ slider/ time series / button / animation
# coding: utf-8
import pandas as pd
from bokeh.core.properties import field
from bokeh.io import curdoc,output_notebook
from bokeh.layouts import layout,widgetbox,row
from bokeh.models import (
ColumnDataSource, HoverTool, SingleIntervalTicker, Slider,DateRangeSlider, Button, Label,RelativeDelta,
CategoricalColorMapper,HBox, Select