Last active
October 18, 2017 01:53
-
-
Save bbejeck/2d35726d4f0d5108eae7eb4016db6812 to your computer and use it in GitHub Desktop.
Updating the Prediction Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// process call left out for clarity; it places airline data | |
// in a list, storing in state store by airport code | |
@Override | |
public void punctuate(long timestamp) { | |
KeyValueIterator<String, List<String>> allFlights = flights.all(); | |
while (allFlights.hasNext()) { | |
KeyValue<String, List<String>> kv = allFlights.next(); | |
List<String> flightList = kv.value; | |
String key = kv.key; | |
if(flightList.size() >= 100) { | |
try { | |
byte[] serializedRegression = ModelBuilder.train(flightList); | |
context().forward(key, serializedRegression); | |
LOG.info("updating model for {}", key); | |
flightList.clear(); | |
flights.put(key, flightList); | |
} catch (Exception e) { | |
LOG.error("couldn't update online regression for {}",key, e); | |
} | |
} | |
} | |
allFlights.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment