Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
how to use deeprenewal programatically
dataset = get_dataset(args.datasource, regenerate=False)
prediction_length = dataset.metadata.prediction_length
freq = dataset.metadata.freq
cardinality = ast.literal_eval(dataset.metadata.feat_static_cat[0].cardinality)
train_ds = dataset.train
test_ds = dataset.test
trainer = Trainer(ctx=mx.context.gpu() if is_gpu&args.use_cuda else mx.context.cpu(),
batch_size=args.batch_size,
learning_rate=args.learning_rate,
epochs=20,
num_batches_per_epoch=args.number_of_batches_per_epoch,
clip_gradient=args.clip_gradient,
weight_decay=args.weight_decay,
hybridize=True) #hybridize false for development
estimator = DeepRenewalEstimator(
prediction_length=prediction_length,
context_length=prediction_length*args.context_length_multiplier,
num_layers=args.num_layers,
num_cells=args.num_cells,
cell_type=args.cell_type,
dropout_rate=args.dropout_rate,
scaling=True,
lags_seq=np.arange(1,args.num_lags+1).tolist(),
freq=freq,
use_feat_dynamic_real=args.use_feat_dynamic_real,
use_feat_static_cat=args.use_feat_static_cat,
use_feat_static_real=args.use_feat_static_real,
cardinality=cardinality if args.use_feat_static_cat else None,
trainer=trainer,
)
predictor = estimator.train(train_ds, test_ds)
deep_renewal_flat_forecast_it, ts_it = make_evaluation_predictions(
dataset=test_ds, predictor=predictor, num_samples=100
)
evaluator = IntermittentEvaluator(quantiles=[0.25,0.5,0.75], median=True, calculate_spec=False, round_integer=True)
#DeepAR
agg_metrics, item_metrics = evaluator(
ts_it, deep_renewal_flat_forecast_it, num_series=len(test_ds)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment