Skip to content

Instantly share code, notes, and snippets.

View yamaguchiyuto's full-sized avatar

Yuto Yamaguchi yamaguchiyuto

View GitHub Profile
@yamaguchiyuto
yamaguchiyuto / grid_search.py
Created December 5, 2014 04:06
Grid search for oreore regression
import sys
import numpy as np
import matplotlib.pyplot as plt
from sklearn import grid_search
from oreore_ridge import RidgeRegression
def psi(xlist,M):
""" make a design matrix """
ret = []
for x in xlist:
@yamaguchiyuto
yamaguchiyuto / cross_validation.py
Created December 5, 2014 04:06
Cross validation for oreore regression
import sys
import numpy as np
from sklearn import cross_validation
from oreore_ridge import RidgeRegression
def psi(xlist,M):
""" make a design matrix """
ret = []
for x in xlist:
ret.append([x**i for i in range(0,M+1)])
@yamaguchiyuto
yamaguchiyuto / remove_usernames_and_urls.py
Last active October 9, 2015 00:50
Removing URLs and usernames in tweets
import re
def remove_usernames_and_urls(text):
username_removed_text = re.sub('@\w+', '', text) # remove usernames
return re.sub('(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)', '', username_removed_text) # remove urls
import numpy as np
from scipy import linalg,sparse,random
class RESCAL:
def __init__(self,r,lamb_A,lamb_R):
self.r = r
self.lamb_A = lamb_A
self.lamb_R = lamb_R
def fit(self,X,niter=30):
@yamaguchiyuto
yamaguchiyuto / predict.py
Created February 23, 2016 23:51
Reproducing TransE experiments [NIPS'13]
import sys
import pickle
import numpy as np
import pandas as pd
from transe import TRANSE
modelfilepath = sys.argv[1]
h = sys.argv[2]
r = sys.argv[3]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
class CPALS:
def __init__(self,k,lamb,max_iter):
self.k=k
self.lamb=lamb
self.max_iter=max_iter
def _calc_data_shape(self,X):
max_i = -1
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
class Tucker:
def __init__(self,R,S,T,max_iter):
self.latent_size = (R,S,T)
self.max_iter=max_iter
def _calc_data_shape(self,X):
max_i = -1
max_j = -1