File size: 1,322 Bytes
7f50cd1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | """Fit the published forest on practice training data plus this instance."""
import sys
import time
from runtime import featurize, load_pool, make_model, record_id
from interface.data import load, write
import numpy as np
def main():
start = time.monotonic()
train, query = load(sys.argv[1])
pool_x, pool_y, pool_ids = load_pool()
features = featurize(train + query, workers=4)
# During practice rehearsal the current cohort is already in the pool.
# Include each of its training rows once, with its current supplied label.
current_ids = {record_id(row) for row in train}
keep = np.fromiter((value not in current_ids for value in pool_ids), dtype=bool)
x = np.concatenate((pool_x[keep], features[:len(train)]))
y = np.concatenate((pool_y[keep], [row['response'] for row in train]))
print(f'fit: {int(keep.sum())} pooled + {len(train)} current = {len(y)} rows; '
f'{len(pool_y)-int(keep.sum())} overlapping rows excluded', file=sys.stderr, flush=True)
model = make_model(workers=4)
model.fit(x, y)
predictions = model.predict(features[len(train):]) if query else np.empty(0)
write(sys.argv[2], query, predictions)
print(f'prediction complete: {time.monotonic()-start:.3f}s', file=sys.stderr, flush=True)
if __name__ == '__main__':
main()
|