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 12, 2016 03:21
summary
summary(c[2])
freq
Min. : 4.0
1st Qu.: 521.0
Median : 634.0
Mean : 632.3
3rd Qu.: 747.0
Max. :1215.0
@tengpeng
tengpeng / a.rb
Created April 12, 2016 03:15
count mean by group R
aggregate(data$age, by=list(data$group), FUN=mean)[2]
@tengpeng
tengpeng / a.rb
Created April 12, 2016 03:11
df subset by count R
df2 <- subset(df, article_id %in% names(tt[tt > 200]))
@tengpeng
tengpeng / a.rb
Created April 11, 2016 02:00
cv result2
0.863635408019
{'estimator__kernel': 'rbf', 'estimator__C': 8, 'estimator__gamma': 0.00048828125}
@tengpeng
tengpeng / a.rb
Created April 11, 2016 01:14
cv result
{'estimator__kernel': 'rbf', 'estimator__C': 8, 'estimator__degree': 3.0517578125e-05}
@tengpeng
tengpeng / a.rb
Created April 10, 2016 21:05
cv svm
from sklearn.datasets import load_iris
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import f1_score
model_to_set = OneVsRestClassifier(SVC())
parameters = {
"estimator__C": [2e-5, 2e-3, 2e-1, 2e1, 2e3, 2e5, 2e7, 2e9, 2e11, 2e13, 2e15],
@tengpeng
tengpeng / a.rb
Created April 10, 2016 15:30
mean vector
mean = []
for bid, loc in bid_loc.iteritems():
try:
mean.append(np.mean(pid_ftr[loc],axis=0))
except IndexError:
pass
np.save('mean_vector', mean)
@tengpeng
tengpeng / a.rb
Created April 10, 2016 15:29
mark location2
bid_loc = defaultdict(list)
i = 0
for key, value in bid_img.iteritems():
for v in value:
bid_loc[key].append(idx[i])
i += 1
@tengpeng
tengpeng / a.rb
Created April 10, 2016 15:28
mark location
t = time.time()
idx = []
for key, value in bid_img.iteritems():
for v in value:
loc = -1
for pid in pid_lst:
loc += 1
if v == pid:
idx.append(loc)
@tengpeng
tengpeng / a.rb
Created April 10, 2016 02:51
check empty element list
i = 0
for x in y_train:
i += 1
if not x:
print i