Skip to content

Instantly share code, notes, and snippets.

import bcolz
import pickle
def save_array(fname, arr):
c=bcolz.carray(arr, rootdir=fname, mode='w')
c.flush()
def load_array(fname):
return bcolz.open(fname)[:]
#genertor
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True) #many other augmentations are avialbile
#flow
datagen.flow(x, batch_size=1, save_to_dir='preview', save_prefix='cat', save_format='jpeg')
@shgidi
shgidi / XGBoost.py
Last active May 7, 2017 08:53
This is generic XGBoost
import xgboost as xgb
clf = xgb.XGBClassifier(max_depth=10, n_estimators=1500,min_child_weight=9,learning_rate=0.01,
nthread=8, subsample=0.80,colsample_bytree=0.80,seed=4242)
clf.fit(trn , y,eval_set=[(val, y_val)], eval_metric='mlogloss', verbose=True, early_stopping_rounds=50)
#multiclass logloss
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
#show and tell
fig = plt.figure(figsize=(16,12))
n_images_per_row=4
choices=np.random.choice(len(imgs),16)
#choices=range(16)
for i,id in enumerate(choices):