Skip to content

Instantly share code, notes, and snippets.

View tengpeng's full-sized avatar

Teng Peng tengpeng

View GitHub Profile
@tengpeng
tengpeng / a.rb
Created April 10, 2016 01:13
get full path 2
def full_path(folder_path):
full_path = []
for dirpath, subdirs, files in os.walk(folder_path):
for f in files:
full_path.append(os.path.join(dirpath, f))
return full_path
@tengpeng
tengpeng / a.rb
Created April 10, 2016 01:12
get full path
import os
data_root = '/home/pt/Dropbox/mxnet/example/yelp/'
def load_info():
full_path = []
for path, dir, files in os.walk(data_root+'/train_photos'):
for f in files:
#path_to_image.append(f)
#dir.append(f)
name = os.path.join(dir, f)
full_path.append(name)
@tengpeng
tengpeng / a.rb
Created April 9, 2016 16:21
dict match bid_img
bid_img = defaultdict(list)
for line in train_photo_to_biz_ids:
pid, bid2 = [v.strip() for v in line.split(',')]
bid2 = bid2.strip("\r\n")
bid_img[bid2].append(pid)
@tengpeng
tengpeng / a.rb
Created April 5, 2016 22:41
view zip file content
unzip -c train.zip Train.csv | less
@tengpeng
tengpeng / a.rb
Created April 3, 2016 18:30
alias bash
echo "alias aliasname='command'" >> ~/.bash_aliases && source ~/.bash_aliases
@tengpeng
tengpeng / a.rb
Created April 2, 2016 19:41
convert py
def convert_label_to_array(str_label):
str_label = str_label[1:-1]
str_label = str_label.split(',')
return [int(x) for x in str_label if len(x)>0]
def convert_feature_to_vector(str_feature):
str_feature = str_feature[1:-1]
str_feature = str_feature.split(',')
return [float(x) for x in str_feature]
@tengpeng
tengpeng / useful_pandas_snippets.py
Created March 21, 2016 14:56 — forked from bsweger/useful_pandas_snippets.md
Useful Pandas Snippets
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]
@tengpeng
tengpeng / a.rb
Created February 26, 2016 19:11
backup m1
def mf(y_true, y_pred):
tp = 0
fp = 0
fn = 0
for i in range(y_true.shape[0]):
for j in range(y_true.shape[1]):
if y_true[i, j] == y_pred[i, j]:
if y_true[i,j] == 1:
tp += 1
elif y_true[i, j] != y_pred[i, j]:
@tengpeng
tengpeng / a.rb
Created February 24, 2016 04:09
m1
def mf(y_true, y_pred):
tp = 0.0
fp = 0.0
fn = 0.0
for i in range(y_true.shape[0]):
for j in range(y_true.shape[1]):
if y_true[i, j] == y_pred[i, j] & y_true[i,j] == 1:
tp += 1
elif y_true[i, j] != y_pred[i, j]:
if y_pred[i,j] == 1:
@tengpeng
tengpeng / a.rb
Created February 22, 2016 06:03
add end folder
from_dir = from_dir if from_dir.endswith('/') else from_dir + '/'