Skip to content

Instantly share code, notes, and snippets.

@ktrnka
ktrnka / keras_sklearn.py
Last active November 4, 2015 19:12
Wrapper around Keras neural network for scikit-learn
from __future__ import unicode_literals
import logging
import numpy
import keras.models
import keras.layers.core
import keras.regularizers
import sklearn.metrics
import sklearn.base
import keras.constraints
import keras.layers.noise
@ktrnka
ktrnka / stacked_ensemble.py
Created December 2, 2015 01:00
Stacked ensemble of classifiers compatible with scikit-learn
class StackedEnsembleClassifier(sklearn.base.BaseEstimator, sklearn.base.ClassifierMixin):
"""
Ensemble of classifiers. Each classifier must have predict_proba and the head classifier is trained
to predict the output based on the individual classifier outputs. Stratified k-fold cross-validation
is used to get probabilities on held-out data.
"""
def __init__(self, classifiers, head_classifier, num_folds=3):
self.classifiers = classifiers
self.head_classifier = head_classifier
self.num_folds = num_folds
@ktrnka
ktrnka / prep_time_matrix.py
Last active July 5, 2018 10:12
Prepare data for Keras RNN
def prepare_time_matrix(X, time_steps=5, fill_value=None):
if time_steps < 1:
raise ValueError("time_steps must be 1 or more")
assert isinstance(X, numpy.ndarray)
time_shifts = [X]
time_shifts.extend(numpy.roll(X, t, axis=0) for t in range(1, time_steps))
time_shifts = reversed(time_shifts)
X_time = numpy.dstack(time_shifts)

EVTF

  • hourly count of total events
  • percent of hour in MRB range, in MSL range, in Mars umbra
  • time since the last MSL AOS_10 and MRB AOS_00 and AOS_10
  • altitude integrated from the ascend/descend events

FTL

  • percent of hour in FTL_EARTH, NADIR, flagcomms, etc. Not all of the fields but most
p50 Sunday Monday Tuesday
No metrics 91 ms 91 ms
EMF 57 ms 88 ms 93 ms
boto3 100 ms 110 ms
p90 Sunday Monday Tuesday
No metrics 140 ms 140 ms
EMF 83 ms 130 ms 140 ms
boto3 150 ms 160 ms