Skip to content

Instantly share code, notes, and snippets.

View crawftv's full-sized avatar
🎯
Focusing

Crawford Collins crawftv

🎯
Focusing
View GitHub Profile
@crawftv
crawftv / .vimrc
Last active November 2, 2019 22:50
vim python
syntax enable
set nu
highlight BadWhitespace ctermbg=red guibg=red
au BufNewFile,BufRead *.py
\ set fileformat=unix |
\ set encoding=utf-8 |
\ match BadWhitespace /\s\+$/
set tabstop=4
set shiftwidth=4
@crawftv
crawftv / load_mnist.py
Last active April 11, 2019 03:52
Skopt Tutorial - Load & Transform Data
from keras.datasets import mnist
(X_train, y_train), (X_test, y_test) = mnist.load_data()
#Scale the data to between 0 and 1
X_train = X_train/ 255
X_test = X_test/ 255
#Flatten arrays from (28x28) to (784x1)
X_train = X_train.reshape(60000,784)
X_test = X_test.reshape(10000,784)
@crawftv
crawftv / baseline_nn.py
Last active April 11, 2019 03:52
Skopt Tutorial - Baseline NN
# the usual imports for a vanilla nueral net
import keras
from keras.models import Sequential
from keras.layers import Dense
model = Sequential()
model.add(Dense(16, input_shape=input_shape, activation='relu',name = 'input_layer'))
model.add(Dense(16, activation='relu', name="hidden_layer"))
model.add(Dense(10,activation='softmax',name="output_layer"))
@crawftv
crawftv / skopt_imports.py
Last active April 11, 2019 03:56
Skopt Tutorial - Imports
#imports we know we'll need
import skopt
# !pip install scikit-optimize if necessary
from skopt import gbrt_minimize, gp_minimize
from skopt.utils import use_named_args
from skopt.space import Real, Categorical, Integer
import keras
from keras.models import Sequential
from keras.layers import Dense
@crawftv
crawftv / skopt_named_dimensions.py
Created April 11, 2019 03:55
Skopt Tutorial - Search Dimensions
dim_learning_rate = Real(low=1e-4, high=1e-2, prior='log-uniform',
name='learning_rate')
dim_num_dense_layers = Integer(low=1, high=5, name='num_dense_layers')
dim_num_input_nodes = Integer(low=1, high=512, name='num_input_nodes')
dim_num_dense_nodes = Integer(low=1, high=28, name='num_dense_nodes')
dim_activation = Categorical(categories=['relu', 'sigmoid'],
name='activation')
dim_batch_size = Integer(low=1, high=128, name='batch_size')
dim_adam_decay = Real(low=1e-6,high=1e-2,name="adam_decay")
@crawftv
crawftv / skopt_model_creation.py
Created April 11, 2019 03:57
Skopt Tutorial - Model Creator
from keras.optimizers import Adam
def create_model(learning_rate, num_dense_layers,num_input_nodes,
num_dense_nodes, activation, adam_decay):
#start the model making process and create our first layer
model = Sequential()
model.add(Dense(num_input_nodes, input_shape= input_shape, activation=activation
))
#create a loop making a new dense layer for the amount passed to this model.
#naming the layers helps avoid tensorflow error deep in the stack trace.
for i in range(num_dense_layers):
@crawftv
crawftv / skopt_fitness.py
Last active April 11, 2019 04:53
Skopt Tutorial - Fitness Function
@use_named_args(dimensions=dimensions)
def fitness(learning_rate, num_dense_layers, num_input_nodes,
num_dense_nodes,activation, batch_size,adam_decay):
model = create_model(learning_rate=learning_rate,
num_dense_layers=num_dense_layers,
num_input_nodes=num_input_nodes,
num_dense_nodes=num_dense_nodes,
activation=activation,
adam_decay=adam_decay
@crawftv
crawftv / skopt-clear_session.py
Created April 11, 2019 03:59
Skopt Tutoria - Clear Session
K.clear_session()
tensorflow.reset_default_graph()
@crawftv
crawftv / skopt_gp_minimize.py
Created April 11, 2019 04:00
Skopt Tutorial - GP Minimize
gp_result = gp_minimize(func=fitness,
dimensions=dimensions,
n_calls=12,
noise= 0.01,
n_jobs=-1,
kappa = 5,
x0=default_parameters)
@crawftv
crawftv / skopt_gbrt_mimize.py
Created April 11, 2019 04:02
Skopt Tutorial - GBRT
gbrt_result = gbrt_minimize(func=fitness,
dimensions=dimensions,
n_calls=12,
n_jobs=-1,
x0=default_parameters)