Skip to content

Instantly share code, notes, and snippets.

@imironhead
Last active December 8, 2017 10:27
Show Gist options
  • Save imironhead/395e6a87a011c0ca84636fe20f98439d to your computer and use it in GitHub Desktop.
Save imironhead/395e6a87a011c0ca84636fe20f98439d to your computer and use it in GitHub Desktop.
code to search linear combination weights
# there are 32 weeks
weights_center = 0.5 * np.ones((32, 1))
weights_offset = np.zeros_like(weights_center)
auc_save = 0.8
auc_best = 0.0
for step in range(steps):
# update weights
weights = np.clip(weights_center + weights_offset, 0.0, 1.0)
# weighted sum all features from training data (32 weeks x 28 slots)
guess = np.matmul(train_eigens, weights).flatten()
truth = train_labels
# calculate the auc of weighted sum of all training data
auc_test = auc(guess, truth)
# keep the new weights if we got better AUC
if auc_best < auc_test:
auc_best = auc_test
weights_center = weights
print 'better auc: [{:>5}]: {:>10,.5f}'.format(step, auc_best)
# save results
if auc_save + 0.00001 <= auc_best:
print 'saving'
auc_save = auc_best
# weighted sum of testing data
guess = np.matmul(issue_eigens, weights_center)
save_labels(guess)
# pick new weights near the current best weights
weights_offset = np.random.normal(np.zeros_like(weights_center), std)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment